mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-20 13:57:25 +01:00
Implemented solution suggested by @dirkf using variadic
This commit is contained in:
parent
7b93fb5ddc
commit
42d0fba2bf
@ -6,6 +6,7 @@
|
||||
age_restricted,
|
||||
bug_reports_message,
|
||||
classproperty,
|
||||
variadic,
|
||||
write_string,
|
||||
)
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
NO_ATTR = object()
|
||||
STATIC_CLASS_PROPERTIES = [
|
||||
'IE_NAME', '_ENABLED', '_VALID_URL', '_VALID_URLS', # Used for URL matching
|
||||
'IE_NAME', '_ENABLED', '_VALID_URL', # Used for URL matching
|
||||
'_WORKING', 'IE_DESC', '_NETRC_MACHINE', 'SEARCH_KEY', # Used for --extractor-descriptions
|
||||
'age_limit', # Used for --age-limit (evaluated)
|
||||
'_RETURN_TYPE', # Accessed in CLI only with instance (evaluated)
|
||||
|
@ -447,7 +447,7 @@ class InfoExtractor:
|
||||
|
||||
|
||||
Subclasses of this should also be added to the list of extractors and
|
||||
should define a _VALID_URL regexp (or a list of _VALID_URLS) and, re-define the _real_extract() and
|
||||
should define a _VALID_URL regexp (a single string or a list) and, re-define the _real_extract() and
|
||||
(optionally) _real_initialize() methods.
|
||||
|
||||
Subclasses may also override suitable() if necessary, but ensure the function
|
||||
@ -508,7 +508,6 @@ class InfoExtractor:
|
||||
IE_DESC = None
|
||||
SEARCH_KEY = None
|
||||
_VALID_URL = None
|
||||
_VALID_URLS = []
|
||||
_EMBED_REGEX = []
|
||||
|
||||
def _login_hint(self, method=NO_DEFAULT, netrc=None):
|
||||
@ -536,18 +535,13 @@ def _match_valid_url(cls, url):
|
||||
if cls._VALID_URL is False:
|
||||
return None
|
||||
|
||||
if cls._VALID_URLS:
|
||||
if '_VALID_URLS_RE' not in cls.__dict__:
|
||||
cls._VALID_URLS_RE = tuple(map(re.compile, cls._VALID_URLS))
|
||||
return next(filter(None, (
|
||||
valid_url_re.match(url) for valid_url_re in cls._VALID_URLS_RE)), None)
|
||||
|
||||
# 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)
|
||||
cls._VALID_URL_RE = tuple(map(re.compile, variadic(cls._VALID_URL)))
|
||||
return next(filter(None, (
|
||||
valid_url_re.match(url) for valid_url_re in cls._VALID_URL_RE)), None)
|
||||
|
||||
@classmethod
|
||||
def suitable(cls, url):
|
||||
|
Loading…
Reference in New Issue
Block a user