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 <arilou@gmail.com>
This commit is contained in:
Jon Doron 2021-09-18 14:44:49 +03:00
parent 8055132746
commit 1d7b3aa258

View File

@ -30,6 +30,7 @@ from ..utils import (
mimetype2ext, mimetype2ext,
parse_codecs, parse_codecs,
parse_duration, parse_duration,
parse_iso8601,
qualities, qualities,
remove_start, remove_start,
smuggle_url, smuggle_url,
@ -1780,10 +1781,6 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
or parse_duration(search_meta('duration')) or parse_duration(search_meta('duration'))
is_live = video_details.get('isLive') is_live = video_details.get('isLive')
owner_profile_url = microformat.get('ownerProfileUrl') 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 = { info = {
'id': video_id, 'id': video_id,
@ -1813,9 +1810,20 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'categories': [category] if category else None, 'categories': [category] if category else None,
'tags': keywords, 'tags': keywords,
'is_live': is_live, '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( pctr = try_get(
player_response, player_response,
lambda x: x['captions']['playerCaptionsTracklistRenderer'], dict) lambda x: x['captions']['playerCaptionsTracklistRenderer'], dict)