Files
importarr/importarr/scanner.py

37 lines
1.1 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from .readiness import has_transient_part
VIDEO_EXTENSIONS = {".mkv", ".mp4", ".avi", ".mov", ".m4v", ".wmv", ".ts"}
@dataclass(frozen=True)
class VideoFile:
path: Path
relative_path: Path
size: int
def is_sample(path: Path) -> bool:
lowered = "/".join(path.parts).lower()
return "sample" in lowered or path.name.lower().startswith("sample")
def scan_videos(root: Path, *, include_transient: bool = False) -> list[VideoFile]:
root = root.resolve()
if not root.exists():
return []
results: list[VideoFile] = []
for path in root.rglob("*"):
if not path.is_file() or path.suffix.lower() not in VIDEO_EXTENSIONS:
continue
if is_sample(path):
continue
if not include_transient and has_transient_part(path):
continue
results.append(VideoFile(path=path, relative_path=path.relative_to(root), size=path.stat().st_size))
return sorted(results, key=lambda item: str(item.relative_path))