fix(downloads): show real title + thumbnail while queued/downloading
A queued/downloading row previously showed the bare video id and no thumbnail because asset metadata was only filled when the download completed. Now: - service.populate_from_catalog fills title/uploader/thumbnail/date/duration at enqueue from our own Video/Channel catalog (0 network cost) — feed downloads look right instantly - worker fills the same from yt-dlp's info_dict on the first progress event (covers ad-hoc URLs / catalog misses), best-effort, never fails a download Verified: a paused feed download now shows its real title, channel, thumbnail and duration.
This commit is contained in:
parent
f61ca96b6c
commit
c6ceaea899
2 changed files with 49 additions and 4 deletions
|
|
@ -13,7 +13,7 @@ from sqlalchemy.exc import IntegrityError
|
|||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.downloads import formats, quota
|
||||
from app.models import DownloadJob, MediaAsset
|
||||
from app.models import Channel, DownloadJob, MediaAsset, Video
|
||||
|
||||
|
||||
def source_url(source_kind: str, source_ref: str) -> str:
|
||||
|
|
@ -54,6 +54,27 @@ def get_or_create_asset(
|
|||
return asset
|
||||
|
||||
|
||||
def populate_from_catalog(db: Session, asset: MediaAsset) -> bool:
|
||||
"""Fill an asset's display metadata (title/uploader/thumbnail/date/duration) from our own
|
||||
catalog when the source is a known YouTube video — so a queued/downloading row shows the
|
||||
real title + thumbnail immediately instead of the bare id. 0 network cost. Returns True if
|
||||
it found a catalog match."""
|
||||
if asset.source_kind != "youtube" or asset.title:
|
||||
return False
|
||||
video = db.get(Video, asset.source_ref)
|
||||
if video is None:
|
||||
return False
|
||||
asset.title = video.title
|
||||
asset.thumbnail_url = video.thumbnail_url
|
||||
asset.duration_s = video.duration_seconds
|
||||
if video.published_at:
|
||||
asset.upload_date = video.published_at.date()
|
||||
channel = db.get(Channel, video.channel_id)
|
||||
if channel is not None:
|
||||
asset.uploader = channel.title
|
||||
return True
|
||||
|
||||
|
||||
def _next_queue_pos(db: Session) -> int:
|
||||
return (db.execute(select(func.coalesce(func.max(DownloadJob.queue_pos), 0))).scalar() or 0) + 1
|
||||
|
||||
|
|
@ -74,6 +95,8 @@ def enqueue(
|
|||
spec = formats.normalize(spec)
|
||||
sig = formats.format_sig(spec)
|
||||
asset = get_or_create_asset(db, source_kind, source_ref, sig)
|
||||
# Show a real title + thumbnail the moment it's queued (feed downloads are catalog videos).
|
||||
populate_from_catalog(db, asset)
|
||||
|
||||
job = DownloadJob(
|
||||
user_id=user_id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue