]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/YoutubeDL.py
Improve `--download-sections`
[yt-dlp.git] / yt_dlp / YoutubeDL.py
index 79b7d47b037525e1a1bf01b3e7434d8cade0c4af..6dade0b2a412e384ec868d2516f687fa94c74f28 100644 (file)
@@ -2806,11 +2806,13 @@ def to_screen(*msg):
                 new_info.update(fmt)
                 offset, duration = info_dict.get('section_start') or 0, info_dict.get('duration') or float('inf')
                 end_time = offset + min(chapter.get('end_time', duration), duration)
+                # duration may not be accurate. So allow deviations <1sec
+                if end_time == float('inf') or end_time > offset + duration + 1:
+                    end_time = None
                 if chapter or offset:
                     new_info.update({
                         'section_start': offset + chapter.get('start_time', 0),
-                        # duration may not be accurate. So allow deviations <1sec
-                        'section_end': end_time if end_time <= offset + duration + 1 else None,
+                        'section_end': end_time,
                         'section_title': chapter.get('title'),
                         'section_number': chapter.get('index'),
                     })