From 8055132746f58a17cc128c49cb40d19ad8649999 Mon Sep 17 00:00:00 2001 From: Jon Doron Date: Fri, 17 Sep 2021 09:07:37 +0300 Subject: [PATCH 1/3] Youtube: Add broadcast start time (if it was a live stream) Signed-off-by: Jon Doron --- youtube_dl/extractor/youtube.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index dc4bd4a77..594659d93 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1780,6 +1780,10 @@ class YoutubeIE(YoutubeBaseInfoExtractor): or parse_duration(search_meta('duration')) is_live = video_details.get('isLive') owner_profile_url = microformat.get('ownerProfileUrl') + live_details = microformat.get('liveBroadcastDetails') + broadcast_start_timestamp = None + if live_details: + broadcast_start_timestamp = live_details.get('startTimestamp') info = { 'id': video_id, @@ -1809,6 +1813,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): 'categories': [category] if category else None, 'tags': keywords, 'is_live': is_live, + 'broadcast_start_timestamp': broadcast_start_timestamp, } pctr = try_get( From 1d7b3aa25871236ca82e90e15a90f009c6d67aad Mon Sep 17 00:00:00 2001 From: Jon Doron Date: Sat, 18 Sep 2021 14:44:49 +0300 Subject: [PATCH 2/3] Youtube: Create a 'timestamp' field when we can In case of a video originated from a live broadcast stream, take the broadcast start time and set it as the 'timestamp' field of the video. 'upload_date' will be auto-generated based on the value of 'timestamp'. In case this is a video not originated from a live broadcast simply set 'upload_date' as it used to be. Signed-off-by: Jon Doron --- youtube_dl/extractor/youtube.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 594659d93..adfd9624a 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -30,6 +30,7 @@ from ..utils import ( mimetype2ext, parse_codecs, parse_duration, + parse_iso8601, qualities, remove_start, smuggle_url, @@ -1780,10 +1781,6 @@ class YoutubeIE(YoutubeBaseInfoExtractor): or parse_duration(search_meta('duration')) is_live = video_details.get('isLive') owner_profile_url = microformat.get('ownerProfileUrl') - live_details = microformat.get('liveBroadcastDetails') - broadcast_start_timestamp = None - if live_details: - broadcast_start_timestamp = live_details.get('startTimestamp') info = { 'id': video_id, @@ -1813,9 +1810,20 @@ class YoutubeIE(YoutubeBaseInfoExtractor): 'categories': [category] if category else None, 'tags': keywords, 'is_live': is_live, - 'broadcast_start_timestamp': broadcast_start_timestamp, } + live_details = microformat.get('liveBroadcastDetails') + broadcast_start_timestamp = None + if live_details: + broadcast_start_timestamp = live_details.get('startTimestamp') + + if broadcast_start_timestamp: + info['timestamp'] = parse_iso8601(broadcast_start_timestamp) + else: + info['upload_date'] = unified_strdate( + microformat.get('uploadDate') + or search_meta('uploadDate')) + pctr = try_get( player_response, lambda x: x['captions']['playerCaptionsTracklistRenderer'], dict) From a5325665d50804f43ebbcb7a87f476ebec8025c8 Mon Sep 17 00:00:00 2001 From: Jon Doron Date: Sat, 18 Sep 2021 14:47:55 +0300 Subject: [PATCH 3/3] Youtube: Use release_timestamp instead of just timestamp Signed-off-by: Jon Doron --- youtube_dl/extractor/youtube.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index adfd9624a..d94050d20 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1813,16 +1813,10 @@ class YoutubeIE(YoutubeBaseInfoExtractor): } live_details = microformat.get('liveBroadcastDetails') - broadcast_start_timestamp = None if live_details: broadcast_start_timestamp = live_details.get('startTimestamp') - - if broadcast_start_timestamp: - info['timestamp'] = parse_iso8601(broadcast_start_timestamp) - else: - info['upload_date'] = unified_strdate( - microformat.get('uploadDate') - or search_meta('uploadDate')) + if broadcast_start_timestamp: + info['release_timestamp'] = parse_iso8601(broadcast_start_timestamp) pctr = try_get( player_response,