]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/testurl.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..utils
import ExtractorError
9 class TestURLIE(InfoExtractor
):
10 """ Allows addressing of the test cases as test:yout.*be_1 """
12 IE_DESC
= False # Do not list
13 _VALID_URL
= r
'test(?:url)?:(?P<id>(?P<extractor>.+?)(?:_(?P<num>[0-9]+))?)$'
15 def _real_extract(self
, url
):
16 from ..extractor
import gen_extractors
18 mobj
= re
.match(self
._VALID
_URL
, url
)
19 video_id
= mobj
.group('id')
20 extractor_id
= mobj
.group('extractor')
21 all_extractors
= gen_extractors()
23 rex
= re
.compile(extractor_id
, flags
=re
.IGNORECASE
)
24 matching_extractors
= [
25 e
for e
in all_extractors
if rex
.search(e
.IE_NAME
)]
27 if len(matching_extractors
) == 0:
29 'No extractors matching %r found' % extractor_id
,
31 elif len(matching_extractors
) > 1:
32 # Is it obvious which one to pick?
35 ie
for ie
in matching_extractors
36 if ie
.IE_NAME
.lower() == extractor_id
.lower())
39 ('Found multiple matching extractors: %s' %
40 ' '.join(ie
.IE_NAME
for ie
in matching_extractors
)),
43 extractor
= matching_extractors
[0]
45 num_str
= mobj
.group('num')
46 num
= int(num_str
) if num_str
else 0
49 t
= getattr(extractor
, '_TEST', None)
52 testcases
.extend(getattr(extractor
, '_TESTS', []))
58 ('Test case %d not found, got only %d tests' %
59 (num
, len(testcases
))),
62 self
.to_screen('Test URL: %s' % tc
['url'])