Detect already merged videos

Without the '--keep-video' option the two files would be downloaded again and even using the option, ffmpeg would be run again, which for some videos can take a long time.
We use a temporary file with ffmpeg so that the final file only exists if it success
This commit is contained in:
Jaime Marquínez Ferrándiz 2015-04-19 16:56:22 +02:00
parent f158799bbe
commit 5b5fbc0867
2 changed files with 18 additions and 11 deletions

View file

@ -1369,6 +1369,11 @@ def dl(name, info):
' The formats won\'t be merged') ' The formats won\'t be merged')
else: else:
postprocessors = [merger] postprocessors = [merger]
if os.path.exists(encodeFilename(filename)):
self.to_screen(
'[download] %s has already been downloaded and '
'merged' % filename)
else:
for f in info_dict['requested_formats']: for f in info_dict['requested_formats']:
new_info = dict(info_dict) new_info = dict(info_dict)
new_info.update(f) new_info.update(f)

View file

@ -580,9 +580,11 @@ def run(self, info):
class FFmpegMergerPP(FFmpegPostProcessor): class FFmpegMergerPP(FFmpegPostProcessor):
def run(self, info): def run(self, info):
filename = info['filepath'] filename = info['filepath']
temp_filename = prepend_extension(filename, 'temp')
args = ['-c', 'copy', '-map', '0:v:0', '-map', '1:a:0'] args = ['-c', 'copy', '-map', '0:v:0', '-map', '1:a:0']
self._downloader.to_screen('[ffmpeg] Merging formats into "%s"' % filename) self._downloader.to_screen('[ffmpeg] Merging formats into "%s"' % filename)
self.run_ffmpeg_multiple_files(info['__files_to_merge'], filename, args) self.run_ffmpeg_multiple_files(info['__files_to_merge'], temp_filename, args)
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
return info['__files_to_merge'], info return info['__files_to_merge'], info