Detect existing files correctly even when there is remux/recode

:ci skip dl
This commit is contained in:
pukkandan 2021-01-28 10:48:36 +05:30
parent 179122495b
commit 6b591b2925
2 changed files with 32 additions and 17 deletions

View File

@ -296,6 +296,9 @@ class YoutubeDL(object):
Progress hooks are guaranteed to be called at least once Progress hooks are guaranteed to be called at least once
(with status "finished") if the download is successful. (with status "finished") if the download is successful.
merge_output_format: Extension to use when merging formats. merge_output_format: Extension to use when merging formats.
final_ext: Expected final extension; used to detect when the file was
already downloaded and converted. "merge_output_format" is
replaced by this extension when given
fixup: Automatically correct known faults of the file. fixup: Automatically correct known faults of the file.
One of: One of:
- "never": do nothing - "never": do nothing
@ -438,6 +441,11 @@ class YoutubeDL(object):
if self.params.get('geo_verification_proxy') is None: if self.params.get('geo_verification_proxy') is None:
self.params['geo_verification_proxy'] = self.params['cn_verification_proxy'] self.params['geo_verification_proxy'] = self.params['cn_verification_proxy']
if self.params.get('final_ext'):
if self.params.get('merge_output_format'):
self.report_warning('--merge-output-format will be ignored since --remux-video or --recode-video is given')
self.params['merge_output_format'] = self.params['final_ext']
check_deprecated('autonumber_size', '--autonumber-size', 'output template with %(autonumber)0Nd, where N in the number of digits') check_deprecated('autonumber_size', '--autonumber-size', 'output template with %(autonumber)0Nd, where N in the number of digits')
check_deprecated('autonumber', '--auto-number', '-o "%(autonumber)s-%(title)s.%(ext)s"') check_deprecated('autonumber', '--auto-number', '-o "%(autonumber)s-%(title)s.%(ext)s"')
check_deprecated('usetitle', '--title', '-o "%(title)s-%(id)s.%(ext)s"') check_deprecated('usetitle', '--title', '-o "%(title)s-%(id)s.%(ext)s"')
@ -2204,22 +2212,27 @@ class YoutubeDL(object):
if not self.params.get('skip_download', False): if not self.params.get('skip_download', False):
try: try:
def existing_file(filename, temp_filename): def existing_file(*filepaths):
file_exists = os.path.exists(encodeFilename(filename)) ext = info_dict.get('ext')
tempfile_exists = ( final_ext = self.params.get('final_ext', ext)
False if temp_filename == filename existing_files = []
else os.path.exists(encodeFilename(temp_filename))) for file in orderedSet(filepaths):
if not self.params.get('overwrites', False) and (file_exists or tempfile_exists): if final_ext != ext:
existing_filename = temp_filename if tempfile_exists else filename converted = replace_extension(file, final_ext, ext)
self.to_screen('[download] %s has already been downloaded and merged' % existing_filename) if os.path.exists(encodeFilename(converted)):
return existing_filename existing_files.append(converted)
if tempfile_exists: if os.path.exists(encodeFilename(file)):
self.report_file_delete(temp_filename) existing_files.append(file)
os.remove(encodeFilename(temp_filename))
if file_exists: if not existing_files or self.params.get('overwrites', False):
self.report_file_delete(filename) for file in orderedSet(existing_files):
os.remove(encodeFilename(filename)) self.report_file_delete(file)
return None os.remove(encodeFilename(file))
return None
self.report_file_already_downloaded(existing_files[0])
info_dict['ext'] = os.path.splitext(existing_files[0])[1][1:]
return existing_files[0]
success = True success = True
if info_dict.get('requested_formats') is not None: if info_dict.get('requested_formats') is not None:
@ -2331,7 +2344,8 @@ class YoutubeDL(object):
assert fixup_policy in ('ignore', 'never') assert fixup_policy in ('ignore', 'never')
if (info_dict.get('requested_formats') is None if (info_dict.get('requested_formats') is None
and info_dict.get('container') == 'm4a_dash'): and info_dict.get('container') == 'm4a_dash'
and info_dict.get('ext') == 'm4a'):
if fixup_policy == 'warn': if fixup_policy == 'warn':
self.report_warning( self.report_warning(
'%s: writing DASH m4a. ' '%s: writing DASH m4a. '

View File

@ -469,6 +469,7 @@ def _real_main(argv=None):
'extract_flat': opts.extract_flat, 'extract_flat': opts.extract_flat,
'mark_watched': opts.mark_watched, 'mark_watched': opts.mark_watched,
'merge_output_format': opts.merge_output_format, 'merge_output_format': opts.merge_output_format,
'final_ext': opts.recodevideo or opts.remuxvideo,
'postprocessors': postprocessors, 'postprocessors': postprocessors,
'fixup': opts.fixup, 'fixup': opts.fixup,
'source_address': opts.source_address, 'source_address': opts.source_address,