]> jfr.im git - yt-dlp.git/commitdiff
[embedsubtitle] Keep original subtitle after conversion if write_subtitles given
authorpukkandan <redacted>
Tue, 9 Feb 2021 18:37:10 +0000 (00:07 +0530)
committerpukkandan <redacted>
Tue, 9 Feb 2021 18:42:42 +0000 (00:12 +0530)
Closes: https://github.com/pukkandan/yt-dlp/issues/57#issuecomment-775227745
:ci skip dl

youtube_dlc/__init__.py
youtube_dlc/postprocessor/ffmpeg.py

index d28510467a452d2f588e7af6c92b8f608dfcd5aa..eeb7b6f7457bf8b8369a7e29314d7e8ddbb13881 100644 (file)
@@ -233,11 +233,6 @@ def parse_retries(retries):
     if opts.extractaudio and not opts.keepvideo and opts.format is None:
         opts.format = 'bestaudio/best'
 
-    # --all-sub automatically sets --write-sub if --write-auto-sub is not given
-    # this was the old behaviour if only --all-sub was given.
-    if opts.allsubtitles and not opts.writeautomaticsub:
-        opts.writesubtitles = True
-
     outtmpl = opts.outtmpl
     if not outtmpl:
         outtmpl = {'default': (
@@ -311,9 +306,17 @@ def parse_retries(retries):
             'format': opts.convertsubtitles,
         })
     if opts.embedsubtitles:
+        already_have_subtitle = opts.writesubtitles
         postprocessors.append({
             'key': 'FFmpegEmbedSubtitle',
+            'already_have_subtitle': already_have_subtitle
         })
+        if not already_have_subtitle:
+            opts.writesubtitles = True
+    # --all-sub automatically sets --write-sub if --write-auto-sub is not given
+    # this was the old behaviour if only --all-sub was given.
+    if opts.allsubtitles and not opts.writeautomaticsub:
+        opts.writesubtitles = True
     if opts.embedthumbnail:
         already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails
         postprocessors.append({
index 948c34287280bc1588d5a2e99dd92eafbe9db4dd..cabe7266e2ba508af7489a62b8b2967cd3381bf4 100644 (file)
@@ -442,6 +442,10 @@ def run(self, information):
 
 
 class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
+    def __init__(self, downloader=None, already_have_subtitle=False):
+        super(FFmpegEmbedSubtitlePP, self).__init__(downloader)
+        self._already_have_subtitle = already_have_subtitle
+
     def run(self, information):
         if information['ext'] not in ('mp4', 'webm', 'mkv'):
             self.to_screen('Subtitles can only be embedded in mp4, webm or mkv files')
@@ -501,7 +505,8 @@ def run(self, information):
         os.remove(encodeFilename(filename))
         os.rename(encodeFilename(temp_filename), encodeFilename(filename))
 
-        return sub_filenames, information
+        files_to_delete = [] if self._already_have_subtitle else sub_filenames
+        return files_to_delete, information
 
 
 class FFmpegMetadataPP(FFmpegPostProcessor):