mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-08-30 07:41:42 +03:00
[utils] subs_list_to_dict: Fix empty value handling (#17311)
Authored by: doe1080
This commit is contained in:
@@ -546,6 +546,18 @@ class TestTraversalHelpers:
|
||||
{'url': 'https://example.com/subs/de4'},
|
||||
],
|
||||
}, 'non str types should be replaced by default id'
|
||||
assert traverse_obj([
|
||||
{'name': '', 'ext': '', 'url': 'https://example.com/subs/en'},
|
||||
], [..., {
|
||||
'id': 'name',
|
||||
'ext': 'ext',
|
||||
'url': 'url',
|
||||
}, all, {subs_list_to_dict(lang='en', ext='vtt')}]) == {
|
||||
'en': [{
|
||||
'ext': 'vtt',
|
||||
'url': 'https://example.com/subs/en',
|
||||
}],
|
||||
}, 'empty id and ext should be replaced by defaults'
|
||||
|
||||
def test_trim_str(self):
|
||||
with pytest.raises(TypeError):
|
||||
|
||||
@@ -360,12 +360,12 @@ def subs_list_to_dict(subs: list[dict] | None = None, /, *, lang='und', ext=None
|
||||
if not url_or_none(sub.get('url')) and not sub.get('data'):
|
||||
continue
|
||||
sub_id = sub.pop('id', None)
|
||||
if not isinstance(sub_id, str):
|
||||
if not isinstance(sub_id, str) or not sub_id:
|
||||
if not lang:
|
||||
continue
|
||||
sub_id = lang
|
||||
sub_ext = sub.get('ext')
|
||||
if not isinstance(sub_ext, str):
|
||||
if not isinstance(sub_ext, str) or not sub_ext:
|
||||
if not ext:
|
||||
sub.pop('ext', None)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user