]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/testurl.py
3 from .common
import InfoExtractor
4 from ..utils
import ExtractorError
7 class TestURLIE(InfoExtractor
):
8 """ Allows addressing of the test cases as test:yout.*be_1 """
10 IE_DESC
= False # Do not list
11 _VALID_URL
= r
'test(?:url)?:(?P<id>(?P<extractor>.+?)(?:_(?P<num>[0-9]+))?)$'
13 def _real_extract(self
, url
):
14 from ..extractor
import gen_extractors
16 mobj
= self
._match
_valid
_url
(url
)
17 video_id
= mobj
.group('id')
18 extractor_id
= mobj
.group('extractor')
19 all_extractors
= gen_extractors()
21 rex
= re
.compile(extractor_id
, flags
=re
.IGNORECASE
)
22 matching_extractors
= [
23 e
for e
in all_extractors
if rex
.search(e
.IE_NAME
)]
25 if len(matching_extractors
) == 0:
27 'No extractors matching %r found' % extractor_id
,
29 elif len(matching_extractors
) > 1:
30 # Is it obvious which one to pick?
33 ie
for ie
in matching_extractors
34 if ie
.IE_NAME
.lower() == extractor_id
.lower())
37 ('Found multiple matching extractors: %s' %
38 ' '.join(ie
.IE_NAME
for ie
in matching_extractors
)),
41 extractor
= matching_extractors
[0]
43 num_str
= mobj
.group('num')
44 num
= int(num_str
) if num_str
else 0
47 t
= getattr(extractor
, '_TEST', None)
50 testcases
.extend(getattr(extractor
, '_TESTS', []))
56 ('Test case %d not found, got only %d tests' %
57 (num
, len(testcases
))),
60 self
.to_screen('Test URL: %s' % tc
['url'])
62 return self
.url_result(tc
['url'], video_id
=video_id
)