feat(main): main
This commit is contained in:
@@ -176,3 +176,21 @@ def download_item(request, item_id: int):
|
||||
except Exception as exc:
|
||||
from ninja.errors import HttpError
|
||||
raise HttpError(500, f"Download failed: {exc}")
|
||||
|
||||
|
||||
@router.get("/{item_id}/progress", response=dict)
|
||||
def download_progress(request, item_id: int):
|
||||
"""
|
||||
Return the current download progress string (e.g. '45.1%') from the yt-dlp hook.
|
||||
"""
|
||||
from django.core.cache import cache
|
||||
item = get_object_or_404(MediaItem, id=item_id)
|
||||
if not item.youtube_video_id:
|
||||
from ninja.errors import HttpError
|
||||
raise HttpError(400, "MediaItem is not a YouTube video.")
|
||||
|
||||
if item.cached_file_path:
|
||||
return {"status": "finished", "progress": "100%"}
|
||||
|
||||
pct = cache.get(f"yt_progress_{item.youtube_video_id}")
|
||||
return {"status": "downloading" if pct else "unknown", "progress": pct or "0%"}
|
||||
|
||||
Reference in New Issue
Block a user