home · contact · privacy
On YoutubeDLError, at least update failed download's status. master
authorChristian Heller <c.heller@plomlompom.de>
Thu, 9 Oct 2025 06:55:15 +0000 (08:55 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 9 Oct 2025 06:55:15 +0000 (08:55 +0200)
src/ytplom/misc.py

index 74c623913f5e6bbf3f9160d8c7bc05b551ab9b64..411013892979dfbb886d27ef5c3033d1285fee1b 100644 (file)
@@ -18,6 +18,7 @@ from ffmpeg import probe as ffprobe  # type: ignore
 import googleapiclient.discovery  # type: ignore
 from mpv import MPV  # type: ignore
 from yt_dlp import YoutubeDL  # type: ignore
 import googleapiclient.discovery  # type: ignore
 from mpv import MPV  # type: ignore
 from yt_dlp import YoutubeDL  # type: ignore
+from yt_dlp.utils import YoutubeDLError  # type: ignore
 # ourselves
 from ytplom.db import DbConn, DbData, Hash
 from ytplom.primitives import HandledException, NotFoundException
 # ourselves
 from ytplom.db import DbConn, DbData, Hash
 from ytplom.primitives import HandledException, NotFoundException
@@ -951,12 +952,17 @@ class DownloadsManager:
             url = f'{YOUTUBE_URL_PREFIX}{video_id}'
             with YoutubeDL(YT_DL_PARAMS | {'progress_hooks': [hook]}) as ydl:
                 self._update_status(video_id, 'preparing download')
             url = f'{YOUTUBE_URL_PREFIX}{video_id}'
             with YoutubeDL(YT_DL_PARAMS | {'progress_hooks': [hook]}) as ydl:
                 self._update_status(video_id, 'preparing download')
-                info = ydl.sanitize_info(ydl.extract_info(url, download=False))
-                for f in info['requested_formats']:
-                    sizes[f[TOK_FO_ID]] = [False, 1]
-                    if TOK_FS_AP in f:
-                        sizes[f[TOK_FO_ID]] = [True, f[TOK_FS_AP]]
-                ydl.download(url)
+                try:
+                    info = ydl.sanitize_info(ydl.extract_info(url,
+                                                              download=False))
+                    for f in info['requested_formats']:
+                        sizes[f[TOK_FO_ID]] = [False, 1]
+                        if TOK_FS_AP in f:
+                            sizes[f[TOK_FO_ID]] = [True, f[TOK_FS_AP]]
+                    ydl.download(url)
+                except YoutubeDLError as e:
+                    self._update_status(video_id, 'ERROR')
+                    raise e
             self._sync_db()
 
     def start_thread(self) -> None:
             self._sync_db()
 
     def start_thread(self) -> None: