feat(main): main
This commit is contained in:
@@ -207,6 +207,21 @@ def download_for_airing(media_item: MediaItem) -> Path:
|
||||
logger.info("cache hit: %s already at %s", video_id, existing)
|
||||
return existing
|
||||
|
||||
from django.core.cache import cache
|
||||
|
||||
def progress_hook(d):
|
||||
if d['status'] == 'downloading':
|
||||
# Note: _percent_str includes ANSI escape codes sometimes, but yt_dlp usually cleans it if not a tty
|
||||
pct = d.get('_percent_str', '').strip()
|
||||
# Clean ANSI just in case
|
||||
import re
|
||||
pct_clean = re.sub(r'\x1b\[[0-9;]*m', '', pct).strip()
|
||||
if pct_clean:
|
||||
# Store the string "xx.x%" into Django cache. Expire after 5 mins so it cleans itself up.
|
||||
cache.set(f"yt_progress_{video_id}", pct_clean, timeout=300)
|
||||
elif d['status'] == 'finished':
|
||||
cache.set(f"yt_progress_{video_id}", "100%", timeout=300)
|
||||
|
||||
ydl_opts = {
|
||||
"quiet": True,
|
||||
"no_warnings": True,
|
||||
@@ -218,6 +233,7 @@ def download_for_airing(media_item: MediaItem) -> Path:
|
||||
# 3. Any pre-muxed webm
|
||||
# 4. Anything pre-muxed (no merger needed)
|
||||
"format": "best[ext=mp4][height<=1080]/best[ext=mp4]/best[ext=webm]/best",
|
||||
"progress_hooks": [progress_hook],
|
||||
}
|
||||
|
||||
url = media_item.file_path # URL stored here by sync_source
|
||||
|
||||
Reference in New Issue
Block a user