mirror of
				https://code.hackerspace.pl/q3k/youtube-dl
				synced 2025-03-16 11:43:02 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									f158799bbe
								
							
						
					
					
						commit
						5b5fbc0867
					
				| @ -1369,16 +1369,21 @@ class YoutubeDL(object): | |||||||
|                                             ' The formats won\'t be merged') |                                             ' The formats won\'t be merged') | ||||||
|                     else: |                     else: | ||||||
|                         postprocessors = [merger] |                         postprocessors = [merger] | ||||||
|                     for f in info_dict['requested_formats']: |                     if os.path.exists(encodeFilename(filename)): | ||||||
|                         new_info = dict(info_dict) |                         self.to_screen( | ||||||
|                         new_info.update(f) |                             '[download] %s has already been downloaded and ' | ||||||
|                         fname = self.prepare_filename(new_info) |                             'merged' % filename) | ||||||
|                         fname = prepend_extension(fname, 'f%s' % f['format_id']) |                     else: | ||||||
|                         downloaded.append(fname) |                         for f in info_dict['requested_formats']: | ||||||
|                         partial_success = dl(fname, new_info) |                             new_info = dict(info_dict) | ||||||
|                         success = success and partial_success |                             new_info.update(f) | ||||||
|                     info_dict['__postprocessors'] = postprocessors |                             fname = self.prepare_filename(new_info) | ||||||
|                     info_dict['__files_to_merge'] = downloaded |                             fname = prepend_extension(fname, 'f%s' % f['format_id']) | ||||||
|  |                             downloaded.append(fname) | ||||||
|  |                             partial_success = dl(fname, new_info) | ||||||
|  |                             success = success and partial_success | ||||||
|  |                         info_dict['__postprocessors'] = postprocessors | ||||||
|  |                         info_dict['__files_to_merge'] = downloaded | ||||||
|                 else: |                 else: | ||||||
|                     # Just a single file |                     # Just a single file | ||||||
|                     success = dl(filename, info_dict) |                     success = dl(filename, info_dict) | ||||||
|  | |||||||
| @ -580,9 +580,11 @@ class FFmpegMetadataPP(FFmpegPostProcessor): | |||||||
| 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 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jaime Marquínez Ferrándiz
						Jaime Marquínez Ferrándiz