Merge remote-tracking branch 'jaimeMF/color_error_messages'
authorPhilipp Hagemeister <phihag@phihag.de>
Thu, 28 Mar 2013 23:25:48 +0000 (00:25 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Thu, 28 Mar 2013 23:25:48 +0000 (00:25 +0100)
1  2 
youtube_dl/FileDownloader.py
youtube_dl/InfoExtractors.py

index 96130152ddd5d0855d2eed96e11c6cd41d0fb29c,8d21a79d5635a59a6666c521e870b6caeb5aec41..5087b4cc824db2d7857407f3215cd0baaede9838
@@@ -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):
 +                return 
  
          if self.params.get('writeinfojson', False):
              infofn = filename + u'.info.json'
                  except ExtractorError as de: # An error we somewhat expected
                      self.trouble(u'ERROR: ' + compat_str(de), de.format_traceback())
                      break
 +                except MaxDownloadsReached:
 +                    self.to_screen(u'[info] Maximum number of downloaded files reached.')
 +                    raise
                  except 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()))
                          break
                      else:
                          raise
index 3f7950cb834c984d97c9c4c1c2899930f9a0a682,83bf5b8f652698644e5a2e82f5cd116eb497bb09..8e164760b5d4c5ec6661a1dcd638263faea96c50
@@@ -524,29 -501,15 +524,29 @@@ class YoutubeIE(InfoExtractor)
          else:
              video_description = ''
  
 -        # closed captions
 +        # subtitles
          video_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)
 +            return
  
          if '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])