AnjaneyaTurai commited on
Commit
47009bb
·
verified ·
1 Parent(s): 4b207a6

Deploy the StemDeck GPU service

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -361,10 +361,12 @@ def _clean_old_downloads() -> None:
361
 
362
 
363
  def _is_blocked(exc: BaseException) -> bool:
364
- """YouTube refused this server ("confirm you're not a bot", a sign-in wall, or too many requests)."""
365
- text = f"{exc} {exc.__cause__ or ''}".lower()
 
366
  return any(needle in text for needle in ("not a bot", "sign in to confirm", "sign-in before", "http error 429",
367
- "too many requests", "limiting downloads", "blocking downloads"))
 
368
 
369
 
370
  def youtube(url: str) -> tuple[dict[str, Any], list[str]]:
@@ -382,11 +384,12 @@ def youtube(url: str) -> tuple[dict[str, Any], list[str]]:
382
  path, info = yt.download_song(canonical, folder, settings, cfg.max_duration_sec,
383
  cfg.max_upload_mb * 1024 * 1024, lambda _done, _text: None)
384
  except yt.YouTubeError as exc:
 
 
385
  if _is_blocked(exc):
386
- log.warning("YouTube blocked a download: %s", exc.__cause__ or exc)
387
  return {"error": "YouTube is blocking downloads from this server right now.",
388
- "reason": YOUTUBE_BLOCKED}, []
389
- return {"error": str(exc)}, []
390
  except Exception: # noqa: BLE001 - logged in full here, summarised for the visitor
391
  log.exception("YouTube download failed")
392
  return {"error": "Couldn't get this song from YouTube. Try again, or upload the file."}, []
 
361
 
362
 
363
  def _is_blocked(exc: BaseException) -> bool:
364
+ """YouTube refused this server ("confirm you're not a bot", a sign-in wall, too many requests, or its newer
365
+ "This content isn't available, try again later" for networks it distrusts)."""
366
+ text = f"{exc} {exc.__cause__ or ''}".lower().replace("’", "'")
367
  return any(needle in text for needle in ("not a bot", "sign in to confirm", "sign-in before", "http error 429",
368
+ "too many requests", "limiting downloads", "blocking downloads",
369
+ "content isn't available", "try again later"))
370
 
371
 
372
  def youtube(url: str) -> tuple[dict[str, Any], list[str]]:
 
384
  path, info = yt.download_song(canonical, folder, settings, cfg.max_duration_sec,
385
  cfg.max_upload_mb * 1024 * 1024, lambda _done, _text: None)
386
  except yt.YouTubeError as exc:
387
+ detail = str(exc.__cause__ or exc)[:300] # yt-dlp's own words, for diagnosing (never cookie contents)
388
+ log.warning("YouTube download failed: %s", detail)
389
  if _is_blocked(exc):
 
390
  return {"error": "YouTube is blocking downloads from this server right now.",
391
+ "reason": YOUTUBE_BLOCKED, "detail": detail}, []
392
+ return {"error": str(exc), "detail": detail}, []
393
  except Exception: # noqa: BLE001 - logged in full here, summarised for the visitor
394
  log.exception("YouTube download failed")
395
  return {"error": "Couldn't get this song from YouTube. Try again, or upload the file."}, []