mirror of https://github.com/yt-dlp/yt-dlp.git
Compare commits
6 Commits
0a3c5aceb5
...
6c8ede8188
Author | SHA1 | Date |
---|---|---|
Kieran Eglin | 6c8ede8188 | |
Kieran Eglin | 3046c17822 | |
Kieran Eglin | dd986a4149 | |
Kieran Eglin | c3fccc58cf | |
Kieran Eglin | 28d5051546 | |
Kieran Eglin | a1ff1d4272 |
|
@ -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)
|
||||
|
@ -1982,9 +1982,8 @@ def __process_playlist(self, ie_result, download):
|
|||
'playlist', ie_result, self.prepare_filename(ie_copy, 'pl_infojson'))
|
||||
if _infojson_written is None:
|
||||
return
|
||||
|
||||
description_file = self._write_description('playlist', ie_result, self.prepare_filename(ie_copy, 'pl_description'))
|
||||
if description_file is None:
|
||||
if self._write_description('playlist', ie_result,
|
||||
self.prepare_filename(ie_copy, 'pl_description')) is None:
|
||||
return
|
||||
# TODO: This should be passed to ThumbnailsConvertor if necessary
|
||||
self._write_thumbnails('playlist', ie_result, self.prepare_filename(ie_copy, 'pl_thumbnail'))
|
||||
|
@ -2885,13 +2884,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,7 +3201,7 @@ 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
|
||||
|
||||
|
@ -3229,8 +3228,8 @@ def check_max_downloads():
|
|||
if not self._ensure_dir_exists(encodeFilename(temp_filename)):
|
||||
return
|
||||
|
||||
description_file = self._write_description('video', info_dict, self.prepare_filename(info_dict, 'description'))
|
||||
if description_file is None:
|
||||
if self._write_description('video', info_dict,
|
||||
self.prepare_filename(info_dict, 'description')) is None:
|
||||
return
|
||||
|
||||
sub_files = self._write_subtitles(info_dict, temp_filename)
|
||||
|
@ -3314,7 +3313,7 @@ def _write_link_file(link_type):
|
|||
for link_type, should_write in write_links.items()):
|
||||
return
|
||||
|
||||
new_info = self.pre_process(info_dict, 'before_dl')
|
||||
new_info, _ = self.pre_process(info_dict, 'before_dl')
|
||||
replace_info_dict(new_info)
|
||||
|
||||
if self.params.get('skip_download'):
|
||||
|
@ -3677,7 +3676,10 @@ 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'):
|
||||
def pre_process(self, ie_info, key='pre_process', files_to_move=None):
|
||||
if files_to_move is not None:
|
||||
self.report_warning('[pre_process] "files_to_move" is deprecated and may be removed in a future version')
|
||||
|
||||
info = dict(ie_info)
|
||||
try:
|
||||
info = self.run_all_pps(key, info)
|
||||
|
@ -3685,13 +3687,17 @@ def pre_process(self, ie_info, key='pre_process'):
|
|||
msg = f'Preprocessing: {err}'
|
||||
info.setdefault('__pending_error', msg)
|
||||
self.report_error(msg, is_error=False)
|
||||
return info
|
||||
return info, files_to_move
|
||||
|
||||
def post_process(self, filename, info):
|
||||
def post_process(self, filename, info, files_to_move=None):
|
||||
"""Run all the postprocessors on the given file."""
|
||||
if files_to_move is not None:
|
||||
self.report_warning('[post_process] "files_to_move" is deprecated and may be removed in a future version')
|
||||
|
||||
info['filepath'] = filename
|
||||
info = self.run_all_pps('post_process', info, additional_pps=info.get('__postprocessors'))
|
||||
info = self.run_pp(MoveFilesAfterDownloadPP(self), info)
|
||||
info.pop('__multiple_thumbnails', None)
|
||||
return self.run_all_pps('after_move', info)
|
||||
|
||||
def _make_archive_id(self, info_dict):
|
||||
|
@ -4233,27 +4239,27 @@ def _write_info_json(self, label, ie_result, infofn, overwrite=None):
|
|||
self.report_error(f'Cannot write {label} metadata to JSON file {infofn}')
|
||||
return None
|
||||
|
||||
def _write_description(self, label, info_dict, filename):
|
||||
def _write_description(self, label, ie_result, descfn):
|
||||
''' Write description and returns True = written, False = skip, None = error '''
|
||||
if not self.params.get('writedescription'):
|
||||
return False
|
||||
elif not filename:
|
||||
elif not descfn:
|
||||
self.write_debug(f'Skipping writing {label} description')
|
||||
return False
|
||||
elif not self._ensure_dir_exists(filename):
|
||||
elif not self._ensure_dir_exists(descfn):
|
||||
return None
|
||||
elif not self.params.get('overwrites', True) and os.path.exists(filename):
|
||||
elif not self.params.get('overwrites', True) and os.path.exists(descfn):
|
||||
self.to_screen(f'[info] {label.title()} description is already present')
|
||||
elif info_dict.get('description') is None:
|
||||
elif ie_result.get('description') is None:
|
||||
self.to_screen(f'[info] There\'s no {label} description to write')
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
self.to_screen(f'[info] Writing {label} description to: {filename}')
|
||||
with open(filename, 'w', encoding='utf-8') as descfile:
|
||||
descfile.write(info_dict['description'])
|
||||
self.to_screen(f'[info] Writing {label} description to: {descfn}')
|
||||
with open(encodeFilename(descfn), 'w', encoding='utf-8') as descfile:
|
||||
descfile.write(ie_result['description'])
|
||||
except OSError:
|
||||
self.report_error(f'Cannot write {label} description file {filename}')
|
||||
self.report_error(f'Cannot write {label} description file {descfn}')
|
||||
return None
|
||||
return True
|
||||
|
||||
|
@ -4282,7 +4288,7 @@ def _write_subtitles(self, info_dict, filename):
|
|||
if existing_sub:
|
||||
self.to_screen(f'[info] Video subtitle {sub_lang}.{sub_format} is already present')
|
||||
sub_info['filepath'] = existing_sub
|
||||
|
||||
ret.append(existing_sub)
|
||||
continue
|
||||
|
||||
self.to_screen(f'[info] Writing video subtitles to: {sub_filename}')
|
||||
|
@ -4293,7 +4299,7 @@ def _write_subtitles(self, info_dict, filename):
|
|||
with open(sub_filename, 'w', encoding='utf-8', newline='') as subfile:
|
||||
subfile.write(sub_info['data'])
|
||||
sub_info['filepath'] = sub_filename
|
||||
|
||||
ret.append(sub_filename)
|
||||
continue
|
||||
except OSError:
|
||||
self.report_error(f'Cannot write video subtitles file {sub_filename}')
|
||||
|
@ -4304,7 +4310,7 @@ def _write_subtitles(self, info_dict, filename):
|
|||
sub_copy.setdefault('http_headers', info_dict.get('http_headers'))
|
||||
self.dl(sub_filename, sub_copy, subtitle=True)
|
||||
sub_info['filepath'] = sub_filename
|
||||
|
||||
ret.append(sub_filename)
|
||||
except (DownloadError, ExtractorError, IOError, OSError, ValueError) + network_exceptions as err:
|
||||
msg = f'Unable to download video subtitles for {sub_lang!r}: {err}'
|
||||
if self.params.get('ignoreerrors') is not True: # False or 'only_download'
|
||||
|
@ -4324,6 +4330,7 @@ def _write_thumbnails(self, label, info_dict, filename, thumb_filename_base=None
|
|||
self.to_screen(f'[info] There are no {label} thumbnails to download')
|
||||
return ret
|
||||
multiple = write_all and len(thumbnails) > 1
|
||||
info_dict['__multiple_thumbnails'] = multiple
|
||||
|
||||
if thumb_filename_base is None:
|
||||
thumb_filename_base = filename
|
||||
|
@ -4345,7 +4352,7 @@ def _write_thumbnails(self, label, info_dict, filename, thumb_filename_base=None
|
|||
self.to_screen('[info] %s is already present' % (
|
||||
thumb_display_id if multiple else f'{label} thumbnail').capitalize())
|
||||
t['filepath'] = existing_thumb
|
||||
|
||||
ret.append(existing_thumb)
|
||||
else:
|
||||
self.to_screen(f'[info] Downloading {thumb_display_id} ...')
|
||||
try:
|
||||
|
@ -4353,7 +4360,7 @@ def _write_thumbnails(self, label, info_dict, filename, thumb_filename_base=None
|
|||
self.to_screen(f'[info] Writing {thumb_display_id} to: {thumb_filename}')
|
||||
with open(encodeFilename(thumb_filename), 'wb') as thumbf:
|
||||
shutil.copyfileobj(uf, thumbf)
|
||||
|
||||
ret.append(thumb_filename)
|
||||
t['filepath'] = thumb_filename
|
||||
except network_exceptions as err:
|
||||
if isinstance(err, HTTPError) and err.status == 404:
|
||||
|
|
|
@ -224,4 +224,8 @@ def run(self, info):
|
|||
thumbnail_filename if converted or not self._already_have_thumbnail else None,
|
||||
original_thumbnail if converted and not self._already_have_thumbnail else None,
|
||||
info=info)
|
||||
|
||||
if not self._already_have_thumbnail:
|
||||
info['thumbnails'][idx].pop('filepath', None)
|
||||
|
||||
return [], info
|
||||
|
|
|
@ -662,6 +662,10 @@ def run(self, info):
|
|||
self.run_ffmpeg_multiple_files(input_files, temp_filename, opts)
|
||||
os.replace(temp_filename, filename)
|
||||
|
||||
if not self._already_have_subtitle:
|
||||
for _, subtitle in subtitles.items():
|
||||
subtitle.pop('filepath', None)
|
||||
|
||||
files_to_delete = [] if self._already_have_subtitle else sub_filenames
|
||||
return files_to_delete, info
|
||||
|
||||
|
@ -698,6 +702,7 @@ def run(self, info):
|
|||
infojson_filename = info.get('infojson_filename')
|
||||
options.extend(self._get_infojson_opts(info, infojson_filename))
|
||||
if not infojson_filename:
|
||||
info.pop('infojson_filename', None)
|
||||
files_to_delete.append(info.get('infojson_filename'))
|
||||
elif self._add_infojson is True:
|
||||
self.to_screen('The info-json can only be attached to mkv/mka files')
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
|
||||
class MoveFilesAfterDownloadPP(PostProcessor):
|
||||
TOP_LEVEL_KEYS = ['filepath']
|
||||
# Map of the keys that contain moveable files and the 'type' of the file
|
||||
# for generating the output filename
|
||||
CHILD_KEYS = {
|
||||
|
@ -33,12 +32,7 @@ def move_file_and_write_to_info(self, info_dict, relevant_dict=None, output_file
|
|||
return
|
||||
|
||||
output_file_type = output_file_type or ''
|
||||
current_filepath = relevant_dict['filepath']
|
||||
# This approach is needed to preserved indexed thumbnail paths from `--write-all-thumbnails`
|
||||
# and also to support user-defined extensions (eg: `%(title)s.temp.%(ext)s`)
|
||||
extension = ''.join(Path(current_filepath).suffixes)
|
||||
name_format = self._downloader.prepare_filename(info_dict, output_file_type)
|
||||
final_filepath = replace_extension(name_format, extension)
|
||||
current_filepath, final_filepath = self.determine_filepath(info_dict, relevant_dict, output_file_type)
|
||||
move_result = self.move_file(info_dict, current_filepath, final_filepath)
|
||||
|
||||
if move_result:
|
||||
|
@ -46,6 +40,17 @@ def move_file_and_write_to_info(self, info_dict, relevant_dict=None, output_file
|
|||
else:
|
||||
del relevant_dict['filepath']
|
||||
|
||||
def determine_filepath(self, info_dict, relevant_dict, output_file_type):
|
||||
current_filepath = relevant_dict['filepath']
|
||||
prepared_filepath = self._downloader.prepare_filename(info_dict, output_file_type)
|
||||
|
||||
if (output_file_type == 'thumbnail' and info_dict['__multiple_thumbnails']) or output_file_type == 'subtitle':
|
||||
desired_extension = ''.join(Path(current_filepath).suffixes[-2:])
|
||||
else:
|
||||
desired_extension = Path(current_filepath).suffix
|
||||
|
||||
return current_filepath, replace_extension(prepared_filepath, desired_extension)
|
||||
|
||||
def move_file(self, info_dict, current_filepath, final_filepath):
|
||||
if not current_filepath or not final_filepath:
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue