Skip to content

Commit

Permalink
encapp: add os walk and regexp search to video file path
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
JohanBlome committed Oct 15, 2024
1 parent 5f03633 commit 69713a7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions scripts/encapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@
".raw",
".yuv",
".ivf",
".mkv",
]


def isVideoExtension(filename):
ending = f".{filename.rsplit('.')[-1]}"
if ending is not None and ending in video_extensions:
return True

return False


Expand Down Expand Up @@ -814,20 +816,27 @@ 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:
if isVideoExtension(file):
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
Expand Down

0 comments on commit 69713a7

Please sign in to comment.