Fix download status handling and the blank page after download

- Never let a non-authoritative MeTube 'updated' event downgrade a
  terminal job (it refilled the progress bar after completion).
- Self-heal stale active jobs against MeTube history on status polls,
  so a missed event no longer leaves a job stuck in 'queued'.
- Build YT.Player on an imperatively created child div: React keeps
  owning the container, so switching to the local copy after a
  download no longer throws removeChild and blanks the page.
- Autoplay on open and seek controls; subtitle experiment reverted.
This commit is contained in:
vrubelroman 2026-09-27 23:36:09 +00:00
parent b1faeb3729
commit 43adec5224
9 changed files with 758 additions and 5 deletions

View file

@ -14,6 +14,8 @@ from app.services.download_jobs import (
MeTubeRejected,
delete_local_copy,
get_latest_job,
job_is_stale,
reconcile_stale_job,
request_download,
)
from app.services.metube_client import MeTubeClient
@ -100,6 +102,15 @@ def download_status(youtube_video_id: str, db: Session = Depends(get_db)) -> dic
job = get_latest_job(db, video.id)
if job is None:
return {"status": "not_downloaded", "progress_percent": None, "media_url": None, "error_message": None}
# Lazy self-heal: an active job whose Socket.IO events stopped (e.g. the
# terminal 'completed' event was missed while we were down) is reconciled
# against MeTube history on poll -- at most once per stale window.
if job_is_stale(job):
try:
reconcile_stale_job(db, job)
except Exception:
logger.warning("Could not self-heal stale download job %s", job.id, exc_info=True)
db.rollback()
return _serialize_job(job)