Skip to content
This repository
Browse code

ExtractorError for errors during extraction

  • Loading branch information...
commit 1c256f7047051bf351ed5aedb95d8e705685a06b 1 parent a34dd63
Philipp Hagemeister authored January 01, 2013
22  youtube_dl/FileDownloader.py
@@ -210,7 +210,7 @@ def fixed_template(self):
210 210
         """Checks if the output template is fixed."""
211 211
         return (re.search(u'(?u)%\\(.+?\\)s', self.params['outtmpl']) is None)
212 212
 
213  
-    def trouble(self, message=None):
  213
+    def trouble(self, message=None, tb=None):
214 214
         """Determine action to take when a download problem appears.
215 215
 
216 216
         Depending on if the downloader has been configured to ignore
@@ -220,7 +220,9 @@ def trouble(self, message=None):
220 220
         if message is not None:
221 221
             self.to_stderr(message)
222 222
         if self.params.get('verbose'):
223  
-            self.to_stderr(u''.join(traceback.format_list(traceback.extract_stack())))
  223
+            if tb is None:
  224
+                tb = u''.join(traceback.format_list(traceback.extract_stack()))
  225
+            self.to_stderr(tb)
224 226
         if not self.params.get('ignoreerrors', False):
225 227
             raise DownloadError(message)
226 228
         self._download_retcode = 1
@@ -485,14 +487,24 @@ def download(self, url_list):
485 487
 
486 488
                 # Warn if the _WORKING attribute is False
487 489
                 if not ie.working():
488  
-                    self.trouble(u'WARNING: the program functionality for this site has been marked as broken, '
489  
-                                 u'and will probably not work. If you want to go on, use the -i option.')
  490
+                    self.to_stderr(u'WARNING: the program functionality for this site has been marked as broken, '
  491
+                                   u'and will probably not work. If you want to go on, use the -i option.')
490 492
 
491 493
                 # Suitable InfoExtractor found
492 494
                 suitable_found = True
493 495
 
494 496
                 # Extract information from URL and process it
495  
-                videos = ie.extract(url)
  497
+                try:
  498
+                    videos = ie.extract(url)
  499
+                except ExtractorError as de: # An error we somewhat expected
  500
+                    self.trouble(u'ERROR: ' + compat_str(de), compat_str(u''.join(traceback.format_tb(de.traceback))))
  501
+                    break
  502
+                except Exception as e:
  503
+                    if self.params.get('ignoreerrors', False):
  504
+                        self.trouble(u'ERROR: ' + compat_str(e), tb=compat_str(traceback.format_exc()))
  505
+                        break
  506
+                    else:
  507
+                        raise
496 508
 
497 509
                 if len(videos or []) > 1 and self.fixed_template():
498 510
                     raise SameFileError(self.params['outtmpl'])
3  youtube_dl/InfoExtractors.py
@@ -3808,8 +3808,7 @@ def _real_extract(self, url):
3808 3808
             webpage_bytes = urlh.read()
3809 3809
             webpage = webpage_bytes.decode('utf-8', 'ignore')
3810 3810
         except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
3811  
-            self._downloader.trouble(u'ERROR: unable to download webpage: %s' % compat_str(err))
3812  
-            return
  3811
+            raise ExtractorError(u'unable to download webpage: %s' % compat_str(err))
3813 3812
         m = re.search(r'data-title="(?P<title>.+)"',webpage)
3814 3813
         title = m.group('title')
3815 3814
         m = re.search(r'<a class="state" data-content-type="channel" data-content-id="(?P<uploader>\d+)"',webpage)
11  youtube_dl/utils.py
@@ -410,6 +410,17 @@ def encodeFilename(s):
410 410
     else:
411 411
         return s.encode(sys.getfilesystemencoding(), 'ignore')
412 412
 
  413
+
  414
+class ExtractorError(Exception):
  415
+    """Error during info extraction."""
  416
+    def __init__(self, msg, tb=None):
  417
+        """ tb is the original traceback (so that it can be printed out) """
  418
+        super(ExtractorError, self).__init__(msg)
  419
+        if tb is None:
  420
+            tb = sys.exc_info()[2]
  421
+        self.traceback = tb
  422
+
  423
+
413 424
 class DownloadError(Exception):
414 425
     """Download Error exception.
415 426
 

0 notes on commit 1c256f7

Please sign in to comment.
Something went wrong with that request. Please try again.