Log URL extraction failures to error_log for admin visibility

When a user pastes a URL and extraction fails (type=unknown), the
failure is now recorded in the error_log table with the actual yt-dlp
error message. Admins can see these in the Errors tab alongside
download failures — gives visibility into which sites/URLs users
are trying that don't work.
This commit is contained in:
xpltd 2026-03-21 23:39:00 -05:00
parent 723e7f4248
commit 6f20d29151

View file

@ -71,6 +71,8 @@ class DownloadService:
) )
# Per-job throttle state for DB writes (only used inside worker threads) # Per-job throttle state for DB writes (only used inside worker threads)
self._last_db_percent: dict[str, float] = {} self._last_db_percent: dict[str, float] = {}
# Stash extraction errors for logging in async context
self._last_extract_error: str = ""
def _base_opts(self) -> dict: def _base_opts(self) -> dict:
"""Return yt-dlp options common to all invocations.""" """Return yt-dlp options common to all invocations."""
@ -526,8 +528,10 @@ class DownloadService:
try: try:
with yt_dlp.YoutubeDL(opts) as ydl: with yt_dlp.YoutubeDL(opts) as ydl:
return ydl.extract_info(url, download=False) return ydl.extract_info(url, download=False)
except Exception: except Exception as e:
logger.exception("URL info extraction failed for %s", url) logger.warning("URL info extraction failed for %s: %s", url, e)
# Stash the error message for get_url_info to log
self._last_extract_error = str(e)
return None return None
def _is_audio_only_source(self, url: str) -> bool: def _is_audio_only_source(self, url: str) -> bool:
@ -579,6 +583,15 @@ class DownloadService:
url, url,
) )
if not info: if not info:
# Log extraction failure for admin visibility
extract_err = getattr(self, "_last_extract_error", "")
from app.core.database import log_download_error
await log_download_error(
self._db,
url=url,
error=extract_err or "URL extraction failed — no media found",
)
self._last_extract_error = ""
# Provide site-specific hints for known auth-required platforms # Provide site-specific hints for known auth-required platforms
hint = self._get_auth_hint(url) hint = self._get_auth_hint(url)
return { return {