28 lines
749 B
Python
28 lines
749 B
Python
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
|
|
)
|