[utils] subs_list_to_dict: Fix empty value handling (#17311)

Authored by: doe1080
This commit is contained in:
doe1080
2026-08-29 23:55:22 +02:00
committed by GitHub
parent 8377aa9555
commit fcdbefb85f
2 changed files with 14 additions and 2 deletions
+12
View File
@@ -546,6 +546,18 @@ class TestTraversalHelpers:
{'url': 'https://example.com/subs/de4'}, {'url': 'https://example.com/subs/de4'},
], ],
}, 'non str types should be replaced by default id' }, '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): def test_trim_str(self):
with pytest.raises(TypeError): with pytest.raises(TypeError):
+2 -2
View File
@@ -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'): 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 not isinstance(sub_id, str): if not isinstance(sub_id, str) or not sub_id:
if not lang: if not lang:
continue continue
sub_id = lang sub_id = lang
sub_ext = sub.get('ext') sub_ext = sub.get('ext')
if not isinstance(sub_ext, str): if not isinstance(sub_ext, str) or not sub_ext:
if not ext: if not ext:
sub.pop('ext', None) sub.pop('ext', None)
else: else: