2014-02-19 00:06:16 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import ExtractorError
|
|
|
|
|
|
|
|
|
|
|
|
class TestURLIE(InfoExtractor):
|
2016-01-10 15:17:47 +00:00
|
|
|
""" Allows addressing of the test cases as test:yout.*be_1 """
|
2014-02-19 00:06:16 +00:00
|
|
|
|
|
|
|
IE_DESC = False # Do not list
|
2022-08-24 09:40:21 +00:00
|
|
|
_VALID_URL = r'test(?:url)?:(?P<extractor>.*?)(?:_(?P<num>[0-9]+))?$'
|
2014-02-19 00:06:16 +00:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2022-04-17 17:18:50 +00:00
|
|
|
from . import gen_extractor_classes
|
2014-02-19 00:06:16 +00:00
|
|
|
|
2022-05-11 15:54:44 +00:00
|
|
|
extractor_id, num = self._match_valid_url(url).group('extractor', 'num')
|
2022-08-24 09:40:21 +00:00
|
|
|
if not extractor_id:
|
|
|
|
return {'id': ':test', 'title': '', 'url': url}
|
2014-02-19 00:06:16 +00:00
|
|
|
|
|
|
|
rex = re.compile(extractor_id, flags=re.IGNORECASE)
|
2022-05-11 15:54:44 +00:00
|
|
|
matching_extractors = [e for e in gen_extractor_classes() if rex.search(e.IE_NAME)]
|
2014-02-19 00:06:16 +00:00
|
|
|
|
|
|
|
if len(matching_extractors) == 0:
|
2022-11-11 03:13:08 +00:00
|
|
|
raise ExtractorError(f'No extractors matching {extractor_id!r} found', expected=True)
|
2014-02-19 00:06:16 +00:00
|
|
|
elif len(matching_extractors) > 1:
|
2023-01-02 04:55:11 +00:00
|
|
|
extractor = next(( # Check for exact match
|
|
|
|
ie for ie in matching_extractors if ie.IE_NAME.lower() == extractor_id.lower()
|
|
|
|
), None) or next(( # Check for exact match without plugin suffix
|
|
|
|
ie for ie in matching_extractors if ie.IE_NAME.split('+')[0].lower() == extractor_id.lower()
|
|
|
|
), None)
|
|
|
|
if not extractor:
|
2014-02-19 00:06:16 +00:00
|
|
|
raise ExtractorError(
|
2022-05-11 15:54:44 +00:00
|
|
|
'Found multiple matching extractors: %s' % ' '.join(ie.IE_NAME for ie in matching_extractors),
|
2014-02-19 00:06:16 +00:00
|
|
|
expected=True)
|
2014-02-25 09:43:34 +00:00
|
|
|
else:
|
|
|
|
extractor = matching_extractors[0]
|
2014-02-19 00:06:16 +00:00
|
|
|
|
2022-05-11 15:54:44 +00:00
|
|
|
testcases = tuple(extractor.get_testcases(True))
|
2014-02-19 00:06:16 +00:00
|
|
|
try:
|
2022-05-11 15:54:44 +00:00
|
|
|
tc = testcases[int(num or 0)]
|
2014-02-19 00:06:16 +00:00
|
|
|
except IndexError:
|
|
|
|
raise ExtractorError(
|
2022-05-11 15:54:44 +00:00
|
|
|
f'Test case {num or 0} not found, got only {len(testcases)} tests', expected=True)
|
2014-02-19 00:06:16 +00:00
|
|
|
|
2022-05-11 15:54:44 +00:00
|
|
|
self.to_screen(f'Test URL: {tc["url"]}')
|
|
|
|
return self.url_result(tc['url'])
|