A feature-rich command-line audio/video downloader
Merge remote-tracking branch 'jaimeMF/color_error_messages'
Philipp Hagemeister95506f1235e8
diff --cc youtube_dl/FileDownloader.pyindex 96130152dd,8d21a79d56..5087b4cc82--- a/youtube_dl/FileDownloader.py+++ b/youtube_dl/FileDownloader.py@@@ -460,35 -465,14 +472,35 @@@ class FileDownloader(object)if self.params.get('writesubtitles', False) and 'subtitles' in info_dict and info_dict['subtitles']:# subtitles download errors are already managed as troubles in relevant IE# that way it will silently go on when used with unsupporting IE+ subtitle = info_dict['subtitles'][0]+ (sub_error, sub_lang, sub) = subtitle+ sub_format = self.params.get('subtitlesformat')try:- srtfn = filename.rsplit('.', 1)[0] + u'.srt'- self.report_writesubtitles(srtfn)- with io.open(encodeFilename(srtfn), 'w', encoding='utf-8') as srtfile:- srtfile.write(info_dict['subtitles'])+ sub_filename = filename.rsplit('.', 1)[0] + u'.' + sub_lang + u'.' + sub_format+ self.report_writesubtitles(sub_filename)+ with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile:+ subfile.write(sub)except (OSError, IOError):- self.trouble(u'ERROR: Cannot write subtitles file ' + descfn)+ self.report_error(u'Cannot write subtitles file ' + descfn)return+ if self.params.get('onlysubtitles', False):+ return++ if self.params.get('allsubtitles', False) and 'subtitles' in info_dict and info_dict['subtitles']:+ subtitles = info_dict['subtitles']+ sub_format = self.params.get('subtitlesformat')+ for subtitle in subtitles:+ (sub_error, sub_lang, sub) = subtitle+ try:+ sub_filename = filename.rsplit('.', 1)[0] + u'.' + sub_lang + u'.' + sub_format+ self.report_writesubtitles(sub_filename)+ with io.open(encodeFilename(sub_filename), 'w', encoding='utf-8') as subfile:+ subfile.write(sub)+ except (OSError, IOError):+ self.trouble(u'ERROR: Cannot write subtitles file ' + descfn)+ return+ if self.params.get('onlysubtitles', False):+ returnif self.params.get('writeinfojson', False):infofn = filename + u'.info.json'@@@ -548,12 -532,9 +560,12 @@@except ExtractorError as de: # An error we somewhat expectedself.trouble(u'ERROR: ' + compat_str(de), de.format_traceback())break+ except MaxDownloadsReached:+ self.to_screen(u'[info] Maximum number of downloaded files reached.')+ raiseexcept Exception as e:if self.params.get('ignoreerrors', False):- self.trouble(u'ERROR: ' + compat_str(e), tb=compat_str(traceback.format_exc()))+ self.report_error(u'' + compat_str(e), tb=compat_str(traceback.format_exc()))breakelse:raisediff --cc youtube_dl/InfoExtractors.pyindex 3f7950cb83,83bf5b8f65..8e164760b5--- a/youtube_dl/InfoExtractors.py+++ b/youtube_dl/InfoExtractors.py@@@ -524,29 -501,15 +524,29 @@@ class YoutubeIE(InfoExtractor)else:video_description = ''- # closed captions+ # subtitlesvideo_subtitles = None+if self._downloader.params.get('writesubtitles', False):- (srt_error, video_subtitles) = self._extract_subtitles(video_id)- if srt_error:- self._downloader.trouble(srt_error)+ video_subtitles = self._extract_subtitle(video_id)+ if video_subtitles:+ (sub_error, sub_lang, sub) = video_subtitles[0]+ if sub_error:+ self._downloader.trouble(sub_error)++ if self._downloader.params.get('allsubtitles', False):+ video_subtitles = self._extract_all_subtitles(video_id)+ for video_subtitle in video_subtitles:+ (sub_error, sub_lang, sub) = video_subtitle+ if sub_error:+ self._downloader.trouble(sub_error)++ if self._downloader.params.get('listsubtitles', False):+ sub_lang_list = self._list_available_subtitles(video_id)+ returnif 'length_seconds' not in video_info:- self._downloader.trouble(u'WARNING: unable to extract video duration')+ self._downloader.report_warning(u'unable to extract video duration')video_duration = ''else:video_duration = compat_urllib_parse.unquote_plus(video_info['length_seconds'][0])