mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-07-18 01:14:14 +09:00
Compare commits
5 Commits
77642776af
...
1dac7d07a7
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1dac7d07a7 | ||
![]() |
673277e510 | ||
![]() |
91b1569f68 | ||
![]() |
711e72c292 | ||
![]() |
26b6f15d14 |
@ -459,6 +459,10 @@ class TestJSInterpreter(unittest.TestCase):
|
|||||||
self._test('function f(){return undefined >> 5}', 0)
|
self._test('function f(){return undefined >> 5}', 0)
|
||||||
self._test('function f(){return 42 << NaN}', 42)
|
self._test('function f(){return 42 << NaN}', 42)
|
||||||
self._test('function f(){return 42 << Infinity}', 42)
|
self._test('function f(){return 42 << Infinity}', 42)
|
||||||
|
self._test('function f(){return 0.0 << null}', 0)
|
||||||
|
self._test('function f(){return NaN << 42}', 0)
|
||||||
|
self._test('function f(){return "21.9" << 1}', 42)
|
||||||
|
self._test('function f(){return 21 << 4294967297}', 42)
|
||||||
|
|
||||||
def test_negative(self):
|
def test_negative(self):
|
||||||
self._test('function f(){return 2 * -2.0 ;}', -4)
|
self._test('function f(){return 2 * -2.0 ;}', -4)
|
||||||
|
@ -219,6 +219,10 @@ _NSIG_TESTS = [
|
|||||||
'https://www.youtube.com/s/player/2f1832d2/player_ias.vflset/en_US/base.js',
|
'https://www.youtube.com/s/player/2f1832d2/player_ias.vflset/en_US/base.js',
|
||||||
'YWt1qdbe8SAfkoPHW5d', 'RrRjWQOJmBiP',
|
'YWt1qdbe8SAfkoPHW5d', 'RrRjWQOJmBiP',
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
'https://www.youtube.com/s/player/9c6dfc4a/player_ias.vflset/en_US/base.js',
|
||||||
|
'jbu7ylIosQHyJyJV', 'uwI0ESiynAmhNg',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,9 +10,10 @@ from .compat import (
|
|||||||
# https://github.com/unicode-org/icu/blob/main/icu4c/source/data/unidata/CaseFolding.txt
|
# https://github.com/unicode-org/icu/blob/main/icu4c/source/data/unidata/CaseFolding.txt
|
||||||
# In case newly foldable Unicode characters are defined, paste the new version
|
# In case newly foldable Unicode characters are defined, paste the new version
|
||||||
# of the text inside the ''' marks.
|
# of the text inside the ''' marks.
|
||||||
# The text is expected to have only blank lines andlines with 1st character #,
|
# The text is expected to have only blank lines and lines with 1st character #,
|
||||||
# all ignored, and fold definitions like this:
|
# all ignored, and fold definitions like this:
|
||||||
# `from_hex_code; space_separated_to_hex_code_list; comment`
|
# `from_hex_code; status; space_separated_to_hex_code_list; comment`
|
||||||
|
# Only `status` C/F are used.
|
||||||
|
|
||||||
_map_str = '''
|
_map_str = '''
|
||||||
# CaseFolding-15.0.0.txt
|
# CaseFolding-15.0.0.txt
|
||||||
@ -1657,11 +1658,6 @@ _map = dict(
|
|||||||
del _map_str
|
del _map_str
|
||||||
|
|
||||||
|
|
||||||
def casefold(s):
|
def _casefold(s):
|
||||||
assert isinstance(s, compat_str)
|
assert isinstance(s, compat_str)
|
||||||
return ''.join((_map.get(c, c) for c in s))
|
return ''.join((_map.get(c, c) for c in s))
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
'casefold',
|
|
||||||
]
|
|
||||||
|
@ -44,7 +44,7 @@ try:
|
|||||||
compat_str.casefold
|
compat_str.casefold
|
||||||
compat_casefold = lambda s: s.casefold()
|
compat_casefold = lambda s: s.casefold()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
from .casefold import casefold as compat_casefold
|
from .casefold import _casefold as compat_casefold
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import collections.abc as compat_collections_abc
|
import collections.abc as compat_collections_abc
|
||||||
@ -3116,17 +3116,21 @@ else:
|
|||||||
compat_kwargs = lambda kwargs: kwargs
|
compat_kwargs = lambda kwargs: kwargs
|
||||||
|
|
||||||
|
|
||||||
|
# compat_numeric_types
|
||||||
try:
|
try:
|
||||||
compat_numeric_types = (int, float, long, complex)
|
compat_numeric_types = (int, float, long, complex)
|
||||||
except NameError: # Python 3
|
except NameError: # Python 3
|
||||||
compat_numeric_types = (int, float, complex)
|
compat_numeric_types = (int, float, complex)
|
||||||
|
|
||||||
|
|
||||||
|
# compat_integer_types
|
||||||
try:
|
try:
|
||||||
compat_integer_types = (int, long)
|
compat_integer_types = (int, long)
|
||||||
except NameError: # Python 3
|
except NameError: # Python 3
|
||||||
compat_integer_types = (int, )
|
compat_integer_types = (int, )
|
||||||
|
|
||||||
|
# compat_int
|
||||||
|
compat_int = compat_integer_types[-1]
|
||||||
|
|
||||||
if sys.version_info < (2, 7):
|
if sys.version_info < (2, 7):
|
||||||
def compat_socket_create_connection(address, timeout, source_address=None):
|
def compat_socket_create_connection(address, timeout, source_address=None):
|
||||||
@ -3532,6 +3536,7 @@ __all__ = [
|
|||||||
'compat_http_client',
|
'compat_http_client',
|
||||||
'compat_http_server',
|
'compat_http_server',
|
||||||
'compat_input',
|
'compat_input',
|
||||||
|
'compat_int',
|
||||||
'compat_integer_types',
|
'compat_integer_types',
|
||||||
'compat_itertools_count',
|
'compat_itertools_count',
|
||||||
'compat_itertools_zip_longest',
|
'compat_itertools_zip_longest',
|
||||||
|
@ -27,6 +27,7 @@ from ..compat import (
|
|||||||
)
|
)
|
||||||
from ..jsinterp import JSInterpreter
|
from ..jsinterp import JSInterpreter
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
bug_reports_message,
|
||||||
clean_html,
|
clean_html,
|
||||||
dict_get,
|
dict_get,
|
||||||
error_to_compat_str,
|
error_to_compat_str,
|
||||||
@ -65,6 +66,7 @@ from ..utils import (
|
|||||||
url_or_none,
|
url_or_none,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
urljoin,
|
urljoin,
|
||||||
|
variadic,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -460,6 +462,26 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|||||||
'uploader': uploader,
|
'uploader': uploader,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _extract_thumbnails(data, *path_list, **kw_final_key):
|
||||||
|
"""
|
||||||
|
Extract thumbnails from thumbnails dict
|
||||||
|
@param path_list: path list to level that contains 'thumbnails' key
|
||||||
|
"""
|
||||||
|
final_key = kw_final_key.get('final_key', 'thumbnails')
|
||||||
|
|
||||||
|
return traverse_obj(data, ((
|
||||||
|
tuple(variadic(path) + (final_key, Ellipsis)
|
||||||
|
for path in path_list or [()])), {
|
||||||
|
'url': ('url', T(url_or_none),
|
||||||
|
# Sometimes youtube gives a wrong thumbnail URL. See:
|
||||||
|
# https://github.com/yt-dlp/yt-dlp/issues/233
|
||||||
|
# https://github.com/ytdl-org/youtube-dl/issues/28023
|
||||||
|
T(lambda u: update_url(u, query=None) if u and 'maxresdefault' in u else u)),
|
||||||
|
'height': ('height', T(int_or_none)),
|
||||||
|
'width': ('width', T(int_or_none)),
|
||||||
|
}, T(lambda t: t if t.get('url') else None)))
|
||||||
|
|
||||||
def _search_results(self, query, params):
|
def _search_results(self, query, params):
|
||||||
data = {
|
data = {
|
||||||
'context': {
|
'context': {
|
||||||
@ -3183,8 +3205,12 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
|||||||
expected_type=txt_or_none)
|
expected_type=txt_or_none)
|
||||||
|
|
||||||
def _grid_entries(self, grid_renderer):
|
def _grid_entries(self, grid_renderer):
|
||||||
for item in grid_renderer['items']:
|
for item in traverse_obj(grid_renderer, ('items', Ellipsis, T(dict))):
|
||||||
if not isinstance(item, dict):
|
lockup_view_model = traverse_obj(item, ('lockupViewModel', T(dict)))
|
||||||
|
if lockup_view_model:
|
||||||
|
entry = self._extract_lockup_view_model(lockup_view_model)
|
||||||
|
if entry:
|
||||||
|
yield entry
|
||||||
continue
|
continue
|
||||||
renderer = self._extract_grid_item_renderer(item)
|
renderer = self._extract_grid_item_renderer(item)
|
||||||
if not isinstance(renderer, dict):
|
if not isinstance(renderer, dict):
|
||||||
@ -3268,6 +3294,25 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
|||||||
continue
|
continue
|
||||||
yield self._extract_video(renderer)
|
yield self._extract_video(renderer)
|
||||||
|
|
||||||
|
def _extract_lockup_view_model(self, view_model):
|
||||||
|
content_id = view_model.get('contentId')
|
||||||
|
if not content_id:
|
||||||
|
return
|
||||||
|
content_type = view_model.get('contentType')
|
||||||
|
if content_type not in ('LOCKUP_CONTENT_TYPE_PLAYLIST', 'LOCKUP_CONTENT_TYPE_PODCAST'):
|
||||||
|
self.report_warning(
|
||||||
|
'Unsupported lockup view model content type "{0}"{1}'.format(content_type, bug_reports_message()), only_once=True)
|
||||||
|
return
|
||||||
|
return merge_dicts(self.url_result(
|
||||||
|
update_url_query('https://www.youtube.com/playlist', {'list': content_id}),
|
||||||
|
ie=YoutubeTabIE.ie_key(), video_id=content_id), {
|
||||||
|
'title': traverse_obj(view_model, (
|
||||||
|
'metadata', 'lockupMetadataViewModel', 'title', 'content', T(compat_str))),
|
||||||
|
'thumbnails': self._extract_thumbnails(view_model, (
|
||||||
|
'contentImage', 'collectionThumbnailViewModel', 'primaryThumbnail',
|
||||||
|
'thumbnailViewModel', 'image'), final_key='sources'),
|
||||||
|
})
|
||||||
|
|
||||||
def _video_entry(self, video_renderer):
|
def _video_entry(self, video_renderer):
|
||||||
video_id = video_renderer.get('videoId')
|
video_id = video_renderer.get('videoId')
|
||||||
if video_id:
|
if video_id:
|
||||||
|
@ -24,6 +24,8 @@ from .compat import (
|
|||||||
compat_collections_chain_map as ChainMap,
|
compat_collections_chain_map as ChainMap,
|
||||||
compat_contextlib_suppress,
|
compat_contextlib_suppress,
|
||||||
compat_filter as filter,
|
compat_filter as filter,
|
||||||
|
compat_int,
|
||||||
|
compat_integer_types,
|
||||||
compat_itertools_zip_longest as zip_longest,
|
compat_itertools_zip_longest as zip_longest,
|
||||||
compat_map as map,
|
compat_map as map,
|
||||||
compat_numeric_types,
|
compat_numeric_types,
|
||||||
@ -70,14 +72,27 @@ class JS_Undefined(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _js_bit_op(op):
|
def _js_bit_op(op, is_shift=False):
|
||||||
|
|
||||||
def zeroise(x):
|
def zeroise(x, is_shift_arg=False):
|
||||||
return 0 if x in (None, JS_Undefined, _NaN, _Infinity) else x
|
if isinstance(x, compat_integer_types):
|
||||||
|
return (x % 32) if is_shift_arg else (x & 0xffffffff)
|
||||||
|
try:
|
||||||
|
x = float(x)
|
||||||
|
if is_shift_arg:
|
||||||
|
x = int(x % 32)
|
||||||
|
elif x < 0:
|
||||||
|
x = -compat_int(-x % 0xffffffff)
|
||||||
|
else:
|
||||||
|
x = compat_int(x % 0xffffffff)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
# also here for int(NaN), including float('inf') % 32
|
||||||
|
x = 0
|
||||||
|
return x
|
||||||
|
|
||||||
@wraps_op(op)
|
@wraps_op(op)
|
||||||
def wrapped(a, b):
|
def wrapped(a, b):
|
||||||
return op(zeroise(a), zeroise(b)) & 0xffffffff
|
return op(zeroise(a), zeroise(b, is_shift)) & 0xffffffff
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
@ -253,8 +268,8 @@ def _js_typeof(expr):
|
|||||||
# avoid dict to maintain order
|
# avoid dict to maintain order
|
||||||
# definition None => Defined in JSInterpreter._operator
|
# definition None => Defined in JSInterpreter._operator
|
||||||
_OPERATORS = (
|
_OPERATORS = (
|
||||||
('>>', _js_bit_op(operator.rshift)),
|
('>>', _js_bit_op(operator.rshift, True)),
|
||||||
('<<', _js_bit_op(operator.lshift)),
|
('<<', _js_bit_op(operator.lshift, True)),
|
||||||
('+', _js_add),
|
('+', _js_add),
|
||||||
('-', _js_arith_op(operator.sub)),
|
('-', _js_arith_op(operator.sub)),
|
||||||
('*', _js_arith_op(operator.mul)),
|
('*', _js_arith_op(operator.mul)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user