[youtube] Add a pseudo-extractor for truncated YouTube video IDs (#4610)
authorPhilipp Hagemeister <phihag@phihag.de>
Thu, 1 Jan 2015 22:44:39 +0000 (23:44 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Thu, 1 Jan 2015 22:44:39 +0000 (23:44 +0100)
youtube_dl/extractor/__init__.py
youtube_dl/extractor/youtube.py

index a95de54cbfd15ddcaab4f24d7ffb4cd378638e7d..9848ff611c1ddc9326dc8afab240182471eb5f41 100644 (file)
@@ -545,6 +545,7 @@ from .youtube import (
     YoutubeShowIE,
     YoutubeSubscriptionsIE,
     YoutubeTopListIE,
+    YoutubeTruncatedIDIE,
     YoutubeTruncatedURLIE,
     YoutubeUserIE,
     YoutubeWatchLaterIE,
index 7f5aeb25bbe175eddf244ec22bedbc5916b58fea..8c7842ee84958d59116976bc49d25e4c77b86ad7 100644 (file)
@@ -1701,3 +1701,20 @@ class YoutubeTruncatedURLIE(InfoExtractor):
             '"http://www.youtube.com/watch?feature=foo&v=BaW_jenozKc" '
             ' or simply  youtube-dl BaW_jenozKc  .',
             expected=True)
+
+
+class YoutubeTruncatedIDIE(InfoExtractor):
+    IE_NAME = 'youtube:truncated_id'
+    IE_DESC = False  # Do not list
+    _VALID_URL = r'https?://(?:www\.)youtube\.com/watch\?v=(?P<id>[0-9A-Za-z_-]{1,10})$'
+
+    _TESTS = [{
+        'url': 'https://www.youtube.com/watch?v=N_708QY7Ob',
+        'only_matching': True,
+    }]
+
+    def _real_extract(self, url):
+        video_id = self._match_id(url)
+        raise ExtractorError(
+            'Incomplete YouTube ID %s. URL %s looks truncated.' % (video_id, url),
+            expected=True)