mirror of https://github.com/yt-dlp/yt-dlp.git
parent
5f7cb91ae9
commit
2c4aaaddc9
|
@ -39,12 +39,6 @@ class {name}({bases}):
|
||||||
_module = '{module}'
|
_module = '{module}'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
make_valid_template = '''
|
|
||||||
@classmethod
|
|
||||||
def _make_valid_url(cls):
|
|
||||||
return {valid_url!r}
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def get_base_name(base):
|
def get_base_name(base):
|
||||||
if base is InfoExtractor:
|
if base is InfoExtractor:
|
||||||
|
@ -61,15 +55,14 @@ def build_lazy_ie(ie, name):
|
||||||
bases=', '.join(map(get_base_name, ie.__bases__)),
|
bases=', '.join(map(get_base_name, ie.__bases__)),
|
||||||
module=ie.__module__)
|
module=ie.__module__)
|
||||||
valid_url = getattr(ie, '_VALID_URL', None)
|
valid_url = getattr(ie, '_VALID_URL', None)
|
||||||
|
if not valid_url and hasattr(ie, '_make_valid_url'):
|
||||||
|
valid_url = ie._make_valid_url()
|
||||||
if valid_url:
|
if valid_url:
|
||||||
s += f' _VALID_URL = {valid_url!r}\n'
|
s += f' _VALID_URL = {valid_url!r}\n'
|
||||||
if not ie._WORKING:
|
if not ie._WORKING:
|
||||||
s += ' _WORKING = False\n'
|
s += ' _WORKING = False\n'
|
||||||
if ie.suitable.__func__ is not InfoExtractor.suitable.__func__:
|
if ie.suitable.__func__ is not InfoExtractor.suitable.__func__:
|
||||||
s += f'\n{getsource(ie.suitable)}'
|
s += f'\n{getsource(ie.suitable)}'
|
||||||
if hasattr(ie, '_make_valid_url'):
|
|
||||||
# search extractors
|
|
||||||
s += make_valid_template.format(valid_url=ie._make_valid_url())
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -466,6 +466,8 @@ class InfoExtractor(object):
|
||||||
# we have cached the regexp for *this* class, whereas getattr would also
|
# we have cached the regexp for *this* class, whereas getattr would also
|
||||||
# match the superclass
|
# match the superclass
|
||||||
if '_VALID_URL_RE' not in cls.__dict__:
|
if '_VALID_URL_RE' not in cls.__dict__:
|
||||||
|
if '_VALID_URL' not in cls.__dict__:
|
||||||
|
cls._VALID_URL = cls._make_valid_url()
|
||||||
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
|
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
|
||||||
return cls._VALID_URL_RE.match(url)
|
return cls._VALID_URL_RE.match(url)
|
||||||
|
|
||||||
|
@ -3658,17 +3660,8 @@ class SearchInfoExtractor(InfoExtractor):
|
||||||
def _make_valid_url(cls):
|
def _make_valid_url(cls):
|
||||||
return r'%s(?P<prefix>|[1-9][0-9]*|all):(?P<query>[\s\S]+)' % cls._SEARCH_KEY
|
return r'%s(?P<prefix>|[1-9][0-9]*|all):(?P<query>[\s\S]+)' % cls._SEARCH_KEY
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def suitable(cls, url):
|
|
||||||
return re.match(cls._make_valid_url(), url) is not None
|
|
||||||
|
|
||||||
def _real_extract(self, query):
|
def _real_extract(self, query):
|
||||||
mobj = re.match(self._make_valid_url(), query)
|
prefix, query = self._match_valid_url(query).group('prefix', 'query')
|
||||||
if mobj is None:
|
|
||||||
raise ExtractorError('Invalid search query "%s"' % query)
|
|
||||||
|
|
||||||
prefix = mobj.group('prefix')
|
|
||||||
query = mobj.group('query')
|
|
||||||
if prefix == '':
|
if prefix == '':
|
||||||
return self._get_n_results(query, 1)
|
return self._get_n_results(query, 1)
|
||||||
elif prefix == 'all':
|
elif prefix == 'all':
|
||||||
|
|
Loading…
Reference in New Issue