mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-08-04 00:58:35 +02:00
[utils] traverse_obj
: Allow filtering by value
This commit is contained in:
parent
c4f60dd7cd
commit
e6f868a63c
3 changed files with 6 additions and 6 deletions
|
@ -5152,8 +5152,8 @@ def traverse_obj(
|
|||
@param path_list A list of paths which are checked one by one.
|
||||
Each path is a list of keys where each key is a string,
|
||||
a function, a tuple of strings/None or "...".
|
||||
When a fuction is given, it takes the key as argument and
|
||||
returns whether the key matches or not. When a tuple is given,
|
||||
When a fuction is given, it takes the key and value as arguments
|
||||
and returns whether the key matches or not. When a tuple is given,
|
||||
all the keys given in the tuple are traversed, and
|
||||
"..." traverses all the keys in the object
|
||||
"None" returns the object without traversal
|
||||
|
@ -5198,7 +5198,7 @@ def traverse_obj(
|
|||
obj = str(obj)
|
||||
_current_depth += 1
|
||||
depth = max(depth, _current_depth)
|
||||
return [_traverse_obj(v, path[i + 1:], _current_depth) for k, v in obj if key(k)]
|
||||
return [_traverse_obj(v, path[i + 1:], _current_depth) for k, v in obj if try_call(key, args=(k, v))]
|
||||
elif isinstance(obj, dict) and not (is_user_input and key == ':'):
|
||||
obj = (obj.get(key) if casesense or (key in obj)
|
||||
else next((v for k, v in obj.items() if _lower(k) == key), None))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue