[commonmistakes] Detect BOMs at the beginning of URLs
[youtube-dl] / youtube_dl / extractor / commonmistakes.py
index dbbf27a7486ab78a239df5a21a761b911a1e4a6e..2f86e2381f447faa7b42d6056e685bc04f101f9c 100644 (file)
@@ -27,3 +27,20 @@ class CommonMistakesIE(InfoExtractor):
         if not self._downloader.params.get('verbose'):
             msg += ' Add -v to the command line to see what arguments and configuration youtube-dl got.'
         raise ExtractorError(msg, expected=True)
+
+
+class UnicodeBOMIE(InfoExtractor):
+        IE_DESC = False
+        _VALID_URL = r'(?P<bom>\ufeff)(?P<id>.*)$'
+
+        _TESTS = [{
+            'url': '\ufeffhttp://www.youtube.com/watch?v=BaW_jenozKc',
+            'only_matching': True,
+        }]
+
+        def _real_extract(self, url):
+            real_url = self._match_id(url)
+            self.report_warning(
+                'Your URL starts with a Byte Order Mark (BOM). '
+                'Removing the BOM and looking for "%s" ...' % real_url)
+            return self.url_result(real_url)