mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-09-01 13:05:11 +02:00
Compare commits
5 Commits
3fd9b166bc
...
f754bb142b
Author | SHA1 | Date | |
---|---|---|---|
|
f754bb142b | ||
|
e1b3fa242c | ||
|
451046d62a | ||
|
1221873dcd | ||
|
8230a3575e |
@ -166,6 +166,14 @@ _NSIG_TESTS = [
|
|||||||
'https://www.youtube.com/s/player/b22ef6e7/player_ias.vflset/en_US/base.js',
|
'https://www.youtube.com/s/player/b22ef6e7/player_ias.vflset/en_US/base.js',
|
||||||
'b6HcntHGkvBLk_FRf', 'kNPW6A7FyP2l8A',
|
'b6HcntHGkvBLk_FRf', 'kNPW6A7FyP2l8A',
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
'https://www.youtube.com/s/player/3400486c/player_ias.vflset/en_US/base.js',
|
||||||
|
'lL46g3XifCKUZn1Xfw', 'z767lhet6V2Skl',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'https://www.youtube.com/s/player/5604538d/player_ias.vflset/en_US/base.js',
|
||||||
|
'7X-he4jjvMx7BCX', 'sViSydX8IHtdWA',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -1647,7 +1647,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
except JSInterpreter.Exception as e:
|
except JSInterpreter.Exception as e:
|
||||||
self.report_warning(
|
self.report_warning(
|
||||||
'%s (%s %s)' % (
|
'%s (%s %s)' % (
|
||||||
'Unable to decode n-parameter: download likely to be throttled',
|
'Unable to decode n-parameter: expect download to be blocked or throttled',
|
||||||
error_to_compat_str(e),
|
error_to_compat_str(e),
|
||||||
traceback.format_exc()),
|
traceback.format_exc()),
|
||||||
video_id=video_id)
|
video_id=video_id)
|
||||||
@ -1659,18 +1659,22 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
def _extract_n_function_name(self, jscode):
|
def _extract_n_function_name(self, jscode):
|
||||||
func_name, idx = self._search_regex(
|
func_name, idx = self._search_regex(
|
||||||
# new: (b=String.fromCharCode(110),c=a.get(b))&&c=nfunc[idx](c)
|
# new: (b=String.fromCharCode(110),c=a.get(b))&&c=nfunc[idx](c)
|
||||||
|
# or: (b="nn"[+a.D],c=a.get(b))&&(c=nfunc[idx](c)s
|
||||||
# old: .get("n"))&&(b=nfunc[idx](b)
|
# old: .get("n"))&&(b=nfunc[idx](b)
|
||||||
# older: .get("n"))&&(b=nfunc(b)
|
# older: .get("n"))&&(b=nfunc(b)
|
||||||
r'''(?x)
|
r'''(?x)
|
||||||
(?:\(\s*(?P<b>[a-z])\s*=\s*String\s*\.\s*fromCharCode\s*\(\s*110\s*\)\s*,(?P<c>[a-z])\s*=\s*[a-z]\s*)?
|
(?:\(\s*(?P<b>[a-z])\s*=\s*(?:
|
||||||
\.\s*get\s*\(\s*(?(b)(?P=b)|"n")(?:\s*\)){2}\s*&&\s*\(\s*(?(c)(?P=c)|b)\s*=\s*
|
String\s*\.\s*fromCharCode\s*\(\s*110\s*\)|
|
||||||
|
"n+"\[\s*\+?s*[\w$.]+\s*]
|
||||||
|
)\s*,(?P<c>[a-z])\s*=\s*[a-z]\s*)?
|
||||||
|
\.\s*get\s*\(\s*(?(b)(?P=b)|"n{1,2}")(?:\s*\)){2}\s*&&\s*\(\s*(?(c)(?P=c)|b)\s*=\s*
|
||||||
(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\s*\[(?P<idx>\d+)\])?\s*\(\s*[\w$]+\s*\)
|
(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\s*\[(?P<idx>\d+)\])?\s*\(\s*[\w$]+\s*\)
|
||||||
''', jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
|
''', jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
|
||||||
if not idx:
|
if not idx:
|
||||||
return func_name
|
return func_name
|
||||||
|
|
||||||
return self._parse_json(self._search_regex(
|
return self._parse_json(self._search_regex(
|
||||||
r'var {0}\s*=\s*(\[.+?\])\s*[,;]'.format(re.escape(func_name)), jscode,
|
r'var\s+{0}\s*=\s*(\[.+?\])\s*[,;]'.format(re.escape(func_name)), jscode,
|
||||||
'Initial JS player n function list ({0}.{1})'.format(func_name, idx)),
|
'Initial JS player n function list ({0}.{1})'.format(func_name, idx)),
|
||||||
func_name, transform_source=js_to_json)[int(idx)]
|
func_name, transform_source=js_to_json)[int(idx)]
|
||||||
|
|
||||||
|
@ -2057,7 +2057,8 @@ def sanitize_open(filename, open_mode):
|
|||||||
import msvcrt
|
import msvcrt
|
||||||
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
||||||
return (sys.stdout.buffer if hasattr(sys.stdout, 'buffer') else sys.stdout, filename)
|
return (sys.stdout.buffer if hasattr(sys.stdout, 'buffer') else sys.stdout, filename)
|
||||||
stream = open(encodeFilename(filename), open_mode)
|
stream = locked_file(encodeFilename(filename), open_mode, block=False)
|
||||||
|
stream = stream.__enter__()
|
||||||
return (stream, filename)
|
return (stream, filename)
|
||||||
except (IOError, OSError) as err:
|
except (IOError, OSError) as err:
|
||||||
if err.errno in (errno.EACCES,):
|
if err.errno in (errno.EACCES,):
|
||||||
@ -2069,7 +2070,8 @@ def sanitize_open(filename, open_mode):
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
# An exception here should be caught in the caller
|
# An exception here should be caught in the caller
|
||||||
stream = open(encodeFilename(alt_filename), open_mode)
|
stream = locked_file(encodeFilename(filename), open_mode, block=False)
|
||||||
|
stream = stream.__enter__()
|
||||||
return (stream, alt_filename)
|
return (stream, alt_filename)
|
||||||
|
|
||||||
|
|
||||||
@ -3498,15 +3500,18 @@ else:
|
|||||||
try:
|
try:
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
def _lock_file(f, exclusive):
|
def _lock_file(f, exclusive, block):
|
||||||
fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
|
if block:
|
||||||
|
fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
|
||||||
|
else:
|
||||||
|
fcntl.flock(f, fcntl.LOCK_EX|fcntl.LOCK_NB if exclusive else fcntl.LOCK_SH)
|
||||||
|
|
||||||
def _unlock_file(f):
|
def _unlock_file(f):
|
||||||
fcntl.flock(f, fcntl.LOCK_UN)
|
fcntl.flock(f, fcntl.LOCK_UN)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
UNSUPPORTED_MSG = 'file locking is not supported on this platform'
|
UNSUPPORTED_MSG = 'file locking is not supported on this platform'
|
||||||
|
|
||||||
def _lock_file(f, exclusive):
|
def _lock_file(f, exclusive, block):
|
||||||
raise IOError(UNSUPPORTED_MSG)
|
raise IOError(UNSUPPORTED_MSG)
|
||||||
|
|
||||||
def _unlock_file(f):
|
def _unlock_file(f):
|
||||||
@ -3514,15 +3519,16 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
class locked_file(object):
|
class locked_file(object):
|
||||||
def __init__(self, filename, mode, encoding=None):
|
def __init__(self, filename, mode, block=True, encoding=None):
|
||||||
assert mode in ['r', 'a', 'w']
|
assert mode in ['r', 'rb', 'a', 'ab', 'w', 'wb']
|
||||||
self.f = io.open(filename, mode, encoding=encoding)
|
self.f = io.open(filename, mode, encoding=encoding)
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
self.block = block
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
exclusive = self.mode != 'r'
|
exclusive = self.mode not in ['r', 'rb']
|
||||||
try:
|
try:
|
||||||
_lock_file(self.f, exclusive)
|
_lock_file(self.f, exclusive, self.block)
|
||||||
except IOError:
|
except IOError:
|
||||||
self.f.close()
|
self.f.close()
|
||||||
raise
|
raise
|
||||||
@ -3543,6 +3549,11 @@ class locked_file(object):
|
|||||||
def read(self, *args):
|
def read(self, *args):
|
||||||
return self.f.read(*args)
|
return self.f.read(*args)
|
||||||
|
|
||||||
|
def flush(self, *args):
|
||||||
|
self.f.flush()
|
||||||
|
|
||||||
|
def close(self, *args):
|
||||||
|
self.__exit__(self, *args, value=False, traceback=False)
|
||||||
|
|
||||||
def get_filesystem_encoding():
|
def get_filesystem_encoding():
|
||||||
encoding = sys.getfilesystemencoding()
|
encoding = sys.getfilesystemencoding()
|
||||||
|
Loading…
Reference in New Issue
Block a user