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