Initial video AI analysis project
This commit is contained in:
27
video_ai_analysis_poc/discovery.py
Normal file
27
video_ai_analysis_poc/discovery.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def discover_videos(
|
||||
input_dir: str | Path,
|
||||
extensions: list[str],
|
||||
*,
|
||||
recursive: bool,
|
||||
) -> list[Path]:
|
||||
root = Path(input_dir).expanduser()
|
||||
if not root.exists():
|
||||
raise FileNotFoundError(f"input dir not found: {root}")
|
||||
if not root.is_dir():
|
||||
raise NotADirectoryError(f"input path is not a directory: {root}")
|
||||
|
||||
allowed = {
|
||||
extension.lower() if extension.startswith(".") else f".{extension.lower()}"
|
||||
for extension in extensions
|
||||
}
|
||||
iterator = root.rglob("*") if recursive else root.iterdir()
|
||||
return sorted(
|
||||
path
|
||||
for path in iterator
|
||||
if path.is_file() and path.suffix.lower() in allowed
|
||||
)
|
||||
Reference in New Issue
Block a user