From 9c3b227db8f4889e496ff4ac65da426dcfc79e02 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Wed, 24 Apr 2024 11:02:26 -0700 Subject: [PATCH] Removed files_to_move logic --- yt_dlp/YoutubeDL.py | 33 ++++++++++----------------------- yt_dlp/postprocessor/ffmpeg.py | 15 --------------- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index f6921297d1..06e9109e1a 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -1808,7 +1808,7 @@ def process_ie_result(self, ie_result, download=True, extra_info=None): info_copy['id'] = ie.get_temp_id(ie_result['url']) self.add_default_extra_info(info_copy, ie, ie_result['url']) self.add_extra_info(info_copy, extra_info) - info_copy, _ = self.pre_process(info_copy) + info_copy = self.pre_process(info_copy) self._fill_common_fields(info_copy, False) self.__forced_printings(info_copy) self._raise_pending_errors(info_copy) @@ -2885,13 +2885,13 @@ def is_wellformed(f): # which can't be exported to json info_dict['formats'] = formats - info_dict, _ = self.pre_process(info_dict) + info_dict = self.pre_process(info_dict) if self._match_entry(info_dict, incomplete=self._format_fields) is not None: return info_dict self.post_extract(info_dict) - info_dict, _ = self.pre_process(info_dict, 'after_filter') + info_dict = self.pre_process(info_dict, 'after_filter') # The pre-processors may have modified the formats formats = self._get_formats(info_dict) @@ -3202,14 +3202,13 @@ def replace_info_dict(new_info): info_dict.clear() info_dict.update(new_info) - new_info, _ = self.pre_process(info_dict, 'video') + new_info = self.pre_process(info_dict, 'video') replace_info_dict(new_info) self._num_downloads += 1 # info_dict['_filename'] needs to be set for backward compatibility info_dict['_filename'] = full_filename = self.prepare_filename(info_dict, warn=True) temp_filename = self.prepare_filename(info_dict, 'temp') - files_to_move = {} # Forced printings self.__forced_printings(info_dict, full_filename, incomplete=('format' not in info_dict)) @@ -3238,15 +3237,11 @@ def check_max_downloads(): if sub_files is None: return - files_to_move['requested_subtitles'] = sub_files - thumb_files = self._write_thumbnails( 'video', info_dict, temp_filename, self.prepare_filename(info_dict, 'thumbnail')) if thumb_files is None: return - files_to_move['thumbnails'] = thumb_files - infofn = self.prepare_filename(info_dict, 'infojson') _infojson_written = self._write_info_json('video', info_dict, infofn) if _infojson_written: @@ -3319,13 +3314,12 @@ def _write_link_file(link_type): for link_type, should_write in write_links.items()): return - new_info, files_to_move = self.pre_process(info_dict, 'before_dl', files_to_move) + new_info = self.pre_process(info_dict, 'before_dl') replace_info_dict(new_info) if self.params.get('skip_download'): info_dict['filepath'] = temp_filename info_dict['__finaldir'] = os.path.dirname(os.path.abspath(encodeFilename(full_filename))) - info_dict['__files_to_move'] = files_to_move replace_info_dict(self.run_pp(MoveFilesAfterDownloadPP(self, False), info_dict)) info_dict['__write_download_archive'] = self.params.get('force_write_download_archive') else: @@ -3439,9 +3433,6 @@ def correct_ext(filename, ext=new_ext): info_dict['__files_to_merge'] = downloaded # Even if there were no downloads, it is being merged only now info_dict['__real_download'] = True - else: - for file in downloaded: - files_to_move[file] = None else: # Just a single file dl_filename = existing_video_file(full_filename, temp_filename) @@ -3525,7 +3516,7 @@ def ffmpeg_fixup(cndn, msg, cls): fixup() try: - replace_info_dict(self.post_process(dl_filename, info_dict, files_to_move)) + replace_info_dict(self.post_process(dl_filename, info_dict)) except PostProcessingError as err: self.report_error('Postprocessing: %s' % str(err)) return @@ -3662,8 +3653,7 @@ def actual_post_extract(info_dict): def run_pp(self, pp, infodict): files_to_delete = [] - if '__files_to_move' not in infodict: - infodict['__files_to_move'] = {} + try: files_to_delete, infodict = pp.run(infodict) except PostProcessingError as e: @@ -3687,24 +3677,21 @@ def run_all_pps(self, key, info, *, additional_pps=None): info = self.run_pp(pp, info) return info - def pre_process(self, ie_info, key='pre_process', files_to_move=None): + def pre_process(self, ie_info, key='pre_process'): info = dict(ie_info) - info['__files_to_move'] = files_to_move or {} try: info = self.run_all_pps(key, info) except PostProcessingError as err: msg = f'Preprocessing: {err}' info.setdefault('__pending_error', msg) self.report_error(msg, is_error=False) - return info, info.pop('__files_to_move', None) + return info - def post_process(self, filename, info, files_to_move=None): + def post_process(self, filename, info): """Run all the postprocessors on the given file.""" info['filepath'] = filename - info['__files_to_move'] = files_to_move or {} info = self.run_all_pps('post_process', info, additional_pps=info.get('__postprocessors')) info = self.run_pp(MoveFilesAfterDownloadPP(self), info) - del info['__files_to_move'] return self.run_all_pps('after_move', info) def _make_archive_id(self, info_dict): diff --git a/yt_dlp/postprocessor/ffmpeg.py b/yt_dlp/postprocessor/ffmpeg.py index e794c1358d..3c069c8c6a 100644 --- a/yt_dlp/postprocessor/ffmpeg.py +++ b/yt_dlp/postprocessor/ffmpeg.py @@ -1016,11 +1016,6 @@ def run(self, info): 'filepath': new_file, } - for sub_info in info['__files_to_move']['requested_subtitles']: - if sub_info['lang'] == lang and sub_info['ext'] == sub['ext']: - sub_info['current_filepath'] = replace_extension(sub_info['current_filepath'], new_ext) - sub_info['final_filepath'] = replace_extension(sub_info['final_filepath'], new_ext) - return sub_filenames, info @@ -1095,11 +1090,6 @@ def fixup_webp(self, info, idx=-1): os.replace(thumbnail_filename, webp_filename) thumbnail['filepath'] = webp_filename - for thumb_info in info['__files_to_move']['thumbnails']: - if thumb_info['id'] == thumbnail['id']: - thumb_info['current_filepath'] = replace_extension(thumbnail_filename, 'webp') - thumb_info['final_filepath'] = replace_extension(thumb_info['final_filepath'], 'webp') - @staticmethod def _options(target_ext): yield from ('-update', '1') @@ -1137,11 +1127,6 @@ def run(self, info): thumbnail_dict['filepath'] = self.convert_thumbnail(original_thumbnail, target_ext) files_to_delete.append(original_thumbnail) - for thumb_info in info['__files_to_move']['thumbnails']: - if thumb_info['id'] == thumbnail_dict['id']: - thumb_info['current_filepath'] = replace_extension(thumb_info['current_filepath'], target_ext) - thumb_info['final_filepath'] = replace_extension(thumb_info['final_filepath'], target_ext) - if not has_thumbnail: self.to_screen('There aren\'t any thumbnails to convert') return files_to_delete, info