diff options
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r-- | yt_dlp/utils.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 878b2b6a8..7cf151e3a 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -5420,7 +5420,7 @@ def traverse_obj( Each of the provided `paths` is tested and the first producing a valid result will be returned. The next path will also be tested if the path branched but no results could be found. Supported values for traversal are `Mapping`, `Sequence` and `re.Match`. - Unhelpful values (`[]`, `{}`, `None`) are treated as the absence of a value and discarded. + Unhelpful values (`{}`, `None`) are treated as the absence of a value and discarded. The paths will be wrapped in `variadic`, so that `'key'` is conveniently the same as `('key', )`. @@ -5484,7 +5484,7 @@ def traverse_obj( branching = False result = None - if obj is None: + if obj is None and traverse_string: pass elif key is None: @@ -5558,14 +5558,13 @@ def traverse_obj( result = next((v for k, v in obj.groupdict().items() if casefold(k) == key), None) elif isinstance(key, (int, slice)): - if not is_sequence(obj): - if traverse_string: - with contextlib.suppress(IndexError): - result = str(obj)[key] - else: + if is_sequence(obj): branching = isinstance(key, slice) with contextlib.suppress(IndexError): result = obj[key] + elif traverse_string: + with contextlib.suppress(IndexError): + result = str(obj)[key] return branching, result if branching else (result,) @@ -5617,7 +5616,7 @@ def traverse_obj( def _traverse_obj(obj, path, allow_empty, test_type): results, has_branched, is_dict = apply_path(obj, path, test_type) - results = LazyList(item for item in results if item not in (None, [], {})) + results = LazyList(item for item in results if item not in (None, {})) if get_all and has_branched: if results: return results.exhaust() |