A feature-rich command-line audio/video downloader
[lazy_extractors] Fix `suitable` and add flake8 test
pukkandan3fb4e21b3806
diff --git a/.github/workflows/quick-test.yml b/.github/workflows/quick-test.ymlindex 7d409dfc45..500a504a4a 100644--- a/.github/workflows/quick-test.yml+++ b/.github/workflows/quick-test.yml@@ -27,5 +27,7 @@ jobs:python-version: 3.9- name: Install flake8run: pip install flake8+ - name: Make lazy extractors+ run: python devscripts/make_lazy_extractors.py yt_dlp/extractor/lazy_extractors.py- name: Run flake8run: flake8 .diff --git a/devscripts/lazy_load_template.py b/devscripts/lazy_load_template.pyindex d06655d106..20322e04b2 100644--- a/devscripts/lazy_load_template.py+++ b/devscripts/lazy_load_template.py@@ -8,10 +8,6 @@ import reclass LazyLoadExtractor(object):_module = None- @classmethod- def ie_key(cls):- return cls.__name__[:-2]-def __new__(cls, *args, **kwargs):mod = __import__(cls._module, fromlist=(cls.__name__,))real_cls = getattr(mod, cls.__name__)diff --git a/devscripts/make_lazy_extractors.py b/devscripts/make_lazy_extractors.pyindex 727d28204a..8189c77dce 100644--- a/devscripts/make_lazy_extractors.py+++ b/devscripts/make_lazy_extractors.py@@ -32,6 +32,7 @@ with open('devscripts/lazy_load_template.py', 'rt') as f:module_contents = [module_template,+ getsource(InfoExtractor.ie_key),getsource(InfoExtractor._match_valid_url),getsource(InfoExtractor.suitable),'\nclass LazyLoadSearchExtractor(LazyLoadExtractor):\n pass\n']@@ -104,7 +105,7 @@ for ie in ordered_cls:names.append(name)module_contents.append(- '_ALL_CLASSES = [{0}]'.format(', '.join(names)))+ '\n_ALL_CLASSES = [{0}]'.format(', '.join(names)))module_src = '\n'.join(module_contents) + '\n'diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.pyindex 31356111bc..734651193a 100644--- a/yt_dlp/extractor/common.py+++ b/yt_dlp/extractor/common.py@@ -458,6 +458,8 @@ class InfoExtractor(object):@classmethoddef suitable(cls, url):"""Receives a URL and returns True if suitable for this IE."""+ # This function must import everything it needs (except other extractors),+ # so that lazy_extractors works correctlyreturn cls._match_valid_url(url) is not None@classmethod@@ -622,7 +624,7 @@ class InfoExtractor(object):@classmethoddef ie_key(cls):"""A string for getting the InfoExtractor with get_info_extractor"""- return compat_str(cls.__name__[:-2])+ return cls.__name__[:-2]@propertydef IE_NAME(self):diff --git a/yt_dlp/extractor/rutube.py b/yt_dlp/extractor/rutube.pyindex 01529315f9..d027412c48 100644--- a/yt_dlp/extractor/rutube.py+++ b/yt_dlp/extractor/rutube.py@@ -297,6 +297,8 @@ class RutubePlaylistIE(RutubePlaylistBaseIE):@classmethoddef suitable(cls, url):+ from ..utils import int_or_none, parse_qs+if not super(RutubePlaylistIE, cls).suitable(url):return Falseparams = parse_qs(url)diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.pyindex 15e0f8adbc..236f5809a2 100644--- a/yt_dlp/extractor/youtube.py+++ b/yt_dlp/extractor/youtube.py@@ -1837,8 +1837,6 @@ class YoutubeIE(YoutubeBaseInfoExtractor):@classmethoddef suitable(cls, url):- # Hack for lazy extractors until more generic solution is implemented- # (see #28780)from ..utils import parse_qsqs = parse_qs(url)