From c5a0627b965f264432170c565c8ba28a720fe250 Mon Sep 17 00:00:00 2001 From: Zil0 <30212477+Zil0@users.noreply.github.com> Date: Sun, 23 Jul 2017 14:25:35 +0200 Subject: [PATCH 1/2] [YoutubeDL] Add filenames key in info_dict --- youtube_dl/YoutubeDL.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 89c07be29..493491a1a 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1578,10 +1578,13 @@ class YoutubeDL(object): if download: if len(formats_to_download) > 1: self.to_screen('[info] %s: downloading video in %s formats' % (info_dict['id'], len(formats_to_download))) + filenames = [] for format in formats_to_download: new_info = dict(info_dict) new_info.update(format) self.process_info(new_info) + filenames.append(new_info.get('_filename')) + info_dict['filenames'] = filenames # We update the info dict with the best quality format (backwards compatibility) info_dict.update(formats_to_download[-1]) return info_dict @@ -1827,7 +1830,7 @@ class YoutubeDL(object): self.report_warning( 'Requested formats are incompatible for merge and will be merged into mkv.') # Ensure filename always has a correct extension for successful merge - filename = '%s.%s' % (filename_wo_ext, info_dict['ext']) + info_dict['_filename'] = filename = '%s.%s' % (filename_wo_ext, info_dict['ext']) if os.path.exists(encodeFilename(filename)): self.to_screen( '[download] %s has already been downloaded and ' @@ -1985,6 +1988,7 @@ class YoutubeDL(object): files_to_delete = [] try: files_to_delete, info = pp.run(info) + ie_info['_filename'] = info['filepath'] except PostProcessingError as e: self.report_error(e.msg) if files_to_delete and not self.params.get('keepvideo', False): From 0948f25c261d0f8b45e25340b7373083cb447344 Mon Sep 17 00:00:00 2001 From: Zil0 <30212477+Zil0@users.noreply.github.com> Date: Sun, 23 Jul 2017 22:52:49 +0200 Subject: [PATCH 2/2] Save transitional filenames if keepvideo is set --- youtube_dl/YoutubeDL.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 493491a1a..225ef741b 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1984,20 +1984,26 @@ class YoutubeDL(object): if ie_info.get('__postprocessors') is not None: pps_chain.extend(ie_info['__postprocessors']) pps_chain.extend(self._pps) + filepaths = [] for pp in pps_chain: files_to_delete = [] try: files_to_delete, info = pp.run(info) - ie_info['_filename'] = info['filepath'] except PostProcessingError as e: self.report_error(e.msg) - if files_to_delete and not self.params.get('keepvideo', False): - for old_filename in files_to_delete: - self.to_screen('Deleting original file %s (pass -k to keep)' % old_filename) - try: - os.remove(encodeFilename(old_filename)) - except (IOError, OSError): - self.report_warning('Unable to remove downloaded original file') + if files_to_delete: + if self.params.get('keepvideo'): + filepaths.extend(files_to_delete) + else: + for old_filename in files_to_delete: + self.to_screen('Deleting original file %s (pass -k to keep)' % old_filename) + try: + os.remove(encodeFilename(old_filename)) + except (IOError, OSError): + self.report_warning('Unable to remove downloaded original file') + if info.get('filepath'): + filepaths.append(info['filepath']) + ie_info['_filename'] = filepaths or filename def _make_archive_id(self, info_dict): # Future-proof against any change in case