|
|
|
@ -3208,7 +3208,6 @@ class YoutubeDL:
|
|
|
|
|
# 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))
|
|
|
|
@ -3236,13 +3235,11 @@ class YoutubeDL:
|
|
|
|
|
sub_files = self._write_subtitles(info_dict, temp_filename)
|
|
|
|
|
if sub_files is None:
|
|
|
|
|
return
|
|
|
|
|
files_to_move.update(dict(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.update(dict(thumb_files))
|
|
|
|
|
|
|
|
|
|
infofn = self.prepare_filename(info_dict, 'infojson')
|
|
|
|
|
_infojson_written = self._write_info_json('video', info_dict, infofn)
|
|
|
|
@ -3316,13 +3313,12 @@ class YoutubeDL:
|
|
|
|
|
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:
|
|
|
|
@ -3436,9 +3432,6 @@ class YoutubeDL:
|
|
|
|
|
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)
|
|
|
|
@ -3452,7 +3445,6 @@ class YoutubeDL:
|
|
|
|
|
|
|
|
|
|
dl_filename = dl_filename or temp_filename
|
|
|
|
|
info_dict['__finaldir'] = os.path.dirname(os.path.abspath(encodeFilename(full_filename)))
|
|
|
|
|
|
|
|
|
|
except network_exceptions as err:
|
|
|
|
|
self.report_error('unable to download video data: %s' % error_to_compat_str(err))
|
|
|
|
|
return
|
|
|
|
@ -3523,7 +3515,7 @@ class YoutubeDL:
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
@ -3644,8 +3636,6 @@ class YoutubeDL:
|
|
|
|
|
os.remove(filename)
|
|
|
|
|
except OSError:
|
|
|
|
|
self.report_warning(f'Unable to delete file {filename}')
|
|
|
|
|
if filename in info.get('__files_to_move', []): # NB: Delete even if None
|
|
|
|
|
del info['__files_to_move'][filename]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def post_extract(info_dict):
|
|
|
|
@ -3662,8 +3652,7 @@ class YoutubeDL:
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
@ -3675,10 +3664,7 @@ class YoutubeDL:
|
|
|
|
|
|
|
|
|
|
if not files_to_delete:
|
|
|
|
|
return infodict
|
|
|
|
|
if self.params.get('keepvideo', False):
|
|
|
|
|
for f in files_to_delete:
|
|
|
|
|
infodict['__files_to_move'].setdefault(f, '')
|
|
|
|
|
else:
|
|
|
|
|
if not self.params.get('keepvideo', False):
|
|
|
|
|
self._delete_downloaded_files(
|
|
|
|
|
*files_to_delete, info=infodict, msg='Deleting original file %s (pass -k to keep)')
|
|
|
|
|
return infodict
|
|
|
|
@ -3691,23 +3677,27 @@ class YoutubeDL:
|
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
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, files_to_move
|
|
|
|
|
|
|
|
|
|
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['__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']
|
|
|
|
|
info.pop('__multiple_thumbnails', None)
|
|
|
|
|
return self.run_all_pps('after_move', info)
|
|
|
|
|
|
|
|
|
|
def _make_archive_id(self, info_dict):
|
|
|
|
@ -4294,10 +4284,11 @@ class YoutubeDL:
|
|
|
|
|
sub_filename = subtitles_filename(filename, sub_lang, sub_format, info_dict.get('ext'))
|
|
|
|
|
sub_filename_final = subtitles_filename(sub_filename_base, sub_lang, sub_format, info_dict.get('ext'))
|
|
|
|
|
existing_sub = self.existing_file((sub_filename_final, sub_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, sub_filename_final))
|
|
|
|
|
ret.append(existing_sub)
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
self.to_screen(f'[info] Writing video subtitles to: {sub_filename}')
|
|
|
|
@ -4308,7 +4299,7 @@ class YoutubeDL:
|
|
|
|
|
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, sub_filename_final))
|
|
|
|
|
ret.append(sub_filename)
|
|
|
|
|
continue
|
|
|
|
|
except OSError:
|
|
|
|
|
self.report_error(f'Cannot write video subtitles file {sub_filename}')
|
|
|
|
@ -4319,7 +4310,7 @@ class YoutubeDL:
|
|
|
|
|
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, sub_filename_final))
|
|
|
|
|
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'
|
|
|
|
@ -4339,6 +4330,7 @@ class YoutubeDL:
|
|
|
|
|
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
|
|
|
|
@ -4360,7 +4352,7 @@ class YoutubeDL:
|
|
|
|
|
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, thumb_filename_final))
|
|
|
|
|
ret.append(existing_thumb)
|
|
|
|
|
else:
|
|
|
|
|
self.to_screen(f'[info] Downloading {thumb_display_id} ...')
|
|
|
|
|
try:
|
|
|
|
@ -4368,7 +4360,7 @@ class YoutubeDL:
|
|
|
|
|
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, thumb_filename_final))
|
|
|
|
|
ret.append(thumb_filename)
|
|
|
|
|
t['filepath'] = thumb_filename
|
|
|
|
|
except network_exceptions as err:
|
|
|
|
|
if isinstance(err, HTTPError) and err.status == 404:
|
|
|
|
@ -4378,4 +4370,5 @@ class YoutubeDL:
|
|
|
|
|
thumbnails.pop(idx)
|
|
|
|
|
if ret and not write_all:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|