[core] Calculate date by strftime_or_none; fix seconds in datetime_round

- Negative datetime is not acceptable on Windows.
- Scale the timestamp up 1000000 times to calculate milliseconds.
This commit is contained in:
Mozi
2024-12-25 09:49:53 +00:00
parent 3905f64920
commit bcda6e49b0
3 changed files with 35 additions and 13 deletions
+1 -5
View File
@@ -2673,11 +2673,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])}))