diff options
author | Pccode66 <49125134+Pccode66@users.noreply.github.com> | 2021-02-24 15:45:56 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-25 00:15:56 +0530 |
commit | 7a5c1cfe93924351387b44919b3c0b2f66c4b883 (patch) | |
tree | 6da63f3d7b16cf7d4b9fdb29b029125cab8bd0d3 /yt_dlp/extractor/testurl.py | |
parent | c4218ac3f1146daac20308439cdc374e3561101a (diff) | |
download | hypervideo-pre-7a5c1cfe93924351387b44919b3c0b2f66c4b883.tar.lz hypervideo-pre-7a5c1cfe93924351387b44919b3c0b2f66c4b883.tar.xz hypervideo-pre-7a5c1cfe93924351387b44919b3c0b2f66c4b883.zip |
Completely change project name to yt-dlp (#85)
* All modules and binary names are changed
* All documentation references changed
* yt-dlp no longer loads youtube-dlc config files
* All URLs changed to point to organization account
Co-authored-by: Pccode66
Co-authored-by: pukkandan
Diffstat (limited to 'yt_dlp/extractor/testurl.py')
-rw-r--r-- | yt_dlp/extractor/testurl.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/yt_dlp/extractor/testurl.py b/yt_dlp/extractor/testurl.py new file mode 100644 index 000000000..84a14a0bd --- /dev/null +++ b/yt_dlp/extractor/testurl.py @@ -0,0 +1,64 @@ +from __future__ import unicode_literals + +import re + +from .common import InfoExtractor +from ..utils import ExtractorError + + +class TestURLIE(InfoExtractor): + """ Allows addressing of the test cases as test:yout.*be_1 """ + + IE_DESC = False # Do not list + _VALID_URL = r'test(?:url)?:(?P<id>(?P<extractor>.+?)(?:_(?P<num>[0-9]+))?)$' + + def _real_extract(self, url): + from ..extractor import gen_extractors + + mobj = re.match(self._VALID_URL, url) + video_id = mobj.group('id') + extractor_id = mobj.group('extractor') + all_extractors = gen_extractors() + + rex = re.compile(extractor_id, flags=re.IGNORECASE) + matching_extractors = [ + e for e in all_extractors if rex.search(e.IE_NAME)] + + if len(matching_extractors) == 0: + raise ExtractorError( + 'No extractors matching %r found' % extractor_id, + expected=True) + elif len(matching_extractors) > 1: + # Is it obvious which one to pick? + try: + extractor = next( + ie for ie in matching_extractors + if ie.IE_NAME.lower() == extractor_id.lower()) + except StopIteration: + raise ExtractorError( + ('Found multiple matching extractors: %s' % + ' '.join(ie.IE_NAME for ie in matching_extractors)), + expected=True) + else: + extractor = matching_extractors[0] + + num_str = mobj.group('num') + num = int(num_str) if num_str else 0 + + testcases = [] + t = getattr(extractor, '_TEST', None) + if t: + testcases.append(t) + testcases.extend(getattr(extractor, '_TESTS', [])) + + try: + tc = testcases[num] + except IndexError: + raise ExtractorError( + ('Test case %d not found, got only %d tests' % + (num, len(testcases))), + expected=True) + + self.to_screen('Test URL: %s' % tc['url']) + + return self.url_result(tc['url'], video_id=video_id) |