Fix --no-overwrite for playlist infojson

Fixes: https://github.com/yt-dlp/yt-dlp/issues/1467#issuecomment-1079922971
This commit is contained in:
pukkandan 2022-03-28 08:44:55 +05:30
parent 90137ca4be
commit cb96c5be70
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

View File

@ -1815,7 +1815,7 @@ class YoutubeDL(object):
ie_result['entries'] = playlist_results
# Write the updated info to json
if _infojson_written and self._write_info_json(
if _infojson_written is True and self._write_info_json(
'updated playlist', ie_result,
self.prepare_filename(ie_copy, 'pl_infojson'), overwrite=True) is None:
return
@ -3786,7 +3786,7 @@ class YoutubeDL(object):
return encoding
def _write_info_json(self, label, ie_result, infofn, overwrite=None):
''' Write infojson and returns True = written, False = skip, None = error '''
''' Write infojson and returns True = written, 'exists' = Already exists, False = skip, None = error '''
if overwrite is None:
overwrite = self.params.get('overwrites', True)
if not self.params.get('writeinfojson'):
@ -3798,14 +3798,15 @@ class YoutubeDL(object):
return None
elif not overwrite and os.path.exists(infofn):
self.to_screen(f'[info] {label.title()} metadata is already present')
else:
self.to_screen(f'[info] Writing {label} metadata as JSON to: {infofn}')
try:
write_json_file(self.sanitize_info(ie_result, self.params.get('clean_infojson', True)), infofn)
except (OSError, IOError):
self.report_error(f'Cannot write {label} metadata to JSON file {infofn}')
return None
return True
return 'exists'
self.to_screen(f'[info] Writing {label} metadata as JSON to: {infofn}')
try:
write_json_file(self.sanitize_info(ie_result, self.params.get('clean_infojson', True)), infofn)
return True
except (OSError, IOError):
self.report_error(f'Cannot write {label} metadata to JSON file {infofn}')
return None
def _write_description(self, label, ie_result, descfn):
''' Write description and returns True = written, False = skip, None = error '''