From 2b02803c65252587e17fe33757bd6578a8b21282 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sat, 23 Nov 2024 00:13:52 +0100 Subject: [PATCH] Throw out unfinished broadcasts from query results. --- ytplom/misc.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ytplom/misc.py b/ytplom/misc.py index 5f69085..579c3ce 100644 --- a/ytplom/misc.py +++ b/ytplom/misc.py @@ -241,7 +241,7 @@ class YoutubeVideo(DbData): self.duration = duration self.definition = definition - def set_duration_from_yt_string(self, yt_string) -> None: + def set_duration_from_yt_string(self, yt_string: str) -> None: """Set .duration from the kind of format the YouTube API provides.""" date_dur, time_dur = yt_string.split('T') seconds = 0 @@ -628,13 +628,17 @@ class TaskHandler(BaseHTTPRequestHandler): ids_for_details = ','.join([r.id_ for r in results]) videos_request = youtube.videos().list(id=ids_for_details, part='content_details') + unfinished_streams: list[YoutubeId] = [] for i, detailed in enumerate(videos_request.execute()['items']): result = results[i] assert result.id_ == detailed['id'] content_details: dict[str, str] = detailed['contentDetails'] + if 'P0D' == content_details['duration']: + unfinished_streams += [result.id_] + continue result.set_duration_from_yt_string(content_details['duration']) result.definition = content_details['definition'].upper() - return results + return [r for r in results if r.id_ not in unfinished_streams] query_data = YoutubeQuery( None, query_txt, -- 2.30.2