[common] Add new helper function _match_id
authorPhilipp Hagemeister <phihag@phihag.de>
Sun, 28 Sep 2014 07:31:58 +0000 (09:31 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Sun, 28 Sep 2014 07:31:58 +0000 (09:31 +0200)
youtube_dl/extractor/abc.py
youtube_dl/extractor/common.py

index 7d89f44ee4e6c5a1607c0567aafa3e2172cebbb1..69f89320ce7e30a5fdf65acff01df1668620334f 100644 (file)
@@ -22,8 +22,7 @@ class ABCIE(InfoExtractor):
     }
 
     def _real_extract(self, url):
-        mobj = re.match(self._VALID_URL, url)
-        video_id = mobj.group('id')
+        video_id = self._match_id(url)
         webpage = self._download_webpage(url, video_id)
 
         urls_info_json = self._search_regex(
index 403791e6b7252f2f7432d5aa98d9aab8f8a7da55..8d6a6f601e3a2d9316d6ce9fa08a1b2ac98bbf45 100644 (file)
@@ -165,6 +165,14 @@ class InfoExtractor(object):
             cls._VALID_URL_RE = re.compile(cls._VALID_URL)
         return cls._VALID_URL_RE.match(url) is not None
 
+    @classmethod
+    def _match_id(cls, url):
+        if '_VALID_URL_RE' not in cls.__dict__:
+            cls._VALID_URL_RE = re.compile(cls._VALID_URL)
+        m = cls._VALID_URL_RE.match(url)
+        assert m
+        return m.group('id')
+
     @classmethod
     def working(cls):
         """Getter method for _WORKING."""