[FFmpegSubtitlesConvertorPP] delete old subtitle files (fixes #8382)

This commit is contained in:
Jaime Marquínez Ferrándiz 2016-01-31 14:22:36 +01:00
parent 231ea2a3bb
commit e04398e397

View File

@ -479,6 +479,7 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
self._downloader.to_screen('[ffmpeg] There aren\'t any subtitles to convert') self._downloader.to_screen('[ffmpeg] There aren\'t any subtitles to convert')
return [], info return [], info
self._downloader.to_screen('[ffmpeg] Converting subtitles') self._downloader.to_screen('[ffmpeg] Converting subtitles')
sub_filenames = []
for lang, sub in subs.items(): for lang, sub in subs.items():
ext = sub['ext'] ext = sub['ext']
if ext == new_ext: if ext == new_ext:
@ -486,6 +487,8 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
'[ffmpeg] Subtitle file for %s is already in the requested' '[ffmpeg] Subtitle file for %s is already in the requested'
'format' % new_ext) 'format' % new_ext)
continue continue
old_file = subtitles_filename(filename, lang, ext)
sub_filenames.append(old_file)
new_file = subtitles_filename(filename, lang, new_ext) new_file = subtitles_filename(filename, lang, new_ext)
if ext == 'dfxp' or ext == 'ttml': if ext == 'dfxp' or ext == 'ttml':
@ -493,7 +496,7 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
'You have requested to convert dfxp (TTML) subtitles into another format, ' 'You have requested to convert dfxp (TTML) subtitles into another format, '
'which results in style information loss') 'which results in style information loss')
dfxp_file = subtitles_filename(filename, lang, ext) dfxp_file = old_file
srt_file = subtitles_filename(filename, lang, 'srt') srt_file = subtitles_filename(filename, lang, 'srt')
with io.open(dfxp_file, 'rt', encoding='utf-8') as f: with io.open(dfxp_file, 'rt', encoding='utf-8') as f:
@ -511,9 +514,7 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
if new_ext == 'srt': if new_ext == 'srt':
continue continue
self.run_ffmpeg( self.run_ffmpeg(old_file, new_file, ['-f', new_format])
subtitles_filename(filename, lang, ext),
new_file, ['-f', new_format])
with io.open(new_file, 'rt', encoding='utf-8') as f: with io.open(new_file, 'rt', encoding='utf-8') as f:
subs[lang] = { subs[lang] = {
@ -521,4 +522,4 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
'data': f.read(), 'data': f.read(),
} }
return [], info return sub_filenames, info