From 8fbd94b12027594294a859a995f75e6fdc8c2f55 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 10 Jul 2025 10:10:49 +0700 Subject: [PATCH] add to queue error handling --- backend/common/src/helper.py | 10 +++++++--- backend/download/src/queue.py | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/backend/common/src/helper.py b/backend/common/src/helper.py index 7b1d43be..bfb5e474 100644 --- a/backend/common/src/helper.py +++ b/backend/common/src/helper.py @@ -155,9 +155,13 @@ def is_shorts(youtube_id: str) -> bool: """check if youtube_id is a shorts video, bot not it it's not a shorts""" shorts_url = f"https://www.youtube.com/shorts/{youtube_id}" cookies = {"SOCS": "CAI"} - response = requests.head( - shorts_url, cookies=cookies, headers=requests_headers(), timeout=10 - ) + try: + response = requests.head( + shorts_url, cookies=cookies, headers=requests_headers(), timeout=10 + ) + except requests.exceptions.RequestException: + # assume video on error + return False return response.status_code == 200 diff --git a/backend/download/src/queue.py b/backend/download/src/queue.py index 45311572..3d8c1522 100644 --- a/backend/download/src/queue.py +++ b/backend/download/src/queue.py @@ -266,8 +266,15 @@ class PendingList(PendingIndex): video_results = ChannelSubscription().get_last_youtube_videos( url, limit=False, query_filter=query_filter ) + if not video_results: + print(f"{url}: no videos to add from channel, skipping") + return + channel_handler = YoutubeChannel(url) channel_handler.build_json(upload=False) + if not channel_handler.json_data: + print(f"{url}: channel metadata extraction failed, skipping") + return total = len(video_results) for idx, video_data in enumerate(video_results): @@ -307,6 +314,10 @@ class PendingList(PendingIndex): """fast parse playlist""" playlist = YoutubePlaylist(url) playlist.get_from_youtube() + if not playlist.youtube_meta: + print(f"{url}: playlist metadata extraction failed, skipping") + return + video_results = playlist.youtube_meta["entries"] total = len(video_results) @@ -347,11 +358,14 @@ class PendingList(PendingIndex): video = YoutubeVideo(youtube_id=url) video.get_from_youtube() - video_data = video.youtube_meta - video_data["vid_type"] = vid_type + if not video.youtube_meta: + print(f"{url}: video metadata extraction failed, skipping") + return None + + video.youtube_meta["vid_type"] = vid_type to_add = self._parse_entry( youtube_id=url, - video_data=video_data, + video_data=video.youtube_meta, url_type=url_type, idx=idx, total=total,