aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/utils.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-03-31 13:25:50 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-03-31 13:33:28 +0530
commite6f868a63c15f576152733a1508f474b5e5bd1ef (patch)
treec3ec5c413f3a137ade860345e076197eaaf93834 /yt_dlp/utils.py
parentc4f60dd7cdbf5282a8d1a8fa8dd4f6fd60acc034 (diff)
downloadhypervideo-pre-e6f868a63c15f576152733a1508f474b5e5bd1ef.tar.lz
hypervideo-pre-e6f868a63c15f576152733a1508f474b5e5bd1ef.tar.xz
hypervideo-pre-e6f868a63c15f576152733a1508f474b5e5bd1ef.zip
[utils] `traverse_obj`: Allow filtering by value
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r--yt_dlp/utils.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index 22062f85f..a2fa29afe 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -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))