]> jfr.im git - yt-dlp.git/commitdiff
[postprocessor] Fix chapters if duration is not extracted (#6037)
authorbashonly <redacted>
Wed, 8 Mar 2023 13:10:19 +0000 (07:10 -0600)
committerGitHub <redacted>
Wed, 8 Mar 2023 13:10:19 +0000 (13:10 +0000)
Authored by: bashonly

yt_dlp/postprocessor/ffmpeg.py
yt_dlp/postprocessor/modify_chapters.py

index 123a95a3a9e2d0b88df21ff12fd2337c4c61c10a..0e8f4c70b118dbb70d74f9fe792486d0dafe4a27 100644 (file)
@@ -302,6 +302,11 @@ def get_stream_number(self, path, keys, value):
             None)
         return num, len(streams)
 
+    def _fixup_chapters(self, info):
+        last_chapter = traverse_obj(info, ('chapters', -1))
+        if last_chapter and not last_chapter.get('end_time'):
+            last_chapter['end_time'] = self._get_real_video_duration(info['filepath'])
+
     def _get_real_video_duration(self, filepath, fatal=True):
         try:
             duration = float_or_none(
@@ -678,6 +683,7 @@ def _options(target_ext):
 
     @PostProcessor._restrict_to(images=False)
     def run(self, info):
+        self._fixup_chapters(info)
         filename, metadata_filename = info['filepath'], None
         files_to_delete, options = [], []
         if self._add_chapters and info.get('chapters'):
@@ -1040,6 +1046,7 @@ def _ffmpeg_args_for_chapter(self, number, chapter, info):
 
     @PostProcessor._restrict_to(images=False)
     def run(self, info):
+        self._fixup_chapters(info)
         chapters = info.get('chapters') or []
         if not chapters:
             self.to_screen('Chapter information is unavailable')
index a745b4524cdedfb0e8c94dc5fd71bab86fc99228..f5219868c842f7b8aa2fa3023e47a346df45928a 100644 (file)
@@ -23,6 +23,7 @@ def __init__(self, downloader, remove_chapters_patterns=None, remove_sponsor_seg
 
     @PostProcessor._restrict_to(images=False)
     def run(self, info):
+        self._fixup_chapters(info)
         # Chapters must be preserved intact when downloading multiple formats of the same video.
         chapters, sponsor_chapters = self._mark_chapters_to_remove(
             copy.deepcopy(info.get('chapters')) or [],