]> jfr.im git - yt-dlp.git/commitdiff
Add field `live_status`
authorpukkandan <redacted>
Wed, 21 Jul 2021 15:14:18 +0000 (20:44 +0530)
committerpukkandan <redacted>
Wed, 21 Jul 2021 15:20:58 +0000 (20:50 +0530)
README.md
yt_dlp/YoutubeDL.py
yt_dlp/extractor/common.py

index 838131e8c9b76e758e5593f81304d5772c2ff003..a02b45b8482ff66f84f25e6560b33948909f0293 100644 (file)
--- a/README.md
+++ b/README.md
@@ -941,6 +941,7 @@ # OUTPUT TEMPLATE
  - `average_rating` (numeric): Average rating give by users, the scale used depends on the webpage
  - `comment_count` (numeric): Number of comments on the video (For some extractors, comments are only downloaded at the end, and so this field cannot be used)
  - `age_limit` (numeric): Age restriction for the video (years)
+ - `live_status` (string): One of 'is_live', 'was_live', 'upcoming', 'not_live'
  - `is_live` (boolean): Whether this video is a live stream or a fixed-length video
  - `was_live` (boolean): Whether this video was originally a live stream
  - `playable_in_embed` (string): Whether this video is allowed to play in embedded players on other sites
index 1789cb46304f2520103e1af077dd19ae4c65fd5e..3ab59ea31e65b5044a8b6d73d8724949183788a5 100644 (file)
@@ -2036,7 +2036,7 @@ def sanitize_numeric_fields(info):
         elif thumbnails:
             info_dict['thumbnail'] = thumbnails[-1]['url']
 
-        if 'display_id' not in info_dict and 'id' in info_dict:
+        if info_dict.get('display_id') is None and 'id' in info_dict:
             info_dict['display_id'] = info_dict['id']
 
         for ts_key, date_key in (
@@ -2052,6 +2052,23 @@ def sanitize_numeric_fields(info):
                 except (ValueError, OverflowError, OSError):
                     pass
 
+        live_keys = ('is_live', 'was_live')
+        live_status = info_dict.get('live_status')
+        if live_status is None:
+            for key in live_keys:
+                if info_dict.get(key) is False:
+                    continue
+                if info_dict.get(key):
+                    live_status = key
+                break
+            if all(info_dict.get(key) is False for key in live_keys):
+                live_status = 'not_live'
+        if live_status:
+            info_dict['live_status'] = live_status
+            for key in live_keys:
+                if info_dict.get(key) is None:
+                    info_dict[key] = (live_status == key)
+
         # Auto generate title fields corresponding to the *_number fields when missing
         # in order to always have clean titles. This is very common for TV series.
         for field in ('chapter', 'season', 'episode'):
index a6fc5d11a3e134e2f300dd92994350f694a68858..e892ff3cbcc02564d9e3bf14dd9412fe879c5a21 100644 (file)
@@ -297,6 +297,8 @@ class InfoExtractor(object):
                     live stream that goes on instead of a fixed-length video.
     was_live:       True, False, or None (=unknown). Whether this video was
                     originally a live stream.
+    live_status:    'is_live', 'upcoming', 'was_live', 'not_live' or None (=unknown)
+                    If absent, automatically set from is_live, was_live
     start_time:     Time in seconds where the reproduction should start, as
                     specified in the URL.
     end_time:       Time in seconds where the reproduction should end, as