]> jfr.im git - yt-dlp.git/commitdiff
[lazy_extractors] Fix `suitable` and add flake8 test
authorpukkandan <redacted>
Sun, 22 Aug 2021 19:19:23 +0000 (00:49 +0530)
committerpukkandan <redacted>
Sun, 22 Aug 2021 19:34:29 +0000 (01:04 +0530)
.github/workflows/quick-test.yml
devscripts/lazy_load_template.py
devscripts/make_lazy_extractors.py
yt_dlp/extractor/common.py
yt_dlp/extractor/rutube.py
yt_dlp/extractor/youtube.py

index 7d409dfc454c40e47cfe7dc819e54c681edd9950..500a504a4a9412941555ed543b69158fe218feef 100644 (file)
@@ -27,5 +27,7 @@ jobs:
         python-version: 3.9
     - name: Install flake8
       run: pip install flake8
+    - name: Make lazy extractors
+      run: python devscripts/make_lazy_extractors.py yt_dlp/extractor/lazy_extractors.py
     - name: Run flake8
       run: flake8 .
index d06655d106513394e70efdd1ef2c7af8d4faa9da..20322e04b2c4da1aec56dd9cd71178aba154c4a5 100644 (file)
@@ -8,10 +8,6 @@
 class 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__)
index 727d28204a4ecb0db9614f2aa2729df8f4d61f47..8189c77dce5a588ac5796c8453e6080a9ab6b920 100644 (file)
@@ -32,6 +32,7 @@
 
 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 @@ def build_lazy_ie(ie, name):
         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'
 
index 31356111bca4bc4d0316e3752de7cda4b97f3fdf..734651193a3413a5a0068dd2f24acd33faac7e13 100644 (file)
@@ -458,6 +458,8 @@ def _match_valid_url(cls, url):
     @classmethod
     def 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 correctly
         return cls._match_valid_url(url) is not None
 
     @classmethod
@@ -622,7 +624,7 @@ def _real_extract(self, url):
     @classmethod
     def ie_key(cls):
         """A string for getting the InfoExtractor with get_info_extractor"""
-        return compat_str(cls.__name__[:-2])
+        return cls.__name__[:-2]
 
     @property
     def IE_NAME(self):
index 01529315f923fb3fa18f3832dce6bea398c107f7..d027412c48fe7a7ea7c2a3ab113051826faa55aa 100644 (file)
@@ -297,6 +297,8 @@ class RutubePlaylistIE(RutubePlaylistBaseIE):
 
     @classmethod
     def suitable(cls, url):
+        from ..utils import int_or_none, parse_qs
+
         if not super(RutubePlaylistIE, cls).suitable(url):
             return False
         params = parse_qs(url)
index 15e0f8adbc0ac1fa3de56719b24d4867f5443715..236f5809a27a4f124ceb0ed5b61dfbea58210425 100644 (file)
@@ -1837,8 +1837,6 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
 
     @classmethod
     def suitable(cls, url):
-        # Hack for lazy extractors until more generic solution is implemented
-        # (see #28780)
         from ..utils import parse_qs
 
         qs = parse_qs(url)