Refactor subtitle options from srt to the more generic 'sub'.
[youtube-dl] / youtube_dl / FileDownloader.py
index e496b8a8de6b6a89fe4fac6f80145b8fb6f7a93a..4549dd46486ba205ba9bf853987ac4fde9ab437a 100644 (file)
@@ -78,7 +78,7 @@ class FileDownloader(object):
     updatetime:        Use the Last-modified header to set output file timestamps.
     writedescription:  Write the video description to a .description file
     writeinfojson:     Write the video description to a .info.json file
-    writesubtitles:    Write the video subtitles to a .srt file
+    writesubtitles:    Write the video subtitles to a file (default=srt)
     onlysubtitles:     Downloads only the subtitles of the video
     allsubtitles:      Downloads all the subtitles of the video
     subtitleslang:     Language of the subtitles to download
@@ -291,9 +291,9 @@ class FileDownloader(object):
         """ Report that the description file is being written """
         self.to_screen(u'[info] Writing video description to: ' + descfn)
 
-    def report_writesubtitles(self, srtfn):
+    def report_writesubtitles(self, sub_filename):
         """ Report that the subtitles file is being written """
-        self.to_screen(u'[info] Writing video subtitles to: ' + srtfn)
+        self.to_screen(u'[info] Writing video subtitles to: ' + sub_filename)
 
     def report_writeinfojson(self, infofn):
         """ Report that the metadata file has been written """
@@ -444,12 +444,12 @@ class FileDownloader(object):
             # subtitles download errors are already managed as troubles in relevant IE
             # that way it will silently go on when used with unsupporting IE
             subtitle = info_dict['subtitles'][0]
-            (srt_error, srt_lang, srt) = subtitle
+            (sub_error, sub_lang, sub) = subtitle
             try:
-                srtfn = filename.rsplit('.', 1)[0] + u'.' + srt_lang + u'.srt'
-                self.report_writesubtitles(srtfn)
-                with io.open(encodeFilename(srtfn), 'w', encoding='utf-8') as srtfile:
-                    srtfile.write(srt)
+                sub_filename = filename.rsplit('.', 1)[0] + u'.' + sub_lang + u'.srt'
+                self.report_writesubtitles(sub_filename)
+                with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile:
+                    subfile.write(sub)
             except (OSError, IOError):
                 self.trouble(u'ERROR: Cannot write subtitles file ' + descfn)
                 return
@@ -459,12 +459,12 @@ class FileDownloader(object):
         if self.params.get('allsubtitles', False) and 'subtitles' in info_dict and info_dict['subtitles']:
             subtitles = info_dict['subtitles']
             for subtitle in subtitles:
-                (srt_error, srt_lang, srt) = subtitle
+                (sub_error, sub_lang, sub) = subtitle
                 try:
-                    srtfn = filename.rsplit('.', 1)[0] + u'.' + srt_lang + u'.srt'
-                    self.report_writesubtitles(srtfn)
-                    with io.open(encodeFilename(srtfn), 'w', encoding='utf-8') as srtfile:
-                            srtfile.write(srt)
+                    sub_filename = filename.rsplit('.', 1)[0] + u'.' + sub_lang + u'.srt'
+                    self.report_writesubtitles(sub_filename)
+                    with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile:
+                            subfile.write(sub)
                 except (OSError, IOError):
                     self.trouble(u'ERROR: Cannot write subtitles file ' + descfn)
                     return