1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-12-30 11:31:25 +00:00

matrix download test

This commit is contained in:
c-basalt
2025-02-19 16:50:05 -05:00
parent af4f71c44a
commit 076ca745aa
3 changed files with 60 additions and 20 deletions

View File

@@ -398,6 +398,27 @@ class IqIE(InfoExtractor):
IE_DESC = 'International version of iQiyi'
_VALID_URL = r'https?://(?:www\.)?iq\.com/play/(?:[\w%-]*-)?(?P<id>\w+)'
_TESTS = [{
'url': 'https://www.iq.com/play/sangmin-dinneaw-episode-1-xmk7546rfw',
'md5': '63fcb4b7d4863472fe0a9be75d9e9d60',
'info_dict': {
'ext': 'mp4',
'id': 'xmk7546rfw',
'title': '尚岷与丁尼奥 第1集',
'description': 'md5:e8fe4a8da25f4b8c86bc5506b1c3faaa',
'duration': 3092,
'timestamp': 1735520401,
'upload_date': '20241230',
'episode_number': 1,
'episode': 'Episode 1',
'series': 'Sangmin Dinneaw',
'age_limit': 18,
'average_rating': float,
'categories': [],
'cast': ['Sangmin Choi', 'Ratana Aiamsaart'],
},
'expected_warnings': ['format is restricted'],
'jsi_matrix_features': ['dom'],
}, {
'url': 'https://www.iq.com/play/one-piece-episode-1000-1ma1i6ferf4',
'md5': '2d7caf6eeca8a32b407094b33b757d39',
'info_dict': {
@@ -418,6 +439,7 @@ class IqIE(InfoExtractor):
'format': '500',
},
'expected_warnings': ['format is restricted'],
'skip': 'geo-restricted',
}, {
# VIP-restricted video
'url': 'https://www.iq.com/play/mermaid-in-the-fog-2021-gbdpx13bs4',

View File

@@ -31,6 +31,17 @@ def get_jsi_keys(jsi_or_keys: typing.Iterable[str | type[JSI] | JSI]) -> list[st
return [jok if isinstance(jok, str) else jok.JSI_KEY for jok in jsi_or_keys]
def filter_jsi_include(only_include: typing.Iterable[str] | None, exclude: typing.Iterable[str] | None):
keys = get_jsi_keys(only_include) if only_include else _JSI_HANDLERS.keys()
return [key for key in keys if key not in (exclude or [])]
def filter_jsi_feature(features: typing.Iterable[str], keys=None):
keys = keys if keys is not None else _JSI_HANDLERS.keys()
return [key for key in keys if key in _JSI_HANDLERS
and _JSI_HANDLERS[key]._SUPPORTED_FEATURES.issuperset(features)]
def order_to_pref(jsi_order: typing.Iterable[str | type[JSI] | JSI], multiplier: int) -> JSIPreference:
jsi_order = reversed(get_jsi_keys(jsi_order))
pref_score = {jsi_cls: (i + 1) * multiplier for i, jsi_cls in enumerate(jsi_order)}
@@ -112,10 +123,9 @@ class JSIWrapper:
self.report_warning(f'`{invalid_key}` is not a valid JSI, ignoring preference setting')
user_prefs.remove(invalid_key)
jsi_keys = [key for key in get_jsi_keys(only_include or _JSI_HANDLERS) if key not in get_jsi_keys(exclude)]
jsi_keys = filter_jsi_include(only_include, exclude)
self.write_debug(f'Allowed JSI keys: {jsi_keys}')
handler_classes = [_JSI_HANDLERS[key] for key in jsi_keys
if _JSI_HANDLERS[key]._SUPPORTED_FEATURES.issuperset(self._features)]
handler_classes = [_JSI_HANDLERS[key] for key in filter_jsi_feature(self._features, jsi_keys)]
self.write_debug(f'Select JSI for features={self._features}: {get_jsi_keys(handler_classes)}, '
f'included: {get_jsi_keys(only_include) or "all"}, excluded: {get_jsi_keys(exclude)}')
if not handler_classes:
@@ -159,38 +169,25 @@ class JSIWrapper:
unavailable: list[str] = []
exceptions: list[tuple[JSI, Exception]] = []
test_results: list[tuple[JSI, typing.Any]] = []
for handler in handlers:
if not handler.is_available():
if self._is_test:
raise Exception(f'{handler.JSI_NAME} is not available for testing, '
f'add "{handler.JSI_KEY}" in `exclude` if it should not be used')
raise ExtractorError(f'{handler.JSI_NAME} is not available for testing, '
f'add "{handler.JSI_KEY}" in `exclude` if it should not be used')
self.write_debug(f'{handler.JSI_KEY} is not available')
unavailable.append(handler.JSI_NAME)
continue
try:
self.write_debug(f'Dispatching `{method_name}` task to {handler.JSI_NAME}')
result = getattr(handler, method_name)(*args, **kwargs)
if self._is_test:
test_results.append((handler, result))
else:
return result
except Exception as e:
return getattr(handler, method_name)(*args, **kwargs)
except ExtractorError as e:
if handler.JSI_KEY not in self._fallback_jsi:
raise
else:
exceptions.append((handler, e))
self.write_debug(f'{handler.JSI_NAME} encountered error, fallback to next handler: {e}')
if self._is_test and test_results:
ref_handler, ref_result = test_results[0]
for handler, result in test_results[1:]:
if result != ref_result:
self.report_warning(
f'Different JSI results produced from {ref_handler.JSI_NAME} and {handler.JSI_NAME}')
return ref_result
if not exceptions:
msg = f'No available JSI installed, please install one of: {", ".join(unavailable)}'
else: