Do not extract timestamp if timezone not available

This commit is contained in:
coletdjnz 2024-05-04 22:05:18 +12:00
parent a1af9ffe27
commit 481ada3437
No known key found for this signature in database
GPG Key ID: 91984263BB39894A
1 changed files with 4 additions and 12 deletions

View File

@ -4553,19 +4553,11 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'uploader_url': format_field(channel_handle, None, 'https://www.youtube.com/%s', default=None),
})
def get_pacific_tz():
# Python 3.8 should be deprecated soon
# This fallback may make the timestamp slightly inaccurate for 3.8 users.
if sys.version_info < (3, 9):
return NO_DEFAULT
from zoneinfo import ZoneInfo
return dt.datetime.now(ZoneInfo('US/Pacific')).utcoffset()
# We only want timestamp IF it has second precision
# Additionally, if there is no timezone present, we should assume it is in PT.
# We only want timestamp IF it has second precision AND a timezone
# Currently the uploadDate in microformats appears to be in US/Pacific timezone.
timestamp = (
parse_iso8601(get_first(microformats, 'uploadDate'), timezone=get_pacific_tz())
or parse_iso8601(search_meta('uploadDate'), timezone=get_pacific_tz())
parse_iso8601(get_first(microformats, 'uploadDate'), timezone=NO_DEFAULT)
or parse_iso8601(search_meta('uploadDate'), timezone=NO_DEFAULT)
)
upload_date = (
dt.datetime.fromtimestamp(timestamp, dt.timezone.utc).strftime('%Y%m%d') if timestamp else