Don't crash in FileDownloader if subtitles couldn't be found and errors are ignored

pull/8/head
Jaime Marquínez Ferrándiz 12 years ago
parent ef767f9fd5
commit bafeed9f5d

@ -485,14 +485,17 @@ class FileDownloader(object):
subtitle = info_dict['subtitles'][0] subtitle = info_dict['subtitles'][0]
(sub_error, sub_lang, sub) = subtitle (sub_error, sub_lang, sub) = subtitle
sub_format = self.params.get('subtitlesformat') sub_format = self.params.get('subtitlesformat')
try: if sub_error:
sub_filename = filename.rsplit('.', 1)[0] + u'.' + sub_lang + u'.' + sub_format self.report_warning("Some error while getting the subtitles")
self.report_writesubtitles(sub_filename) else:
with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile: try:
subfile.write(sub) sub_filename = filename.rsplit('.', 1)[0] + u'.' + sub_lang + u'.' + sub_format
except (OSError, IOError): self.report_writesubtitles(sub_filename)
self.report_error(u'Cannot write subtitles file ' + descfn) with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile:
return subfile.write(sub)
except (OSError, IOError):
self.report_error(u'Cannot write subtitles file ' + descfn)
return
if self.params.get('onlysubtitles', False): if self.params.get('onlysubtitles', False):
return return
@ -501,14 +504,17 @@ class FileDownloader(object):
sub_format = self.params.get('subtitlesformat') sub_format = self.params.get('subtitlesformat')
for subtitle in subtitles: for subtitle in subtitles:
(sub_error, sub_lang, sub) = subtitle (sub_error, sub_lang, sub) = subtitle
try: if sub_error:
sub_filename = filename.rsplit('.', 1)[0] + u'.' + sub_lang + u'.' + sub_format self.report_warning("Some error while getting the subtitles")
self.report_writesubtitles(sub_filename) else:
with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile: try:
subfile.write(sub) sub_filename = filename.rsplit('.', 1)[0] + u'.' + sub_lang + u'.' + sub_format
except (OSError, IOError): self.report_writesubtitles(sub_filename)
self.trouble(u'ERROR: Cannot write subtitles file ' + descfn) with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile:
return subfile.write(sub)
except (OSError, IOError):
self.trouble(u'ERROR: Cannot write subtitles file ' + descfn)
return
if self.params.get('onlysubtitles', False): if self.params.get('onlysubtitles', False):
return return

Loading…
Cancel
Save