feat(main): main

This commit is contained in:
2026-03-09 08:26:45 -04:00
parent f37382d2b8
commit f14454b4c8
12 changed files with 598 additions and 62 deletions

View File

@@ -238,7 +238,36 @@ def download_for_airing(media_item: MediaItem) -> Path:
# Persist the cache location on the model
media_item.cached_file_path = str(downloaded_path)
media_item.save(update_fields=["cached_file_path"])
# Extract exact runtime from the cached file using ffprobe-static via Node.js
import subprocess
import json
exact_duration = None
try:
# Resolve ffprobe path from the npm package
node_cmd = ["node", "-e", "console.log(require('ffprobe-static').path)"]
result = subprocess.run(node_cmd, capture_output=True, text=True, check=True)
ffprobe_cmd = result.stdout.strip()
probe_cmd = [
ffprobe_cmd,
"-v", "error",
"-show_entries", "format=duration",
"-of", "default=noprint_wrappers=1:nokey=1",
str(downloaded_path)
]
probe_result = subprocess.run(probe_cmd, capture_output=True, text=True, check=True)
exact_duration = float(probe_result.stdout.strip())
except Exception as e:
logger.warning(f"Failed to extract exact runtime for {video_id} using ffprobe: {e}")
if exact_duration:
# Round up to nearest integer to be safe on bounds
import math
media_item.runtime_seconds = int(math.ceil(exact_duration))
media_item.save(update_fields=["cached_file_path", "runtime_seconds"])
logger.info("downloaded %s -> %s", video_id, downloaded_path)
logger.info("downloaded %s -> %s (exact runtime: %s)", video_id, downloaded_path, exact_duration)
return downloaded_path