]>
Commit | Line | Data |
---|---|---|
a9c7198a PH |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ExtractorError | |
5 | ||
6 | ||
7 | class TestURLIE(InfoExtractor): | |
dfb1b146 | 8 | """ Allows addressing of the test cases as test:yout.*be_1 """ |
a9c7198a PH |
9 | |
10 | IE_DESC = False # Do not list | |
e5458d1d | 11 | _VALID_URL = r'test(?:url)?:(?P<extractor>.*?)(?:_(?P<num>[0-9]+))?$' |
a9c7198a PH |
12 | |
13 | def _real_extract(self, url): | |
c487cf00 | 14 | from . import gen_extractor_classes |
a9c7198a | 15 | |
82d02080 | 16 | extractor_id, num = self._match_valid_url(url).group('extractor', 'num') |
e5458d1d | 17 | if not extractor_id: |
18 | return {'id': ':test', 'title': '', 'url': url} | |
a9c7198a PH |
19 | |
20 | rex = re.compile(extractor_id, flags=re.IGNORECASE) | |
82d02080 | 21 | matching_extractors = [e for e in gen_extractor_classes() if rex.search(e.IE_NAME)] |
a9c7198a PH |
22 | |
23 | if len(matching_extractors) == 0: | |
82d02080 | 24 | raise ExtractorError('No extractors matching {extractor_id!r} found', expected=True) |
a9c7198a | 25 | elif len(matching_extractors) > 1: |
82d02080 | 26 | try: # Check for exact match |
a9c7198a PH |
27 | extractor = next( |
28 | ie for ie in matching_extractors | |
29 | if ie.IE_NAME.lower() == extractor_id.lower()) | |
30 | except StopIteration: | |
31 | raise ExtractorError( | |
82d02080 | 32 | 'Found multiple matching extractors: %s' % ' '.join(ie.IE_NAME for ie in matching_extractors), |
a9c7198a | 33 | expected=True) |
4d756a9c PH |
34 | else: |
35 | extractor = matching_extractors[0] | |
a9c7198a | 36 | |
82d02080 | 37 | testcases = tuple(extractor.get_testcases(True)) |
a9c7198a | 38 | try: |
82d02080 | 39 | tc = testcases[int(num or 0)] |
a9c7198a PH |
40 | except IndexError: |
41 | raise ExtractorError( | |
82d02080 | 42 | f'Test case {num or 0} not found, got only {len(testcases)} tests', expected=True) |
a9c7198a | 43 | |
82d02080 | 44 | self.to_screen(f'Test URL: {tc["url"]}') |
45 | return self.url_result(tc['url']) |