avorg/backend/video_scanner.py

28 lines
963 B
Python

import os
from typing import List
from models import Video
def scan_video_directory(directory_path: str) -> List[dict]:
"""
Scan a directory for video files and return a list of video information.
"""
video_extensions = {'.mp4', '.avi', '.mkv', '.mov', '.wmv', '.flv', '.webm', '.m4v'}
videos = []
if not os.path.exists(directory_path):
raise FileNotFoundError(f"Directory {directory_path} does not exist")
for root, dirs, files in os.walk(directory_path):
for file in files:
if os.path.splitext(file)[1].lower() in video_extensions:
full_path = os.path.join(root, file)
stat = os.stat(full_path)
video_info = {
"title": os.path.splitext(file)[0],
"path": full_path,
"size": stat.st_size,
}
videos.append(video_info)
return videos