1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-23 08:54: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) self.set_downloader(downloader)
@classmethod @classmethod
def suitable(cls, url): def valid_url_match(cls, url):
"""Receives a URL and returns True if suitable for this IE."""
# This does not use has/getattr intentionally - we want to know whether # This does not use has/getattr intentionally - we want to know whether
# we have cached the regexp for *this* class, whereas getattr would also # we have cached the regexp for *this* class, whereas getattr would also
# match the superclass # match the superclass
if '_VALID_URL_RE' not in cls.__dict__: if '_VALID_URL_RE' not in cls.__dict__:
cls._VALID_URL_RE = re.compile(cls._VALID_URL) 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 @classmethod
def _match_id(cls, url): def _match_id(cls, url):
if '_VALID_URL_RE' not in cls.__dict__: m = cls.valid_url_match(url)
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
m = cls._VALID_URL_RE.match(url)
assert m assert m
return compat_str(m.group('id')) return compat_str(m.group('id'))