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