From 1d7b3aa25871236ca82e90e15a90f009c6d67aad Mon Sep 17 00:00:00 2001 From: Jon Doron Date: Sat, 18 Sep 2021 14:44:49 +0300 Subject: [PATCH] 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)