home · contact · privacy
Throw out unfinished broadcasts from query results.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 22 Nov 2024 23:13:52 +0000 (00:13 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 22 Nov 2024 23:13:52 +0000 (00:13 +0100)
ytplom/misc.py

index 5f6908591dc0a7bb1ca95f822c0441ea89536213..579c3ce754c26583e6c35365705ca9250855a51b 100644 (file)
@@ -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,