Show popular fetch phases in nav indicator and Downloads page

- Phase 1 (crawling) now creates the task immediately so Downloads shows it
- Phase label updates to 'Enriching view counts' when phase 2 starts
- Nav bar DownloadIndicator also polls /channels/tasks and shows spinning
  indicator + progress % for background tasks (not just file downloads)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 23:32:39 +02:00
parent be84660e2d
commit 3a557a1d24
3 changed files with 55 additions and 20 deletions

View File

@@ -680,7 +680,20 @@ def _fetch_popular_task(channel_id: int, youtube_channel_id: str, channel_name:
from ..database import SessionLocal
from concurrent.futures import ThreadPoolExecutor, as_completed
task_id = f"popular-{channel_id}"
label = f"Popular fetch — {channel_name}" if channel_name else "Popular fetch"
# Phase 1 — flat-playlist: crawl all channel videos quickly
with _tasks_lock:
_tasks[task_id] = {
"id": task_id,
"label": label,
"phase": "Crawling channel…",
"total": 0,
"done": 0,
"started_at": datetime.utcnow().isoformat(),
}
if youtube_channel_id.startswith("@"):
url = f"https://www.youtube.com/{youtube_channel_id}/videos"
else:
@@ -750,17 +763,15 @@ def _fetch_popular_task(channel_id: int, youtube_channel_id: str, channel_name:
db.close()
if not video_ids:
with _tasks_lock:
_tasks.pop(task_id, None)
return
task_id = f"popular-{channel_id}"
with _tasks_lock:
_tasks[task_id] = {
"id": task_id,
"label": f"Popular fetch — {channel_name}" if channel_name else "Popular fetch",
"total": len(video_ids),
"done": 0,
"started_at": datetime.utcnow().isoformat(),
}
if task_id in _tasks:
_tasks[task_id]["phase"] = "Enriching view counts…"
_tasks[task_id]["total"] = len(video_ids)
_tasks[task_id]["done"] = 0
results = {}
try: