From: Christian Heller Date: Fri, 15 Nov 2024 03:24:30 +0000 (+0100) Subject: Treat absence of yt_videos row and thumbnail files more forgivingly. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%22https:/validator.w3.org/calendar?a=commitdiff_plain;h=2c7e3c73989da7d6219176a3b0af8504fe96518a;p=ytplom Treat absence of yt_videos row and thumbnail files more forgivingly. --- 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,