1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-26 10:24:33 +01:00

[chore] DRY: move common _VALID_URL_RE caching to a method

This commit is contained in:
Elan Ruusamäe 2018-12-18 13:15:38 +02:00 committed by Elan Ruusamäe
parent 00eb865b3c
commit 16b73da1cb

View File

@ -400,21 +400,24 @@ class InfoExtractor(object):
self.set_downloader(downloader)
@classmethod
def suitable(cls, url):
"""Receives a URL and returns True if suitable for this IE."""
def valid_url_match(cls, url):
# This does not use has/getattr intentionally - we want to know whether
# we have cached the regexp for *this* class, whereas getattr would also
# match the superclass
if '_VALID_URL_RE' not in cls.__dict__:
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
return cls._VALID_URL_RE.match(url) is not None
m = cls._VALID_URL_RE.match(url)
return m
@classmethod
def suitable(cls, url):
"""Receives a URL and returns True if suitable for this IE."""
m = cls.valid_url_match(url)
return m 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)
m = cls.valid_url_match(url)
assert m
return compat_str(m.group('id'))