From 84d5d1e96e793ac444487cbc2b9138ba456daa6b Mon Sep 17 00:00:00 2001 From: Tithen-Firion Date: Mon, 10 Apr 2017 06:03:54 +0200 Subject: [PATCH 1/2] [openload] switch to pairing method --- youtube_dl/extractor/openload.py | 75 +++++++++++++------------------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/youtube_dl/extractor/openload.py b/youtube_dl/extractor/openload.py index d8036b54a..b8ac56298 100644 --- a/youtube_dl/extractor/openload.py +++ b/youtube_dl/extractor/openload.py @@ -58,6 +58,12 @@ class OpenloadIE(InfoExtractor): 'only_matching': True, }] + _API_URL = 'https://api.openload.co/1' + _PAIR_INFO_URL = _API_URL + '/streaming/info' + _GET_VIDEO_URL = _API_URL + '/streaming/get?file={0}' + + _PAIR_NEEDED = 'Open this url: {0}, solve captcha, click "Pair" button and try again' + @staticmethod def _extract_urls(webpage): return re.findall( @@ -66,60 +72,39 @@ class OpenloadIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) - webpage = self._download_webpage('https://openload.co/embed/%s/' % video_id, video_id) + webpage = self._download_webpage('https://openload.co/embed/{0}/'.format(video_id), video_id) if 'File not found' in webpage or 'deleted by the owner' in webpage: - raise ExtractorError('File not found', expected=True) + raise ExtractorError('File not found', expected=True, video_id=video_id) - ol_id = self._search_regex( - ']+id="[^"]+"[^>]*>([0-9A-Za-z]+)', - webpage, 'openload ID') - - decoded = '' - a = ol_id[0:24] - b = [] - for i in range(0, len(a), 8): - b.append(int(a[i:i + 8] or '0', 16)) - ol_id = ol_id[24:] - j = 0 - k = 0 - while j < len(ol_id): - c = 128 - d = 0 - e = 0 - f = 0 - _more = True - while _more: - if j + 1 >= len(ol_id): - c = 143 - f = int(ol_id[j:j + 2] or '0', 16) - j += 2 - d += (f & 127) << e - e += 7 - _more = f >= c - g = d ^ b[k % 3] - for i in range(4): - char_dec = (g >> 8 * i) & (c + 127) - char = compat_chr(char_dec) - if char != '#': - decoded += char - k += 1 - - video_url = 'https://openload.co/stream/%s?mime=true' - video_url = video_url % decoded - - title = self._og_search_title(webpage, default=None) or self._search_regex( - r']+class=["\']title["\'][^>]*>([^<]+)', webpage, - 'title', default=None) or self._html_search_meta( - 'description', webpage, 'title', fatal=True) + get_info = self._download_json(self._GET_VIDEO_URL.format(video_id), video_id) + status = get_info.get('status') + if status == 200: + result = get_info.get('result', {}) + title = result.get('name') + video_url = result.get('url') + elif status == 403: + pair_info = self._download_json(self._PAIR_INFO_URL, video_id, + note='Downloading pair info') + if pair_info.get('status') == 200: + pair_url = pair_info.get('result', {}).get('auth_url') + if pair_url: + raise ExtractorError(self._PAIR_NEEDED.format(pair_url), expected=True) + else: + raise ExtractorError('Pair URL not found') + else: + raise ExtractorError('Error loading pair info') + else: + raise ExtractorError('Error loading JSON metadata', video_id=video_id) entries = self._parse_html5_media_entries(url, webpage, video_id) - subtitles = entries[0]['subtitles'] if entries else None + entry = entries[0] if entries else {} + subtitles = entry.get('subtitles') info_dict = { 'id': video_id, 'title': title, - 'thumbnail': self._og_search_thumbnail(webpage, default=None), + 'thumbnail': entry.get('thumbnail') or self._og_search_thumbnail(webpage, default=None), 'url': video_url, # Seems all videos have extensions in their titles 'ext': determine_ext(title, 'mp4'), From d5eea9e47caac810472884f402eccc2ae9007f52 Mon Sep 17 00:00:00 2001 From: Tithen-Firion Date: Mon, 10 Apr 2017 10:24:50 +0200 Subject: [PATCH 2/2] [openload] change all test to 'only_matching' --- youtube_dl/extractor/openload.py | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/youtube_dl/extractor/openload.py b/youtube_dl/extractor/openload.py index b8ac56298..b9d0c5086 100644 --- a/youtube_dl/extractor/openload.py +++ b/youtube_dl/extractor/openload.py @@ -16,29 +16,10 @@ class OpenloadIE(InfoExtractor): _TESTS = [{ 'url': 'https://openload.co/f/kUEfGclsU9o', - 'md5': 'bf1c059b004ebc7a256f89408e65c36e', - 'info_dict': { - 'id': 'kUEfGclsU9o', - 'ext': 'mp4', - 'title': 'skyrim_no-audio_1080.mp4', - 'thumbnail': r're:^https?://.*\.jpg$', - }, + 'only_matching': True, }, { 'url': 'https://openload.co/embed/rjC09fkPLYs', - 'info_dict': { - 'id': 'rjC09fkPLYs', - 'ext': 'mp4', - 'title': 'movie.mp4', - 'thumbnail': r're:^https?://.*\.jpg$', - 'subtitles': { - 'en': [{ - 'ext': 'vtt', - }], - }, - }, - 'params': { - 'skip_download': True, # test subtitles only - }, + 'only_matching': True, }, { 'url': 'https://openload.co/embed/kUEfGclsU9o/skyrim_no-audio_1080.mp4', 'only_matching': True,