1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-11-01 07:05:14 +00:00

[compat] Add compat_datetime_from_timestamp (#11902)

Authored by: pzhlkj6612, seproDev

Co-authored-by: sepro <sepro@sepr0.com>
This commit is contained in:
Mozi
2025-09-06 23:48:24 +00:00
committed by GitHub
parent e6e6b51214
commit 6a763a55d8
5 changed files with 77 additions and 15 deletions

View File

@@ -2717,11 +2717,7 @@ class YoutubeDL:
('modified_timestamp', 'modified_date'),
):
if info_dict.get(date_key) is None and info_dict.get(ts_key) is not None:
# Working around out-of-range timestamp values (e.g. negative ones on Windows,
# see http://bugs.python.org/issue1646728)
with contextlib.suppress(ValueError, OverflowError, OSError):
upload_date = dt.datetime.fromtimestamp(info_dict[ts_key], dt.timezone.utc)
info_dict[date_key] = upload_date.strftime('%Y%m%d')
info_dict[date_key] = strftime_or_none(info_dict[ts_key])
if not info_dict.get('release_year'):
info_dict['release_year'] = traverse_obj(info_dict, ('release_date', {lambda x: int(x[:4])}))