aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2025-10-31 13:36:55 +0000
committerdirkf <fieldhouse@gmx.net>2025-11-21 01:52:11 +0000
commit68fe8c1781f6bbfef3aa75cf7746f6508d7ef75c (patch)
treed8e6508922754ba9aff981009384487881daa0d5 /youtube_dl/utils.py
parent96419fa7064c7f77ccb1909e23150fde603f9f36 (diff)
[utils] Support traversal helper functions `require`, `value`, `unpack`
Thx: yt-dlp/yt-dlp#10653
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 29d62130a..437257f5b 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -6543,6 +6543,31 @@ def traverse_obj(obj, *paths, **kwargs):
return None if default is NO_DEFAULT else default
+def value(value):
+ return lambda _: value
+
+
+class require(ExtractorError):
+ def __init__(self, name, expected=False):
+ super(require, self).__init__(
+ 'Unable to extract {0}'.format(name), expected=expected)
+
+ def __call__(self, value):
+ if value is None:
+ raise self
+
+ return value
+
+
+def unpack(func, **kwargs):
+ """Make a function that applies `partial(func, **kwargs)` to its argument as *args"""
+ @functools.wraps(func)
+ def inner(items):
+ return func(*items, **kwargs)
+
+ return inner
+
+
def T(*x):
""" For use in yt-dl instead of {type, ...} or set((type, ...)) """
return set(x)