Merge branch 'master' of https://github.com/rg3/youtube-dl
[youtube-dl] / youtube_dl / utils.py
index 463804e183117b23efd8f0e4b0ad9b132e519ddb..8f856ee8c073dd9095f2b62b1567eabdb321c117 100644 (file)
@@ -8,6 +8,7 @@ import locale
 import os
 import re
 import sys
+import traceback
 import zlib
 import email.utils
 import json
@@ -154,6 +155,7 @@ std_headers = {
     'Accept-Encoding': 'gzip, deflate',
     'Accept-Language': 'en-us,en;q=0.5',
 }
+
 def preferredencoding():
     """Get preferred encoding.
 
@@ -187,7 +189,6 @@ else:
         with open(fn, 'w', encoding='utf-8') as f:
             json.dump(obj, f)
 
-
 def htmlentity_transform(matchobj):
     """Transforms an HTML entity to a character.
 
@@ -410,6 +411,20 @@ def encodeFilename(s):
     else:
         return s.encode(sys.getfilesystemencoding(), 'ignore')
 
+
+class ExtractorError(Exception):
+    """Error during info extraction."""
+    def __init__(self, msg, tb=None):
+        """ tb, if given, is the original traceback (so that it can be printed out). """
+        super(ExtractorError, self).__init__(msg)
+        self.traceback = tb
+
+    def format_traceback(self):
+        if self.traceback is None:
+            return None
+        return u''.join(traceback.format_tb(self.traceback))
+
+
 class DownloadError(Exception):
     """Download Error exception.