ExtractorError for errors during extraction
authorPhilipp Hagemeister <phihag@phihag.de>
Tue, 1 Jan 2013 19:27:53 +0000 (20:27 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Tue, 1 Jan 2013 19:27:53 +0000 (20:27 +0100)
youtube_dl/FileDownloader.py
youtube_dl/InfoExtractors.py
youtube_dl/utils.py

index ebc2552dfc0933306a2e50b1e4a9b0bc8e501270..756fc72ec8e823751e891cdc3e7041506a0f6fe8 100644 (file)
@@ -210,7 +210,7 @@ class FileDownloader(object):
         """Checks if the output template is fixed."""
         return (re.search(u'(?u)%\\(.+?\\)s', self.params['outtmpl']) is None)
 
-    def trouble(self, message=None):
+    def trouble(self, message=None, tb=None):
         """Determine action to take when a download problem appears.
 
         Depending on if the downloader has been configured to ignore
@@ -220,7 +220,9 @@ class FileDownloader(object):
         if message is not None:
             self.to_stderr(message)
         if self.params.get('verbose'):
-            self.to_stderr(u''.join(traceback.format_list(traceback.extract_stack())))
+            if tb is None:
+                tb = u''.join(traceback.format_list(traceback.extract_stack()))
+            self.to_stderr(tb)
         if not self.params.get('ignoreerrors', False):
             raise DownloadError(message)
         self._download_retcode = 1
@@ -485,14 +487,24 @@ class FileDownloader(object):
 
                 # Warn if the _WORKING attribute is False
                 if not ie.working():
-                    self.trouble(u'WARNING: the program functionality for this site has been marked as broken, '
-                                 u'and will probably not work. If you want to go on, use the -i option.')
+                    self.to_stderr(u'WARNING: the program functionality for this site has been marked as broken, '
+                                   u'and will probably not work. If you want to go on, use the -i option.')
 
                 # Suitable InfoExtractor found
                 suitable_found = True
 
                 # Extract information from URL and process it
-                videos = ie.extract(url)
+                try:
+                    videos = ie.extract(url)
+                except ExtractorError as de: # An error we somewhat expected
+                    self.trouble(u'ERROR: ' + compat_str(de), compat_str(u''.join(traceback.format_tb(de.traceback))))
+                    break
+                except Exception as e:
+                    if self.params.get('ignoreerrors', False):
+                        self.trouble(u'ERROR: ' + compat_str(e), tb=compat_str(traceback.format_exc()))
+                        break
+                    else:
+                        raise
 
                 if len(videos or []) > 1 and self.fixed_template():
                     raise SameFileError(self.params['outtmpl'])
index 18326e294f50885670e036183797419047db58f5..0c101e704728330a597a682e4d081a2b07aa9bf4 100755 (executable)
@@ -3808,8 +3808,7 @@ class UstreamIE(InfoExtractor):
             webpage_bytes = urlh.read()
             webpage = webpage_bytes.decode('utf-8', 'ignore')
         except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
-            self._downloader.trouble(u'ERROR: unable to download webpage: %s' % compat_str(err))
-            return
+            raise ExtractorError(u'unable to download webpage: %s' % compat_str(err))
         m = re.search(r'data-title="(?P<title>.+)"',webpage)
         title = m.group('title')
         m = re.search(r'<a class="state" data-content-type="channel" data-content-id="(?P<uploader>\d+)"',webpage)
index e9336bcddcb11818b8abe58e490edac52740344c..91e1803265dd88d3c50943c44cbb598fd4a139b1 100644 (file)
@@ -410,6 +410,17 @@ def encodeFilename(s):
     else:
         return s.encode(sys.getfilesystemencoding(), 'ignore')
 
+
+class ExtractorError(Exception):
+    """Error during info extraction."""
+    def __init__(self, msg, tb=None):
+        """ tb is the original traceback (so that it can be printed out) """
+        super(ExtractorError, self).__init__(msg)
+        if tb is None:
+            tb = sys.exc_info()[2]
+        self.traceback = tb
+
+
 class DownloadError(Exception):
     """Download Error exception.