mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-08-13 22:24:14 +09:00
Compare commits
No commits in common. "21792b88b791b16e3ab0a0fb2e26e5bb8a4e2ff3" and "71211e7db7243377f862dfdea9a9c3a511df66c2" have entirely different histories.
21792b88b7
...
71211e7db7
@ -18,7 +18,6 @@ from test.helper import (
|
|||||||
)
|
)
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
from youtube_dl.compat import (
|
from youtube_dl.compat import (
|
||||||
compat_contextlib_suppress,
|
|
||||||
compat_http_cookiejar_Cookie,
|
compat_http_cookiejar_Cookie,
|
||||||
compat_http_server,
|
compat_http_server,
|
||||||
compat_kwargs,
|
compat_kwargs,
|
||||||
@ -36,9 +35,6 @@ from youtube_dl.downloader.external import (
|
|||||||
HttpieFD,
|
HttpieFD,
|
||||||
WgetFD,
|
WgetFD,
|
||||||
)
|
)
|
||||||
from youtube_dl.postprocessor import (
|
|
||||||
FFmpegPostProcessor,
|
|
||||||
)
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
TEST_SIZE = 10 * 1024
|
TEST_SIZE = 10 * 1024
|
||||||
@ -231,17 +227,7 @@ class TestAria2cFD(unittest.TestCase):
|
|||||||
self.assertIn('--load-cookies=%s' % downloader._cookies_tempfile, cmd)
|
self.assertIn('--load-cookies=%s' % downloader._cookies_tempfile, cmd)
|
||||||
|
|
||||||
|
|
||||||
# Handle delegated availability
|
@ifExternalFDAvailable(FFmpegFD)
|
||||||
def ifFFmpegFDAvailable(externalFD):
|
|
||||||
# raise SkipTest, or set False!
|
|
||||||
avail = ifExternalFDAvailable(externalFD) and False
|
|
||||||
with compat_contextlib_suppress(Exception):
|
|
||||||
avail = FFmpegPostProcessor(downloader=None).available
|
|
||||||
return unittest.skipUnless(
|
|
||||||
avail, externalFD.get_basename() + ' not found')
|
|
||||||
|
|
||||||
|
|
||||||
@ifFFmpegFDAvailable(FFmpegFD)
|
|
||||||
class TestFFmpegFD(unittest.TestCase):
|
class TestFFmpegFD(unittest.TestCase):
|
||||||
_args = []
|
_args = []
|
||||||
|
|
||||||
|
@ -2421,26 +2421,29 @@ except ImportError: # Python 2
|
|||||||
compat_urllib_request_urlretrieve = compat_urlretrieve
|
compat_urllib_request_urlretrieve = compat_urlretrieve
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from HTMLParser import (
|
|
||||||
HTMLParser as compat_HTMLParser,
|
|
||||||
HTMLParseError as compat_HTMLParseError)
|
|
||||||
except ImportError: # Python 3
|
|
||||||
from html.parser import HTMLParser as compat_HTMLParser
|
from html.parser import HTMLParser as compat_HTMLParser
|
||||||
|
except ImportError: # Python 2
|
||||||
|
from HTMLParser import HTMLParser as compat_HTMLParser
|
||||||
|
compat_html_parser_HTMLParser = compat_HTMLParser
|
||||||
|
|
||||||
|
try: # Python 2
|
||||||
|
from HTMLParser import HTMLParseError as compat_HTMLParseError
|
||||||
|
except ImportError: # Python <3.4
|
||||||
try:
|
try:
|
||||||
from html.parser import HTMLParseError as compat_HTMLParseError
|
from html.parser import HTMLParseError as compat_HTMLParseError
|
||||||
except ImportError: # Python >3.4
|
except ImportError: # Python >3.4
|
||||||
# HTMLParseError was deprecated in Python 3.3 and removed in
|
|
||||||
|
# HTMLParseError has been deprecated in Python 3.3 and removed in
|
||||||
# Python 3.5. Introducing dummy exception for Python >3.5 for compatible
|
# Python 3.5. Introducing dummy exception for Python >3.5 for compatible
|
||||||
# and uniform cross-version exception handling
|
# and uniform cross-version exception handling
|
||||||
class compat_HTMLParseError(Exception):
|
class compat_HTMLParseError(Exception):
|
||||||
pass
|
pass
|
||||||
compat_html_parser_HTMLParser = compat_HTMLParser
|
|
||||||
compat_html_parser_HTMLParseError = compat_HTMLParseError
|
compat_html_parser_HTMLParseError = compat_HTMLParseError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_DEVNULL = subprocess.DEVNULL
|
from subprocess import DEVNULL
|
||||||
compat_subprocess_get_DEVNULL = lambda: _DEVNULL
|
compat_subprocess_get_DEVNULL = lambda: DEVNULL
|
||||||
except AttributeError:
|
except ImportError:
|
||||||
compat_subprocess_get_DEVNULL = lambda: open(os.path.devnull, 'w')
|
compat_subprocess_get_DEVNULL = lambda: open(os.path.devnull, 'w')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -2940,51 +2943,6 @@ else:
|
|||||||
compat_socket_create_connection = socket.create_connection
|
compat_socket_create_connection = socket.create_connection
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from contextlib import suppress as compat_contextlib_suppress
|
|
||||||
except ImportError:
|
|
||||||
class compat_contextlib_suppress(object):
|
|
||||||
_exceptions = None
|
|
||||||
|
|
||||||
def __init__(self, *exceptions):
|
|
||||||
super(compat_contextlib_suppress, self).__init__()
|
|
||||||
# TODO: [Base]ExceptionGroup (3.12+)
|
|
||||||
self._exceptions = exceptions
|
|
||||||
|
|
||||||
def __enter__(self):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
||||||
return exc_val is not None and isinstance(exc_val, self._exceptions or tuple())
|
|
||||||
|
|
||||||
|
|
||||||
# subprocess.Popen context manager
|
|
||||||
# avoids leaking handles if .communicate() is not called
|
|
||||||
try:
|
|
||||||
_Popen = subprocess.Popen
|
|
||||||
# check for required context manager attributes
|
|
||||||
_Popen.__enter__ and _Popen.__exit__
|
|
||||||
compat_subprocess_Popen = _Popen
|
|
||||||
except AttributeError:
|
|
||||||
# not a context manager - make one
|
|
||||||
from contextlib import contextmanager
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def compat_subprocess_Popen(*args, **kwargs):
|
|
||||||
popen = None
|
|
||||||
try:
|
|
||||||
popen = _Popen(*args, **kwargs)
|
|
||||||
yield popen
|
|
||||||
finally:
|
|
||||||
if popen:
|
|
||||||
for f in (popen.stdin, popen.stdout, popen.stderr):
|
|
||||||
if f:
|
|
||||||
# repeated .close() is OK, but just in case
|
|
||||||
with compat_contextlib_suppress(EnvironmentError):
|
|
||||||
f.close()
|
|
||||||
popen.wait()
|
|
||||||
|
|
||||||
|
|
||||||
# Fix https://github.com/ytdl-org/youtube-dl/issues/4223
|
# Fix https://github.com/ytdl-org/youtube-dl/issues/4223
|
||||||
# See http://bugs.python.org/issue9161 for what is broken
|
# See http://bugs.python.org/issue9161 for what is broken
|
||||||
def workaround_optparse_bug9161():
|
def workaround_optparse_bug9161():
|
||||||
@ -3305,7 +3263,6 @@ __all__ = [
|
|||||||
'compat_http_cookiejar_Cookie',
|
'compat_http_cookiejar_Cookie',
|
||||||
'compat_http_cookies',
|
'compat_http_cookies',
|
||||||
'compat_http_cookies_SimpleCookie',
|
'compat_http_cookies_SimpleCookie',
|
||||||
'compat_contextlib_suppress',
|
|
||||||
'compat_ctypes_WINFUNCTYPE',
|
'compat_ctypes_WINFUNCTYPE',
|
||||||
'compat_etree_fromstring',
|
'compat_etree_fromstring',
|
||||||
'compat_filter',
|
'compat_filter',
|
||||||
@ -3341,7 +3298,6 @@ __all__ = [
|
|||||||
'compat_struct_pack',
|
'compat_struct_pack',
|
||||||
'compat_struct_unpack',
|
'compat_struct_unpack',
|
||||||
'compat_subprocess_get_DEVNULL',
|
'compat_subprocess_get_DEVNULL',
|
||||||
'compat_subprocess_Popen',
|
|
||||||
'compat_tokenize_tokenize',
|
'compat_tokenize_tokenize',
|
||||||
'compat_urllib_error',
|
'compat_urllib_error',
|
||||||
'compat_urllib_parse',
|
'compat_urllib_parse',
|
||||||
|
@ -11,14 +11,8 @@ from .common import FileDownloader
|
|||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_setenv,
|
compat_setenv,
|
||||||
compat_str,
|
compat_str,
|
||||||
compat_subprocess_Popen,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
from ..postprocessor.ffmpeg import FFmpegPostProcessor, EXT_TO_OUT_FORMATS
|
from ..postprocessor.ffmpeg import FFmpegPostProcessor, EXT_TO_OUT_FORMATS
|
||||||
except ImportError:
|
|
||||||
FFmpegPostProcessor = None
|
|
||||||
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
cli_option,
|
cli_option,
|
||||||
cli_valueless_option,
|
cli_valueless_option,
|
||||||
@ -367,14 +361,13 @@ class FFmpegFD(ExternalFD):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def available(cls):
|
def available(cls):
|
||||||
# actual availability can only be confirmed for an instance
|
return FFmpegPostProcessor().available
|
||||||
return bool(FFmpegPostProcessor)
|
|
||||||
|
|
||||||
def _call_downloader(self, tmpfilename, info_dict):
|
def _call_downloader(self, tmpfilename, info_dict):
|
||||||
# `downloader` means the parent `YoutubeDL`
|
url = info_dict['url']
|
||||||
ffpp = FFmpegPostProcessor(downloader=self.ydl)
|
ffpp = FFmpegPostProcessor(downloader=self)
|
||||||
if not ffpp.available:
|
if not ffpp.available:
|
||||||
self.report_error('ffmpeg required for download but no ffmpeg (nor avconv) executable could be found. Please install one.')
|
self.report_error('m3u8 download detected but ffmpeg or avconv could not be found. Please install one.')
|
||||||
return False
|
return False
|
||||||
ffpp.check_version()
|
ffpp.check_version()
|
||||||
|
|
||||||
@ -403,7 +396,6 @@ class FFmpegFD(ExternalFD):
|
|||||||
# if end_time:
|
# if end_time:
|
||||||
# args += ['-t', compat_str(end_time - start_time)]
|
# args += ['-t', compat_str(end_time - start_time)]
|
||||||
|
|
||||||
url = info_dict['url']
|
|
||||||
cookies = self.ydl.cookiejar.get_cookies_for_url(url)
|
cookies = self.ydl.cookiejar.get_cookies_for_url(url)
|
||||||
if cookies:
|
if cookies:
|
||||||
args.extend(['-cookies', ''.join(
|
args.extend(['-cookies', ''.join(
|
||||||
@ -491,12 +483,7 @@ class FFmpegFD(ExternalFD):
|
|||||||
|
|
||||||
self._debug_cmd(args)
|
self._debug_cmd(args)
|
||||||
|
|
||||||
# From [1], a PIPE opened in Popen() should be closed, unless
|
proc = subprocess.Popen(args, stdin=subprocess.PIPE, env=env)
|
||||||
# .communicate() is called. Avoid leaking any PIPEs by using Popen
|
|
||||||
# as a context manager (newer Python 3.x and compat)
|
|
||||||
# Fixes "Resource Warning" in test/test_downloader_external.py
|
|
||||||
# [1] https://devpress.csdn.net/python/62fde12d7e66823466192e48.html
|
|
||||||
with compat_subprocess_Popen(args, stdin=subprocess.PIPE, env=env) as proc:
|
|
||||||
try:
|
try:
|
||||||
retval = proc.wait()
|
retval = proc.wait()
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
@ -509,6 +496,7 @@ class FFmpegFD(ExternalFD):
|
|||||||
process_communicate_or_kill(proc, b'q')
|
process_communicate_or_kill(proc, b'q')
|
||||||
else:
|
else:
|
||||||
proc.kill()
|
proc.kill()
|
||||||
|
proc.wait()
|
||||||
raise
|
raise
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
@ -96,7 +96,6 @@ class FFmpegPostProcessor(PostProcessor):
|
|||||||
|
|
||||||
self._paths = None
|
self._paths = None
|
||||||
self._versions = None
|
self._versions = None
|
||||||
location = None
|
|
||||||
if self._downloader:
|
if self._downloader:
|
||||||
prefer_ffmpeg = self._downloader.params.get('prefer_ffmpeg', True)
|
prefer_ffmpeg = self._downloader.params.get('prefer_ffmpeg', True)
|
||||||
location = self._downloader.params.get('ffmpeg_location')
|
location = self._downloader.params.get('ffmpeg_location')
|
||||||
@ -119,17 +118,32 @@ class FFmpegPostProcessor(PostProcessor):
|
|||||||
location = os.path.dirname(os.path.abspath(location))
|
location = os.path.dirname(os.path.abspath(location))
|
||||||
if basename in ('ffmpeg', 'ffprobe'):
|
if basename in ('ffmpeg', 'ffprobe'):
|
||||||
prefer_ffmpeg = True
|
prefer_ffmpeg = True
|
||||||
self._paths = dict(
|
|
||||||
(p, p if location is None else os.path.join(location, p))
|
|
||||||
for p in programs)
|
|
||||||
self._versions = dict(
|
|
||||||
x for x in (
|
|
||||||
(p, get_ffmpeg_version(self._paths[p])) for p in programs)
|
|
||||||
if x[1] is not None)
|
|
||||||
|
|
||||||
for p in ('ffmpeg', 'avconv')[::-1 if prefer_ffmpeg is False else 1]:
|
self._paths = dict(
|
||||||
if self._versions.get(p):
|
(p, os.path.join(location, p)) for p in programs)
|
||||||
self.basename = self.probe_basename = p
|
self._versions = dict(
|
||||||
|
(p, get_ffmpeg_version(self._paths[p])) for p in programs)
|
||||||
|
if self._versions is None:
|
||||||
|
self._versions = dict(
|
||||||
|
(p, get_ffmpeg_version(p)) for p in programs)
|
||||||
|
self._paths = dict((p, p) for p in programs)
|
||||||
|
|
||||||
|
if prefer_ffmpeg is False:
|
||||||
|
prefs = ('avconv', 'ffmpeg')
|
||||||
|
else:
|
||||||
|
prefs = ('ffmpeg', 'avconv')
|
||||||
|
for p in prefs:
|
||||||
|
if self._versions[p]:
|
||||||
|
self.basename = p
|
||||||
|
break
|
||||||
|
|
||||||
|
if prefer_ffmpeg is False:
|
||||||
|
prefs = ('avprobe', 'ffprobe')
|
||||||
|
else:
|
||||||
|
prefs = ('ffprobe', 'avprobe')
|
||||||
|
for p in prefs:
|
||||||
|
if self._versions[p]:
|
||||||
|
self.probe_basename = p
|
||||||
break
|
break
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -45,7 +45,6 @@ from .compat import (
|
|||||||
compat_casefold,
|
compat_casefold,
|
||||||
compat_chr,
|
compat_chr,
|
||||||
compat_collections_abc,
|
compat_collections_abc,
|
||||||
compat_contextlib_suppress,
|
|
||||||
compat_cookiejar,
|
compat_cookiejar,
|
||||||
compat_ctypes_WINFUNCTYPE,
|
compat_ctypes_WINFUNCTYPE,
|
||||||
compat_datetime_timedelta_total_seconds,
|
compat_datetime_timedelta_total_seconds,
|
||||||
@ -1856,18 +1855,25 @@ def write_json_file(obj, fn):
|
|||||||
try:
|
try:
|
||||||
with tf:
|
with tf:
|
||||||
json.dump(obj, tf)
|
json.dump(obj, tf)
|
||||||
with compat_contextlib_suppress(OSError):
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
# Need to remove existing file on Windows, else os.rename raises
|
# Need to remove existing file on Windows, else os.rename raises
|
||||||
# WindowsError or FileExistsError.
|
# WindowsError or FileExistsError.
|
||||||
|
try:
|
||||||
os.unlink(fn)
|
os.unlink(fn)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
mask = os.umask(0)
|
mask = os.umask(0)
|
||||||
os.umask(mask)
|
os.umask(mask)
|
||||||
os.chmod(tf.name, 0o666 & ~mask)
|
os.chmod(tf.name, 0o666 & ~mask)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
os.rename(tf.name, fn)
|
os.rename(tf.name, fn)
|
||||||
except Exception:
|
except Exception:
|
||||||
with compat_contextlib_suppress(OSError):
|
try:
|
||||||
os.remove(tf.name)
|
os.remove(tf.name)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@ -2027,13 +2033,14 @@ def extract_attributes(html_element):
|
|||||||
NB HTMLParser is stricter in Python 2.6 & 3.2 than in later versions,
|
NB HTMLParser is stricter in Python 2.6 & 3.2 than in later versions,
|
||||||
but the cases in the unit test will work for all of 2.6, 2.7, 3.2-3.5.
|
but the cases in the unit test will work for all of 2.6, 2.7, 3.2-3.5.
|
||||||
"""
|
"""
|
||||||
ret = None
|
parser = HTMLAttributeParser()
|
||||||
# Older Python may throw HTMLParseError in case of malformed HTML (and on .close()!)
|
try:
|
||||||
with compat_contextlib_suppress(compat_HTMLParseError):
|
|
||||||
with contextlib.closing(HTMLAttributeParser()) as parser:
|
|
||||||
parser.feed(html_element)
|
parser.feed(html_element)
|
||||||
ret = parser.attrs
|
parser.close()
|
||||||
return ret or {}
|
# Older Python may throw HTMLParseError in case of malformed HTML
|
||||||
|
except compat_HTMLParseError:
|
||||||
|
pass
|
||||||
|
return parser.attrs
|
||||||
|
|
||||||
|
|
||||||
def clean_html(html):
|
def clean_html(html):
|
||||||
@ -2234,8 +2241,7 @@ def _htmlentity_transform(entity_with_semicolon):
|
|||||||
numstr = '0%s' % numstr
|
numstr = '0%s' % numstr
|
||||||
else:
|
else:
|
||||||
base = 10
|
base = 10
|
||||||
# See https://github.com/ytdl-org/youtube-dl/issues/7518\
|
# See https://github.com/ytdl-org/youtube-dl/issues/7518
|
||||||
# Also, weirdly, compat_contextlib_suppress fails here in 2.6
|
|
||||||
try:
|
try:
|
||||||
return compat_chr(int(numstr, base))
|
return compat_chr(int(numstr, base))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -2342,9 +2348,11 @@ def make_HTTPS_handler(params, **kwargs):
|
|||||||
# Some servers may (wrongly) reject requests if ALPN extension is not sent. See:
|
# Some servers may (wrongly) reject requests if ALPN extension is not sent. See:
|
||||||
# https://github.com/python/cpython/issues/85140
|
# https://github.com/python/cpython/issues/85140
|
||||||
# https://github.com/yt-dlp/yt-dlp/issues/3878
|
# https://github.com/yt-dlp/yt-dlp/issues/3878
|
||||||
with compat_contextlib_suppress(AttributeError, NotImplementedError):
|
try:
|
||||||
# fails for Python < 2.7.10, not ssl.HAS_ALPN
|
|
||||||
ctx.set_alpn_protocols(ALPN_PROTOCOLS)
|
ctx.set_alpn_protocols(ALPN_PROTOCOLS)
|
||||||
|
except (AttributeError, NotImplementedError):
|
||||||
|
# Python < 2.7.10, not ssl.HAS_ALPN
|
||||||
|
pass
|
||||||
|
|
||||||
opts_no_check_certificate = params.get('nocheckcertificate', False)
|
opts_no_check_certificate = params.get('nocheckcertificate', False)
|
||||||
if hasattr(ssl, 'create_default_context'): # Python >= 3.4 or 2.7.9
|
if hasattr(ssl, 'create_default_context'): # Python >= 3.4 or 2.7.9
|
||||||
@ -2354,10 +2362,12 @@ def make_HTTPS_handler(params, **kwargs):
|
|||||||
context.check_hostname = False
|
context.check_hostname = False
|
||||||
context.verify_mode = ssl.CERT_NONE
|
context.verify_mode = ssl.CERT_NONE
|
||||||
|
|
||||||
with compat_contextlib_suppress(TypeError):
|
try:
|
||||||
# Fails with Python 2.7.8 (create_default_context present
|
|
||||||
# but HTTPSHandler has no context=)
|
|
||||||
return YoutubeDLHTTPSHandler(params, context=context, **kwargs)
|
return YoutubeDLHTTPSHandler(params, context=context, **kwargs)
|
||||||
|
except TypeError:
|
||||||
|
# Python 2.7.8
|
||||||
|
# (create_default_context present but HTTPSHandler has no context=)
|
||||||
|
pass
|
||||||
|
|
||||||
if sys.version_info < (3, 2):
|
if sys.version_info < (3, 2):
|
||||||
return YoutubeDLHTTPSHandler(params, **kwargs)
|
return YoutubeDLHTTPSHandler(params, **kwargs)
|
||||||
@ -3166,10 +3176,12 @@ def parse_iso8601(date_str, delimiter='T', timezone=None):
|
|||||||
if timezone is None:
|
if timezone is None:
|
||||||
timezone, date_str = extract_timezone(date_str)
|
timezone, date_str = extract_timezone(date_str)
|
||||||
|
|
||||||
with compat_contextlib_suppress(ValueError):
|
try:
|
||||||
date_format = '%Y-%m-%d{0}%H:%M:%S'.format(delimiter)
|
date_format = '%Y-%m-%d{0}%H:%M:%S'.format(delimiter)
|
||||||
dt = datetime.datetime.strptime(date_str, date_format) - timezone
|
dt = datetime.datetime.strptime(date_str, date_format) - timezone
|
||||||
return calendar.timegm(dt.timetuple())
|
return calendar.timegm(dt.timetuple())
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def date_formats(day_first=True):
|
def date_formats(day_first=True):
|
||||||
@ -3189,13 +3201,17 @@ def unified_strdate(date_str, day_first=True):
|
|||||||
_, date_str = extract_timezone(date_str)
|
_, date_str = extract_timezone(date_str)
|
||||||
|
|
||||||
for expression in date_formats(day_first):
|
for expression in date_formats(day_first):
|
||||||
with compat_contextlib_suppress(ValueError):
|
try:
|
||||||
upload_date = datetime.datetime.strptime(date_str, expression).strftime('%Y%m%d')
|
upload_date = datetime.datetime.strptime(date_str, expression).strftime('%Y%m%d')
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
if upload_date is None:
|
if upload_date is None:
|
||||||
timetuple = email.utils.parsedate_tz(date_str)
|
timetuple = email.utils.parsedate_tz(date_str)
|
||||||
if timetuple:
|
if timetuple:
|
||||||
with compat_contextlib_suppress(ValueError):
|
try:
|
||||||
upload_date = datetime.datetime(*timetuple[:6]).strftime('%Y%m%d')
|
upload_date = datetime.datetime(*timetuple[:6]).strftime('%Y%m%d')
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
if upload_date is not None:
|
if upload_date is not None:
|
||||||
return compat_str(upload_date)
|
return compat_str(upload_date)
|
||||||
|
|
||||||
@ -3224,9 +3240,11 @@ def unified_timestamp(date_str, day_first=True):
|
|||||||
date_str = m.group(1)
|
date_str = m.group(1)
|
||||||
|
|
||||||
for expression in date_formats(day_first):
|
for expression in date_formats(day_first):
|
||||||
with compat_contextlib_suppress(ValueError):
|
try:
|
||||||
dt = datetime.datetime.strptime(date_str, expression) - timezone + datetime.timedelta(hours=pm_delta)
|
dt = datetime.datetime.strptime(date_str, expression) - timezone + datetime.timedelta(hours=pm_delta)
|
||||||
return calendar.timegm(dt.timetuple())
|
return calendar.timegm(dt.timetuple())
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
timetuple = email.utils.parsedate_tz(date_str)
|
timetuple = email.utils.parsedate_tz(date_str)
|
||||||
if timetuple:
|
if timetuple:
|
||||||
return calendar.timegm(timetuple) + pm_delta * 3600 - compat_datetime_timedelta_total_seconds(timezone)
|
return calendar.timegm(timetuple) + pm_delta * 3600 - compat_datetime_timedelta_total_seconds(timezone)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user