From: Christian Heller Date: Fri, 22 Nov 2024 23:13:52 +0000 (+0100) Subject: Throw out unfinished broadcasts from query results. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/test?a=commitdiff_plain;h=2b02803c65252587e17fe33757bd6578a8b21282;p=ytplom Throw out unfinished broadcasts from query results. --- 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,