From 2c7e3c73989da7d6219176a3b0af8504fe96518a Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Fri, 15 Nov 2024 04:24:30 +0100
Subject: [PATCH] Treat absence of yt_videos row and thumbnail files more
 forgivingly.

---
 ytplom.py | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/ytplom.py b/ytplom.py
index 361b898..cfabedc 100755
--- 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,
-- 
2.30.2