diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-06-22 02:57:00 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-06-22 03:19:55 +0530 |
commit | 5fd8367496b42c7b900b896a0d5460561a2859de (patch) | |
tree | 29f49609c14ec0642aee05e347b107c71b509b5d | |
parent | 0dff8e4d1e6e9fb938f4256ea9af7d81f42fd54f (diff) | |
download | hypervideo-pre-5fd8367496b42c7b900b896a0d5460561a2859de.tar.lz hypervideo-pre-5fd8367496b42c7b900b896a0d5460561a2859de.tar.xz hypervideo-pre-5fd8367496b42c7b900b896a0d5460561a2859de.zip |
[extractor] Support multiple `_VALID_URL`s (#5812)
Authored by: nixxo
-rw-r--r-- | devscripts/lazy_load_template.py | 1 | ||||
-rw-r--r-- | yt_dlp/extractor/common.py | 8 |
2 files changed, 5 insertions, 4 deletions
diff --git a/devscripts/lazy_load_template.py b/devscripts/lazy_load_template.py index c8815e01b..6f52165c5 100644 --- a/devscripts/lazy_load_template.py +++ b/devscripts/lazy_load_template.py @@ -6,6 +6,7 @@ from ..utils import ( age_restricted, bug_reports_message, classproperty, + variadic, write_string, ) diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.py index 2ea36c63d..3f7dcb82b 100644 --- a/yt_dlp/extractor/common.py +++ b/yt_dlp/extractor/common.py @@ -475,8 +475,8 @@ class InfoExtractor: Subclasses of this should also be added to the list of extractors and - should define a _VALID_URL regexp and, re-define the _real_extract() and - (optionally) _real_initialize() methods. + should define _VALID_URL as a regexp or a Sequence of regexps, and + re-define the _real_extract() and (optionally) _real_initialize() methods. Subclasses may also override suitable() if necessary, but ensure the function signature is preserved and that this function imports everything it needs @@ -566,8 +566,8 @@ class InfoExtractor: # 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, (regex.match(url) for regex in cls._VALID_URL_RE)), None) @classmethod def suitable(cls, url): |