From 69713a74837631d20cbb83c563dce4d9641894b0 Mon Sep 17 00:00:00 2001 From: JohanBlome Date: Tue, 15 Oct 2024 08:44:05 -0700 Subject: [PATCH] encapp: add os walk and regexp search to video file path input.filepath can now be either: 1) specific file 2) a folder 3) a root folder with a regexp filename A file walk will be performed at the root folder (last '/') and files will be matched based on endings and a regexp filter. E.g input { filepath: "~/Downloads/.*[0-1]{1}.mov" } Matching anythign in the downloads folder with a single digit of either 0 or 1 and '.mov' ending. It will traverse subfolders as well as the root. Signed-off-by: JohanBlome --- scripts/encapp.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/encapp.py b/scripts/encapp.py index 9a199c6..361d8c1 100755 --- a/scripts/encapp.py +++ b/scripts/encapp.py @@ -152,6 +152,7 @@ ".raw", ".yuv", ".ivf", + ".mkv", ] @@ -159,6 +160,7 @@ def isVideoExtension(filename): ending = f".{filename.rsplit('.')[-1]}" if ending is not None and ending in video_extensions: return True + return False @@ -814,10 +816,15 @@ def createTestsFromDefinitionExpansion(testsuite): def expand_filepath(path): - # Allow regexp on filenam - basename = os.path.basename(path) - folder = os.path.dirname(path) - folder = os.path.expanduser(folder) + # Check if path is a folder + basename = "" + folder = "" + path = os.path.expanduser(path) + if os.path.isdir(path): + folder = path + else: + basename = os.path.basename(path) + folder = os.path.dirname(path) video_files = [] for root, _dirs, files in os.walk(folder): for file in files: @@ -825,9 +832,11 @@ def expand_filepath(path): if len(basename) > 0: m = re.search(basename, file) if m: - file = f"{folder}/{m.group(0)}" + file = f"{root}/{m.group(0)}" else: continue + else: + file = f"{root}/{file}" video_files.append(file) return video_files