home · contact · privacy
Treat absence of yt_videos row and thumbnail files more forgivingly.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 15 Nov 2024 03:24:30 +0000 (04:24 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 15 Nov 2024 03:24:30 +0000 (04:24 +0100)
ytplom.py

index 361b89837b57348ae38c36d86f2bf8b005235bbf..cfabedc1b34fc5e1a74e8d8cdc6796d10ed768fb 100755 (executable)
--- a/ytplom.py
+++ b/ytplom.py
@@ -198,11 +198,11 @@ class VideoData(DbData):
 
     def __init__(self,
                  id_: VideoId,
-                 title: ProseText,
-                 description: ProseText,
-                 published_at: DatetimeStr,
-                 duration: str = '',
-                 definition: str = ''
+                 title: ProseText = ProseText('?'),
+                 description: ProseText = ProseText('?'),
+                 published_at: DatetimeStr = DatetimeStr('?'),
+                 duration: str = '?',
+                 definition: str = '?'
                  ) -> None:
         self.id_ = id_
         self.title = title
@@ -583,7 +583,10 @@ class TaskHandler(BaseHTTPRequestHandler):
         return downloads_db
 
     def _send_thumbnail(self, filename: PathStr) -> None:
-        with open(path_join(PATH_DIR_THUMBNAILS, filename), 'rb') as f:
+        path_thumbnail = path_join(PATH_DIR_THUMBNAILS, filename)
+        if not path_exists(path_thumbnail):
+            raise NotFoundException
+        with open(path_thumbnail, 'rb') as f:
             img = f.read()
         self._send_http(img, [('Content-type', 'image/jpg')])
 
@@ -621,7 +624,10 @@ class TaskHandler(BaseHTTPRequestHandler):
         downloads_db = self._make_downloads_db()
         conn = DatabaseConnection()
         linked_queries = QueryData.get_all_for_video(conn, video_id)
-        video_data = VideoData.get_one(conn, video_id)
+        try:
+            video_data = VideoData.get_one(conn, video_id)
+        except NotFoundException:
+            video_data = VideoData(video_id)
         conn.commit_close()
         self._send_rendered_template(
                 NAME_TEMPLATE_VIDEO_ABOUT,