mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-26 09:11:25 +01:00
Compare commits
8 Commits
d42fc5bf72
...
3576c013fd
Author | SHA1 | Date | |
---|---|---|---|
|
3576c013fd | ||
|
c699bafc50 | ||
|
eb64ae7d5d | ||
|
c014fbcddc | ||
|
39d79c9b9c | ||
|
2eaf303b63 | ||
|
367ec929f4 | ||
|
b901e4fb8a |
|
@ -481,7 +481,7 @@ class TestTraversalHelpers:
|
||||||
'id': 'name',
|
'id': 'name',
|
||||||
'data': 'content',
|
'data': 'content',
|
||||||
'url': 'url',
|
'url': 'url',
|
||||||
}, all, {subs_list_to_dict}]) == {
|
}, all, {subs_list_to_dict(lang=None)}]) == {
|
||||||
'de': [{'url': 'https://example.com/subs/de.ass'}],
|
'de': [{'url': 'https://example.com/subs/de.ass'}],
|
||||||
'en': [{'data': 'content'}],
|
'en': [{'data': 'content'}],
|
||||||
}, 'subs with mandatory items missing should be filtered'
|
}, 'subs with mandatory items missing should be filtered'
|
||||||
|
@ -507,6 +507,54 @@ class TestTraversalHelpers:
|
||||||
{'url': 'https://example.com/subs/en1', 'ext': 'ext'},
|
{'url': 'https://example.com/subs/en1', 'ext': 'ext'},
|
||||||
{'url': 'https://example.com/subs/en2', 'ext': 'ext'},
|
{'url': 'https://example.com/subs/en2', 'ext': 'ext'},
|
||||||
]}, '`quality` key should sort subtitle list accordingly'
|
]}, '`quality` key should sort subtitle list accordingly'
|
||||||
|
assert traverse_obj([
|
||||||
|
{'name': 'de', 'url': 'https://example.com/subs/de.ass'},
|
||||||
|
{'name': 'de'},
|
||||||
|
{'name': 'en', 'content': 'content'},
|
||||||
|
{'url': 'https://example.com/subs/en'},
|
||||||
|
], [..., {
|
||||||
|
'id': 'name',
|
||||||
|
'url': 'url',
|
||||||
|
'data': 'content',
|
||||||
|
}, all, {subs_list_to_dict(lang='en')}]) == {
|
||||||
|
'de': [{'url': 'https://example.com/subs/de.ass'}],
|
||||||
|
'en': [
|
||||||
|
{'data': 'content'},
|
||||||
|
{'url': 'https://example.com/subs/en'},
|
||||||
|
],
|
||||||
|
}, 'optionally provided lang should be used if no id available'
|
||||||
|
assert traverse_obj([
|
||||||
|
{'name': 1, 'url': 'https://example.com/subs/de1'},
|
||||||
|
{'name': {}, 'url': 'https://example.com/subs/de2'},
|
||||||
|
{'name': 'de', 'ext': 1, 'url': 'https://example.com/subs/de3'},
|
||||||
|
{'name': 'de', 'ext': {}, 'url': 'https://example.com/subs/de4'},
|
||||||
|
], [..., {
|
||||||
|
'id': 'name',
|
||||||
|
'url': 'url',
|
||||||
|
'ext': 'ext',
|
||||||
|
}, all, {subs_list_to_dict(lang=None)}]) == {
|
||||||
|
'de': [
|
||||||
|
{'url': 'https://example.com/subs/de3'},
|
||||||
|
{'url': 'https://example.com/subs/de4'},
|
||||||
|
],
|
||||||
|
}, 'non str types should be ignored for id and ext'
|
||||||
|
assert traverse_obj([
|
||||||
|
{'name': 1, 'url': 'https://example.com/subs/de1'},
|
||||||
|
{'name': {}, 'url': 'https://example.com/subs/de2'},
|
||||||
|
{'name': 'de', 'ext': 1, 'url': 'https://example.com/subs/de3'},
|
||||||
|
{'name': 'de', 'ext': {}, 'url': 'https://example.com/subs/de4'},
|
||||||
|
], [..., {
|
||||||
|
'id': 'name',
|
||||||
|
'url': 'url',
|
||||||
|
'ext': 'ext',
|
||||||
|
}, all, {subs_list_to_dict(lang='de')}]) == {
|
||||||
|
'de': [
|
||||||
|
{'url': 'https://example.com/subs/de1'},
|
||||||
|
{'url': 'https://example.com/subs/de2'},
|
||||||
|
{'url': 'https://example.com/subs/de3'},
|
||||||
|
{'url': 'https://example.com/subs/de4'},
|
||||||
|
],
|
||||||
|
}, 'non str types should be replaced by default id'
|
||||||
|
|
||||||
def test_trim_str(self):
|
def test_trim_str(self):
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
|
@ -525,7 +573,7 @@ class TestTraversalHelpers:
|
||||||
def test_unpack(self):
|
def test_unpack(self):
|
||||||
assert unpack(lambda *x: ''.join(map(str, x)))([1, 2, 3]) == '123'
|
assert unpack(lambda *x: ''.join(map(str, x)))([1, 2, 3]) == '123'
|
||||||
assert unpack(join_nonempty)([1, 2, 3]) == '1-2-3'
|
assert unpack(join_nonempty)([1, 2, 3]) == '1-2-3'
|
||||||
assert unpack(join_nonempty(delim=' '))([1, 2, 3]) == '1 2 3'
|
assert unpack(join_nonempty, delim=' ')([1, 2, 3]) == '1 2 3'
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
unpack(join_nonempty)()
|
unpack(join_nonempty)()
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
|
|
|
@ -72,7 +72,6 @@ from yt_dlp.utils import (
|
||||||
intlist_to_bytes,
|
intlist_to_bytes,
|
||||||
iri_to_uri,
|
iri_to_uri,
|
||||||
is_html,
|
is_html,
|
||||||
join_nonempty,
|
|
||||||
js_to_json,
|
js_to_json,
|
||||||
limit_length,
|
limit_length,
|
||||||
locked_file,
|
locked_file,
|
||||||
|
@ -2158,10 +2157,6 @@ Line 1
|
||||||
assert int_or_none(v=10) == 10, 'keyword passed positional should call function'
|
assert int_or_none(v=10) == 10, 'keyword passed positional should call function'
|
||||||
assert int_or_none(scale=0.1)(10) == 100, 'call after partial application should call the function'
|
assert int_or_none(scale=0.1)(10) == 100, 'call after partial application should call the function'
|
||||||
|
|
||||||
assert callable(join_nonempty(delim=', ')), 'varargs positional should apply partially'
|
|
||||||
assert callable(join_nonempty()), 'varargs positional should apply partially'
|
|
||||||
assert join_nonempty(None, delim=', ') == '', 'passed varargs should call the function'
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -4381,7 +4381,9 @@ class YoutubeDL:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for idx, t in list(enumerate(thumbnails))[::-1]:
|
for idx, t in list(enumerate(thumbnails))[::-1]:
|
||||||
thumb_ext = (f'{t["id"]}.' if multiple else '') + determine_ext(t['url'], 'jpg')
|
thumb_ext = t.get('ext') or determine_ext(t['url'], 'jpg')
|
||||||
|
if multiple:
|
||||||
|
thumb_ext = f'{t["id"]}.{thumb_ext}'
|
||||||
thumb_display_id = f'{label} thumbnail {t["id"]}'
|
thumb_display_id = f'{label} thumbnail {t["id"]}'
|
||||||
thumb_filename = replace_extension(filename, thumb_ext, info_dict.get('ext'))
|
thumb_filename = replace_extension(filename, thumb_ext, info_dict.get('ext'))
|
||||||
thumb_filename_final = replace_extension(thumb_filename_base, thumb_ext, info_dict.get('ext'))
|
thumb_filename_final = replace_extension(thumb_filename_base, thumb_ext, info_dict.get('ext'))
|
||||||
|
|
|
@ -66,6 +66,14 @@ class AfreecaTVBaseIE(InfoExtractor):
|
||||||
extensions={'legacy_ssl': True}), display_id,
|
extensions={'legacy_ssl': True}), display_id,
|
||||||
'Downloading API JSON', 'Unable to download API JSON')
|
'Downloading API JSON', 'Unable to download API JSON')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _fixup_thumb(thumb_url):
|
||||||
|
if not url_or_none(thumb_url):
|
||||||
|
return None
|
||||||
|
# Core would determine_ext as 'php' from the url, so we need to provide the real ext
|
||||||
|
# See: https://github.com/yt-dlp/yt-dlp/issues/11537
|
||||||
|
return [{'url': thumb_url, 'ext': 'jpg'}]
|
||||||
|
|
||||||
|
|
||||||
class AfreecaTVIE(AfreecaTVBaseIE):
|
class AfreecaTVIE(AfreecaTVBaseIE):
|
||||||
IE_NAME = 'soop'
|
IE_NAME = 'soop'
|
||||||
|
@ -155,7 +163,7 @@ class AfreecaTVIE(AfreecaTVBaseIE):
|
||||||
'uploader': ('writer_nick', {str}),
|
'uploader': ('writer_nick', {str}),
|
||||||
'uploader_id': ('bj_id', {str}),
|
'uploader_id': ('bj_id', {str}),
|
||||||
'duration': ('total_file_duration', {int_or_none(scale=1000)}),
|
'duration': ('total_file_duration', {int_or_none(scale=1000)}),
|
||||||
'thumbnail': ('thumb', {url_or_none}),
|
'thumbnails': ('thumb', {self._fixup_thumb}),
|
||||||
})
|
})
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
|
@ -226,8 +234,7 @@ class AfreecaTVCatchStoryIE(AfreecaTVBaseIE):
|
||||||
|
|
||||||
return self.playlist_result(self._entries(data), video_id)
|
return self.playlist_result(self._entries(data), video_id)
|
||||||
|
|
||||||
@staticmethod
|
def _entries(self, data):
|
||||||
def _entries(data):
|
|
||||||
# 'files' is always a list with 1 element
|
# 'files' is always a list with 1 element
|
||||||
yield from traverse_obj(data, (
|
yield from traverse_obj(data, (
|
||||||
'data', lambda _, v: v['story_type'] == 'catch',
|
'data', lambda _, v: v['story_type'] == 'catch',
|
||||||
|
@ -238,7 +245,7 @@ class AfreecaTVCatchStoryIE(AfreecaTVBaseIE):
|
||||||
'title': ('title', {str}),
|
'title': ('title', {str}),
|
||||||
'uploader': ('writer_nick', {str}),
|
'uploader': ('writer_nick', {str}),
|
||||||
'uploader_id': ('writer_id', {str}),
|
'uploader_id': ('writer_id', {str}),
|
||||||
'thumbnail': ('thumb', {url_or_none}),
|
'thumbnails': ('thumb', {self._fixup_thumb}),
|
||||||
'timestamp': ('write_timestamp', {int_or_none}),
|
'timestamp': ('write_timestamp', {int_or_none}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
|
@ -279,6 +279,7 @@ class InfoExtractor:
|
||||||
thumbnails: A list of dictionaries, with the following entries:
|
thumbnails: A list of dictionaries, with the following entries:
|
||||||
* "id" (optional, string) - Thumbnail format ID
|
* "id" (optional, string) - Thumbnail format ID
|
||||||
* "url"
|
* "url"
|
||||||
|
* "ext" (optional, string) - actual image extension if not given in URL
|
||||||
* "preference" (optional, int) - quality of the image
|
* "preference" (optional, int) - quality of the image
|
||||||
* "width" (optional, int)
|
* "width" (optional, int)
|
||||||
* "height" (optional, int)
|
* "height" (optional, int)
|
||||||
|
|
|
@ -7,6 +7,7 @@ from ..utils import (
|
||||||
parse_resolution,
|
parse_resolution,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
traverse_obj,
|
traverse_obj,
|
||||||
|
update_url,
|
||||||
url_basename,
|
url_basename,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
urljoin,
|
urljoin,
|
||||||
|
@ -34,6 +35,7 @@ class ZoomIE(InfoExtractor):
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Prépa AF2023 - Séance 5 du 11 avril - R20/VM/GO',
|
'title': 'Prépa AF2023 - Séance 5 du 11 avril - R20/VM/GO',
|
||||||
},
|
},
|
||||||
|
'skip': 'This recording has expired',
|
||||||
}, {
|
}, {
|
||||||
# share URL
|
# share URL
|
||||||
'url': 'https://us02web.zoom.us/rec/share/hkUk5Zxcga0nkyNGhVCRfzkA2gX_mzgS3LpTxEEWJz9Y_QpIQ4mZFOUx7KZRZDQA.9LGQBdqmDAYgiZ_8',
|
'url': 'https://us02web.zoom.us/rec/share/hkUk5Zxcga0nkyNGhVCRfzkA2gX_mzgS3LpTxEEWJz9Y_QpIQ4mZFOUx7KZRZDQA.9LGQBdqmDAYgiZ_8',
|
||||||
|
@ -61,41 +63,59 @@ class ZoomIE(InfoExtractor):
|
||||||
return self._search_json(
|
return self._search_json(
|
||||||
r'window\.__data__\s*=', webpage, 'data', video_id, transform_source=js_to_json)
|
r'window\.__data__\s*=', webpage, 'data', video_id, transform_source=js_to_json)
|
||||||
|
|
||||||
def _get_real_webpage(self, url, base_url, video_id, url_type):
|
def _try_login(self, url, base_url, video_id, form):
|
||||||
webpage = self._download_webpage(url, video_id, note=f'Downloading {url_type} webpage')
|
# This will most likely only work for password-protected meetings
|
||||||
try:
|
|
||||||
form = self._form_hidden_inputs('password_form', webpage)
|
|
||||||
except ExtractorError:
|
|
||||||
return webpage
|
|
||||||
|
|
||||||
password = self.get_param('videopassword')
|
password = self.get_param('videopassword')
|
||||||
if not password:
|
if not password:
|
||||||
raise ExtractorError(
|
raise ExtractorError(
|
||||||
'This video is protected by a passcode, use the --video-password option', expected=True)
|
'This video is protected by a passcode, use the --video-password option', expected=True)
|
||||||
|
|
||||||
is_meeting = form.get('useWhichPasswd') == 'meeting'
|
is_meeting = form.get('useWhichPasswd') == 'meeting'
|
||||||
validation = self._download_json(
|
validation = self._download_json(
|
||||||
base_url + 'rec/validate%s_passwd' % ('_meet' if is_meeting else ''),
|
base_url + 'nws/recording/1.0/validate%s-passwd' % ('-meeting' if is_meeting else ''),
|
||||||
video_id, 'Validating passcode', 'Wrong passcode', data=urlencode_postdata({
|
video_id, 'Validating passcode', 'Wrong passcode', data=urlencode_postdata({
|
||||||
'id': form[('meet' if is_meeting else 'file') + 'Id'],
|
'id': form[('meeting' if is_meeting else 'file') + '_id'],
|
||||||
'passwd': password,
|
'passwd': password,
|
||||||
'action': form.get('action'),
|
'action': form.get('action'),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if not validation.get('status'):
|
if not validation.get('status'):
|
||||||
raise ExtractorError(validation['errorMessage'], expected=True)
|
raise ExtractorError(validation['errorMessage'], expected=True)
|
||||||
return self._download_webpage(url, video_id, note=f'Re-downloading {url_type} webpage')
|
|
||||||
|
def _get_real_webpage(self, url, base_url, video_id, url_type):
|
||||||
|
webpage = self._download_webpage(url, video_id, note=f'Downloading {url_type} webpage')
|
||||||
|
|
||||||
|
data = self._get_page_data(webpage, video_id)
|
||||||
|
if data.get('componentName') != 'need-password': # not password protected
|
||||||
|
return webpage
|
||||||
|
|
||||||
|
# Password-protected:
|
||||||
|
self._try_login(url, base_url, video_id, form=data)
|
||||||
|
# Return the new HTML document
|
||||||
|
new_url = f"{base_url}rec/share/{data['meeting_id']}"
|
||||||
|
return self._download_webpage(new_url, video_id, note=f'Re-downloading {url_type} webpage')
|
||||||
|
|
||||||
|
def _get_share_redirect_url(self, url, base_url, video_id):
|
||||||
|
"""Converts a `/rec/share` url to the corresponding `/rec/play` url, performs login if necessary"""
|
||||||
|
webpage = self._get_real_webpage(url, base_url, video_id, 'share')
|
||||||
|
meeting_id = self._get_page_data(webpage, video_id)['meetingId']
|
||||||
|
redirect_dict = self._download_json(
|
||||||
|
f'{base_url}nws/recording/1.0/play/share-info/{meeting_id}',
|
||||||
|
video_id, note='Downloading share info JSON')['result']
|
||||||
|
redirect_path = redirect_dict.pop('redirectUrl')
|
||||||
|
url = update_url(urljoin(base_url, redirect_path), query_update=redirect_dict)
|
||||||
|
|
||||||
|
if redirect_dict.get('componentName') == 'need-password':
|
||||||
|
# First login, then return redirection URL
|
||||||
|
return self._get_share_redirect_url(url, base_url, video_id)
|
||||||
|
|
||||||
|
return url
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
base_url, url_type, video_id = self._match_valid_url(url).group('base_url', 'type', 'id')
|
base_url, url_type, video_id = self._match_valid_url(url).group('base_url', 'type', 'id')
|
||||||
query = {}
|
|
||||||
|
|
||||||
if url_type == 'share':
|
if url_type == 'share':
|
||||||
webpage = self._get_real_webpage(url, base_url, video_id, 'share')
|
url = self._get_share_redirect_url(url, base_url, video_id)
|
||||||
meeting_id = self._get_page_data(webpage, video_id)['meetingId']
|
|
||||||
redirect_path = self._download_json(
|
|
||||||
f'{base_url}nws/recording/1.0/play/share-info/{meeting_id}',
|
|
||||||
video_id, note='Downloading share info JSON')['result']['redirectUrl']
|
|
||||||
url = urljoin(base_url, redirect_path)
|
|
||||||
query['continueMode'] = 'true'
|
|
||||||
|
|
||||||
webpage = self._get_real_webpage(url, base_url, video_id, 'play')
|
webpage = self._get_real_webpage(url, base_url, video_id, 'play')
|
||||||
file_id = self._get_page_data(webpage, video_id)['fileId']
|
file_id = self._get_page_data(webpage, video_id)['fileId']
|
||||||
|
@ -104,10 +124,12 @@ class ZoomIE(InfoExtractor):
|
||||||
raise ExtractorError('Unable to extract file ID')
|
raise ExtractorError('Unable to extract file ID')
|
||||||
|
|
||||||
data = self._download_json(
|
data = self._download_json(
|
||||||
f'{base_url}nws/recording/1.0/play/info/{file_id}', video_id, query=query,
|
f'{base_url}nws/recording/1.0/play/info/{file_id}', video_id, query={
|
||||||
|
'continueMode': 'true', # Makes this return value include interpreter audio information
|
||||||
|
},
|
||||||
note='Downloading play info JSON')['result']
|
note='Downloading play info JSON')['result']
|
||||||
|
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
|
# XXX: Would be more appropriate to parse chapters separate from subtitles
|
||||||
for _type in ('transcript', 'cc', 'chapter'):
|
for _type in ('transcript', 'cc', 'chapter'):
|
||||||
if data.get(f'{_type}Url'):
|
if data.get(f'{_type}Url'):
|
||||||
subtitles[_type] = [{
|
subtitles[_type] = [{
|
||||||
|
@ -117,6 +139,19 @@ class ZoomIE(InfoExtractor):
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
|
|
||||||
|
if data.get('interpreterAudioList'):
|
||||||
|
for audio in data.get('interpreterAudioList'):
|
||||||
|
formats.append({
|
||||||
|
'format_note': f'Intepreter: {audio["languageText"]}',
|
||||||
|
'url': audio['audioUrl'],
|
||||||
|
'format_id': f'interpreter-{ audio["icon"].lower()}',
|
||||||
|
'ext': 'm4a',
|
||||||
|
# There doesn't seem to be an explicit field for a standardized language code,
|
||||||
|
# sometimes the `language` field may be more accurate than `icon`
|
||||||
|
'language': audio['icon'].lower(),
|
||||||
|
'vcodec': 'none',
|
||||||
|
})
|
||||||
|
|
||||||
if data.get('viewMp4Url'):
|
if data.get('viewMp4Url'):
|
||||||
formats.append({
|
formats.append({
|
||||||
'format_note': 'Camera stream',
|
'format_note': 'Camera stream',
|
||||||
|
|
|
@ -216,7 +216,7 @@ def partial_application(func):
|
||||||
sig = inspect.signature(func)
|
sig = inspect.signature(func)
|
||||||
required_args = [
|
required_args = [
|
||||||
param.name for param in sig.parameters.values()
|
param.name for param in sig.parameters.values()
|
||||||
if param.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.VAR_POSITIONAL)
|
if param.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD)
|
||||||
if param.default is inspect.Parameter.empty
|
if param.default is inspect.Parameter.empty
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -4837,7 +4837,6 @@ def number_of_digits(number):
|
||||||
return len('%d' % number)
|
return len('%d' % number)
|
||||||
|
|
||||||
|
|
||||||
@partial_application
|
|
||||||
def join_nonempty(*values, delim='-', from_dict=None):
|
def join_nonempty(*values, delim='-', from_dict=None):
|
||||||
if from_dict is not None:
|
if from_dict is not None:
|
||||||
values = (traversal.traverse_obj(from_dict, variadic(v)) for v in values)
|
values = (traversal.traverse_obj(from_dict, variadic(v)) for v in values)
|
||||||
|
|
|
@ -332,14 +332,14 @@ class _RequiredError(ExtractorError):
|
||||||
|
|
||||||
|
|
||||||
@typing.overload
|
@typing.overload
|
||||||
def subs_list_to_dict(*, ext: str | None = None) -> collections.abc.Callable[[list[dict]], dict[str, list[dict]]]: ...
|
def subs_list_to_dict(*, lang: str | None = 'und', ext: str | None = None) -> collections.abc.Callable[[list[dict]], dict[str, list[dict]]]: ...
|
||||||
|
|
||||||
|
|
||||||
@typing.overload
|
@typing.overload
|
||||||
def subs_list_to_dict(subs: list[dict] | None, /, *, ext: str | None = None) -> dict[str, list[dict]]: ...
|
def subs_list_to_dict(subs: list[dict] | None, /, *, lang: str | None = 'und', ext: str | None = None) -> dict[str, list[dict]]: ...
|
||||||
|
|
||||||
|
|
||||||
def subs_list_to_dict(subs: list[dict] | None = None, /, *, ext=None):
|
def subs_list_to_dict(subs: list[dict] | None = None, /, *, lang='und', ext=None):
|
||||||
"""
|
"""
|
||||||
Convert subtitles from a traversal into a subtitle dict.
|
Convert subtitles from a traversal into a subtitle dict.
|
||||||
The path should have an `all` immediately before this function.
|
The path should have an `all` immediately before this function.
|
||||||
|
@ -352,7 +352,7 @@ def subs_list_to_dict(subs: list[dict] | None = None, /, *, ext=None):
|
||||||
`quality` The sort order for each subtitle
|
`quality` The sort order for each subtitle
|
||||||
"""
|
"""
|
||||||
if subs is None:
|
if subs is None:
|
||||||
return functools.partial(subs_list_to_dict, ext=ext)
|
return functools.partial(subs_list_to_dict, lang=lang, ext=ext)
|
||||||
|
|
||||||
result = collections.defaultdict(list)
|
result = collections.defaultdict(list)
|
||||||
|
|
||||||
|
@ -360,9 +360,15 @@ def subs_list_to_dict(subs: list[dict] | None = None, /, *, ext=None):
|
||||||
if not url_or_none(sub.get('url')) and not sub.get('data'):
|
if not url_or_none(sub.get('url')) and not sub.get('data'):
|
||||||
continue
|
continue
|
||||||
sub_id = sub.pop('id', None)
|
sub_id = sub.pop('id', None)
|
||||||
if sub_id is None:
|
if not isinstance(sub_id, str):
|
||||||
|
if not lang:
|
||||||
continue
|
continue
|
||||||
if ext is not None and not sub.get('ext'):
|
sub_id = lang
|
||||||
|
sub_ext = sub.get('ext')
|
||||||
|
if not isinstance(sub_ext, str):
|
||||||
|
if not ext:
|
||||||
|
sub.pop('ext', None)
|
||||||
|
else:
|
||||||
sub['ext'] = ext
|
sub['ext'] = ext
|
||||||
result[sub_id].append(sub)
|
result[sub_id].append(sub)
|
||||||
result = dict(result)
|
result = dict(result)
|
||||||
|
@ -452,9 +458,9 @@ def trim_str(*, start=None, end=None):
|
||||||
return trim
|
return trim
|
||||||
|
|
||||||
|
|
||||||
def unpack(func):
|
def unpack(func, **kwargs):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def inner(items, **kwargs):
|
def inner(items):
|
||||||
return func(*items, **kwargs)
|
return func(*items, **kwargs)
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
|
Loading…
Reference in New Issue
Block a user