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-05-11 15:54:44 +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')
|
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-05-11 15:54:44 +00:00
|
|
|
raise ExtractorError('No extractors matching {extractor_id!r} found', expected=True)
|
2014-02-19 00:06:16 +00:00
|
|
|
elif len(matching_extractors) > 1:
|
2022-05-11 15:54:44 +00:00
|
|
|
try: # Check for exact match
|
2014-02-19 00:06:16 +00:00
|
|
|
extractor = next(
|
|
|
|
ie for ie in matching_extractors
|
|
|
|
if ie.IE_NAME.lower() == extractor_id.lower())
|
|
|
|
except StopIteration:
|
|
|
|
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'])
|