feat(main): main
This commit is contained in:
@@ -16,11 +16,13 @@ from core.services.youtube import download_for_airing, YOUTUBE_SOURCE_TYPES
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run_cache(hours: int = 24, prune_only: bool = False) -> dict:
|
||||
def run_cache(hours: int = 24, prune_only: bool = False, channel_id: int | None = None) -> dict:
|
||||
"""
|
||||
Scan Airings in the next `hours` hours, download any uncached YouTube
|
||||
videos, and prune stale local files.
|
||||
|
||||
If `channel_id` is provided, only process airings for that specific channel.
|
||||
|
||||
Returns a summary dict suitable for JSON serialization.
|
||||
"""
|
||||
now = timezone.now()
|
||||
@@ -33,11 +35,11 @@ def run_cache(hours: int = 24, prune_only: bool = False) -> dict:
|
||||
return {"pruned": pruned, "downloaded": 0, "already_cached": 0, "failed": 0, "items": []}
|
||||
|
||||
# ── Find upcoming and currently playing YouTube-backed airings ──────────
|
||||
upcoming = (
|
||||
Airing.objects
|
||||
.filter(ends_at__gt=now, starts_at__lte=window_end)
|
||||
.select_related("media_item__media_source")
|
||||
)
|
||||
qs = Airing.objects.filter(ends_at__gt=now, starts_at__lte=window_end)
|
||||
if channel_id is not None:
|
||||
qs = qs.filter(channel_id=channel_id)
|
||||
|
||||
upcoming = qs.select_related("media_item__media_source")
|
||||
|
||||
youtube_items: dict[int, MediaItem] = {}
|
||||
downloaded = already_cached = failed = 0
|
||||
|
||||
Reference in New Issue
Block a user