]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/utils.py
Add option `--download-sections` to download video partially
[yt-dlp.git] / yt_dlp / utils.py
index 777b8b3ead3888e812ef9861f2754e6312fdd5f0..45af4ec6179e419d17bd9f1e997e5a7f71498e73 100644 (file)
@@ -3495,6 +3495,23 @@ def _match_func(info_dict, incomplete=False):
     return _match_func
 
 
+def download_range_func(chapters, ranges):
+    def inner(info_dict, ydl):
+        warning = ('There are no chapters matching the regex' if info_dict.get('chapters')
+                   else 'Chapter information is unavailable')
+        for regex in chapters or []:
+            for i, chapter in enumerate(info_dict.get('chapters') or []):
+                if re.search(regex, chapter['title']):
+                    warning = None
+                    yield {**chapter, 'index': i}
+        if warning:
+            ydl.to_screen(f'[info] {info_dict["id"]}: {warning}')
+
+        yield from ({'start_time': start, 'end_time': end} for start, end in ranges or [])
+
+    return inner
+
+
 def parse_dfxp_time_expr(time_expr):
     if not time_expr:
         return