[lazy_extractors] Fix suitable and add flake8 test

This commit is contained in:
pukkandan 2021-08-23 00:49:23 +05:30
parent 4dfbf8696b
commit 3fb4e21b38
No known key found for this signature in database
GPG key ID: 0F00D95A001F4698
6 changed files with 9 additions and 8 deletions

View file

@ -27,5 +27,7 @@ jobs:
python-version: 3.9 python-version: 3.9
- name: Install flake8 - name: Install flake8
run: pip 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 - name: Run flake8
run: flake8 . run: flake8 .

View file

@ -8,10 +8,6 @@ import re
class LazyLoadExtractor(object): class LazyLoadExtractor(object):
_module = None _module = None
@classmethod
def ie_key(cls):
return cls.__name__[:-2]
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
mod = __import__(cls._module, fromlist=(cls.__name__,)) mod = __import__(cls._module, fromlist=(cls.__name__,))
real_cls = getattr(mod, cls.__name__) real_cls = getattr(mod, cls.__name__)

View file

@ -32,6 +32,7 @@ with open('devscripts/lazy_load_template.py', 'rt') as f:
module_contents = [ module_contents = [
module_template, module_template,
getsource(InfoExtractor.ie_key),
getsource(InfoExtractor._match_valid_url), getsource(InfoExtractor._match_valid_url),
getsource(InfoExtractor.suitable), getsource(InfoExtractor.suitable),
'\nclass LazyLoadSearchExtractor(LazyLoadExtractor):\n pass\n'] '\nclass LazyLoadSearchExtractor(LazyLoadExtractor):\n pass\n']
@ -104,7 +105,7 @@ for ie in ordered_cls:
names.append(name) names.append(name)
module_contents.append( module_contents.append(
'_ALL_CLASSES = [{0}]'.format(', '.join(names))) '\n_ALL_CLASSES = [{0}]'.format(', '.join(names)))
module_src = '\n'.join(module_contents) + '\n' module_src = '\n'.join(module_contents) + '\n'

View file

@ -458,6 +458,8 @@ class InfoExtractor(object):
@classmethod @classmethod
def suitable(cls, url): def suitable(cls, url):
"""Receives a URL and returns True if suitable for this IE.""" """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 return cls._match_valid_url(url) is not None
@classmethod @classmethod
@ -622,7 +624,7 @@ class InfoExtractor(object):
@classmethod @classmethod
def ie_key(cls): def ie_key(cls):
"""A string for getting the InfoExtractor with get_info_extractor""" """A string for getting the InfoExtractor with get_info_extractor"""
return compat_str(cls.__name__[:-2]) return cls.__name__[:-2]
@property @property
def IE_NAME(self): def IE_NAME(self):

View file

@ -297,6 +297,8 @@ class RutubePlaylistIE(RutubePlaylistBaseIE):
@classmethod @classmethod
def suitable(cls, url): def suitable(cls, url):
from ..utils import int_or_none, parse_qs
if not super(RutubePlaylistIE, cls).suitable(url): if not super(RutubePlaylistIE, cls).suitable(url):
return False return False
params = parse_qs(url) params = parse_qs(url)

View file

@ -1837,8 +1837,6 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
@classmethod @classmethod
def suitable(cls, url): def suitable(cls, url):
# Hack for lazy extractors until more generic solution is implemented
# (see #28780)
from ..utils import parse_qs from ..utils import parse_qs
qs = parse_qs(url) qs = parse_qs(url)