mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-30 04:10:23 +00:00
[utils] Fix traverse_obj
depth when is_user_input
This commit is contained in:
parent
57015a4a3f
commit
575e17a1b9
@ -6263,6 +6263,8 @@ def traverse_obj(
|
|||||||
|
|
||||||
def _traverse_obj(obj, path, _current_depth=0):
|
def _traverse_obj(obj, path, _current_depth=0):
|
||||||
nonlocal depth
|
nonlocal depth
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
path = tuple(variadic(path))
|
path = tuple(variadic(path))
|
||||||
for i, key in enumerate(path):
|
for i, key in enumerate(path):
|
||||||
if isinstance(key, (list, tuple)):
|
if isinstance(key, (list, tuple)):
|
||||||
@ -6275,7 +6277,7 @@ def _traverse_obj(obj, path, _current_depth=0):
|
|||||||
_current_depth += 1
|
_current_depth += 1
|
||||||
depth = max(depth, _current_depth)
|
depth = max(depth, _current_depth)
|
||||||
return [_traverse_obj(inner_obj, path[i + 1:], _current_depth) for inner_obj in obj]
|
return [_traverse_obj(inner_obj, path[i + 1:], _current_depth) for inner_obj in obj]
|
||||||
elif isinstance(obj, dict):
|
elif isinstance(obj, dict) and not (is_user_input and key == ':'):
|
||||||
obj = (obj.get(key) if casesense or (key in obj)
|
obj = (obj.get(key) if casesense or (key in obj)
|
||||||
else next((v for k, v in obj.items() if _lower(k) == key), None))
|
else next((v for k, v in obj.items() if _lower(k) == key), None))
|
||||||
else:
|
else:
|
||||||
@ -6283,7 +6285,7 @@ def _traverse_obj(obj, path, _current_depth=0):
|
|||||||
key = (int_or_none(key) if ':' not in key
|
key = (int_or_none(key) if ':' not in key
|
||||||
else slice(*map(int_or_none, key.split(':'))))
|
else slice(*map(int_or_none, key.split(':'))))
|
||||||
if key == slice(None):
|
if key == slice(None):
|
||||||
return _traverse_obj(obj, (..., *path[i + 1:]))
|
return _traverse_obj(obj, (..., *path[i + 1:]), _current_depth)
|
||||||
if not isinstance(key, (int, slice)):
|
if not isinstance(key, (int, slice)):
|
||||||
return None
|
return None
|
||||||
if not isinstance(obj, (list, tuple, LazyList)):
|
if not isinstance(obj, (list, tuple, LazyList)):
|
||||||
|
Loading…
Reference in New Issue
Block a user