1
0
mirror of https://github.com/yt-dlp/yt-dlp synced 2025-12-16 22:25:40 +07: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

@@ -1,3 +1,4 @@
import datetime as dt
import os
import xml.etree.ElementTree as etree
@@ -27,6 +28,13 @@ def compat_ord(c):
return c if isinstance(c, int) else ord(c)
def compat_datetime_from_timestamp(timestamp):
# Calling dt.datetime.fromtimestamp with negative timestamps throws error in Windows
# Ref: https://github.com/yt-dlp/yt-dlp/issues/5185, https://github.com/python/cpython/issues/81708,
# https://github.com/yt-dlp/yt-dlp/issues/6706#issuecomment-1496842642
return (dt.datetime.fromtimestamp(0, dt.timezone.utc) + dt.timedelta(seconds=timestamp))
# Python 3.8+ does not honor %HOME% on windows, but this breaks compatibility with youtube-dl
# See https://github.com/yt-dlp/yt-dlp/issues/792
# https://docs.python.org/3/library/os.path.html#os.path.expanduser