mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-01 02:37:29 +01:00
Apply --no-overwrites for --write-* files as well (Fixes #1980)
This commit is contained in:
parent
525ef9227f
commit
7b6fefc9d4
@ -366,22 +366,6 @@ def report_error(self, message, tb=None):
|
|||||||
error_message = u'%s %s' % (_msg_header, message)
|
error_message = u'%s %s' % (_msg_header, message)
|
||||||
self.trouble(error_message, tb)
|
self.trouble(error_message, tb)
|
||||||
|
|
||||||
def report_writedescription(self, descfn):
|
|
||||||
""" Report that the description file is being written """
|
|
||||||
self.to_screen(u'[info] Writing video description to: ' + descfn)
|
|
||||||
|
|
||||||
def report_writesubtitles(self, sub_filename):
|
|
||||||
""" Report that the subtitles file is being written """
|
|
||||||
self.to_screen(u'[info] Writing video subtitles to: ' + sub_filename)
|
|
||||||
|
|
||||||
def report_writeinfojson(self, infofn):
|
|
||||||
""" Report that the metadata file has been written """
|
|
||||||
self.to_screen(u'[info] Video description metadata as JSON to: ' + infofn)
|
|
||||||
|
|
||||||
def report_writeannotations(self, annofn):
|
|
||||||
""" Report that the annotations file has been written. """
|
|
||||||
self.to_screen(u'[info] Writing video annotations to: ' + annofn)
|
|
||||||
|
|
||||||
def report_file_already_downloaded(self, file_name):
|
def report_file_already_downloaded(self, file_name):
|
||||||
"""Report file has already been fully downloaded."""
|
"""Report file has already been fully downloaded."""
|
||||||
try:
|
try:
|
||||||
@ -791,9 +775,12 @@ def process_info(self, info_dict):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.params.get('writedescription', False):
|
if self.params.get('writedescription', False):
|
||||||
try:
|
|
||||||
descfn = filename + u'.description'
|
descfn = filename + u'.description'
|
||||||
self.report_writedescription(descfn)
|
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(descfn)):
|
||||||
|
self.to_screen(u'[info] Video description is already present')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.to_screen(u'[info] Writing video description to: ' + descfn)
|
||||||
with io.open(encodeFilename(descfn), 'w', encoding='utf-8') as descfile:
|
with io.open(encodeFilename(descfn), 'w', encoding='utf-8') as descfile:
|
||||||
descfile.write(info_dict['description'])
|
descfile.write(info_dict['description'])
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
@ -803,9 +790,12 @@ def process_info(self, info_dict):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.params.get('writeannotations', False):
|
if self.params.get('writeannotations', False):
|
||||||
try:
|
|
||||||
annofn = filename + u'.annotations.xml'
|
annofn = filename + u'.annotations.xml'
|
||||||
self.report_writeannotations(annofn)
|
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(annofn)):
|
||||||
|
self.to_screen(u'[info] Video annotations are already present')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.to_screen(u'[info] Writing video annotations to: ' + annofn)
|
||||||
with io.open(encodeFilename(annofn), 'w', encoding='utf-8') as annofile:
|
with io.open(encodeFilename(annofn), 'w', encoding='utf-8') as annofile:
|
||||||
annofile.write(info_dict['annotations'])
|
annofile.write(info_dict['annotations'])
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
@ -828,7 +818,10 @@ def process_info(self, info_dict):
|
|||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
sub_filename = subtitles_filename(filename, sub_lang, sub_format)
|
sub_filename = subtitles_filename(filename, sub_lang, sub_format)
|
||||||
self.report_writesubtitles(sub_filename)
|
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(sub_filename)):
|
||||||
|
self.to_screen(u'[info] Video subtitle %s.%s is already_present' % (sub_lang, sub_format))
|
||||||
|
else:
|
||||||
|
self.to_screen(u'[info] Writing video subtitles to: ' + sub_filename)
|
||||||
with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile:
|
with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile:
|
||||||
subfile.write(sub)
|
subfile.write(sub)
|
||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
@ -837,7 +830,10 @@ def process_info(self, info_dict):
|
|||||||
|
|
||||||
if self.params.get('writeinfojson', False):
|
if self.params.get('writeinfojson', False):
|
||||||
infofn = os.path.splitext(filename)[0] + u'.info.json'
|
infofn = os.path.splitext(filename)[0] + u'.info.json'
|
||||||
self.report_writeinfojson(infofn)
|
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(infofn)):
|
||||||
|
self.to_screen(u'[info] Video description metadata is already present')
|
||||||
|
else:
|
||||||
|
self.to_screen(u'[info] Writing video description metadata as JSON to: ' + infofn)
|
||||||
try:
|
try:
|
||||||
json_info_dict = dict((k, v) for k, v in info_dict.items() if not k in ['urlhandle'])
|
json_info_dict = dict((k, v) for k, v in info_dict.items() if not k in ['urlhandle'])
|
||||||
write_json_file(json_info_dict, encodeFilename(infofn))
|
write_json_file(json_info_dict, encodeFilename(infofn))
|
||||||
@ -849,6 +845,10 @@ def process_info(self, info_dict):
|
|||||||
if info_dict.get('thumbnail') is not None:
|
if info_dict.get('thumbnail') is not None:
|
||||||
thumb_format = determine_ext(info_dict['thumbnail'], u'jpg')
|
thumb_format = determine_ext(info_dict['thumbnail'], u'jpg')
|
||||||
thumb_filename = os.path.splitext(filename)[0] + u'.' + thumb_format
|
thumb_filename = os.path.splitext(filename)[0] + u'.' + thumb_format
|
||||||
|
if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(infofn)):
|
||||||
|
self.to_screen(u'[%s] %s: Thumbnail is already present' %
|
||||||
|
(info_dict['extractor'], info_dict['id']))
|
||||||
|
else:
|
||||||
self.to_screen(u'[%s] %s: Downloading thumbnail ...' %
|
self.to_screen(u'[%s] %s: Downloading thumbnail ...' %
|
||||||
(info_dict['extractor'], info_dict['id']))
|
(info_dict['extractor'], info_dict['id']))
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user