]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/openload.py
d8036b54acd8defc75992e912af90a28c99f8d87
[youtubedl] / youtube_dl / extractor / openload.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_chr
8 from ..utils import (
9 determine_ext,
10 ExtractorError,
11 )
12
13
14 class OpenloadIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:openload\.(?:co|io)|oload\.tv)/(?:f|embed)/(?P<id>[a-zA-Z0-9-_]+)'
16
17 _TESTS = [{
18 'url': 'https://openload.co/f/kUEfGclsU9o',
19 'md5': 'bf1c059b004ebc7a256f89408e65c36e',
20 'info_dict': {
21 'id': 'kUEfGclsU9o',
22 'ext': 'mp4',
23 'title': 'skyrim_no-audio_1080.mp4',
24 'thumbnail': r're:^https?://.*\.jpg$',
25 },
26 }, {
27 'url': 'https://openload.co/embed/rjC09fkPLYs',
28 'info_dict': {
29 'id': 'rjC09fkPLYs',
30 'ext': 'mp4',
31 'title': 'movie.mp4',
32 'thumbnail': r're:^https?://.*\.jpg$',
33 'subtitles': {
34 'en': [{
35 'ext': 'vtt',
36 }],
37 },
38 },
39 'params': {
40 'skip_download': True, # test subtitles only
41 },
42 }, {
43 'url': 'https://openload.co/embed/kUEfGclsU9o/skyrim_no-audio_1080.mp4',
44 'only_matching': True,
45 }, {
46 'url': 'https://openload.io/f/ZAn6oz-VZGE/',
47 'only_matching': True,
48 }, {
49 'url': 'https://openload.co/f/_-ztPaZtMhM/',
50 'only_matching': True,
51 }, {
52 # unavailable via https://openload.co/f/Sxz5sADo82g/, different layout
53 # for title and ext
54 'url': 'https://openload.co/embed/Sxz5sADo82g/',
55 'only_matching': True,
56 }, {
57 'url': 'https://oload.tv/embed/KnG-kKZdcfY/',
58 'only_matching': True,
59 }]
60
61 @staticmethod
62 def _extract_urls(webpage):
63 return re.findall(
64 r'<iframe[^>]+src=["\']((?:https?://)?(?:openload\.(?:co|io)|oload\.tv)/embed/[a-zA-Z0-9-_]+)',
65 webpage)
66
67 def _real_extract(self, url):
68 video_id = self._match_id(url)
69 webpage = self._download_webpage('https://openload.co/embed/%s/' % video_id, video_id)
70
71 if 'File not found' in webpage or 'deleted by the owner' in webpage:
72 raise ExtractorError('File not found', expected=True)
73
74 ol_id = self._search_regex(
75 '<span[^>]+id="[^"]+"[^>]*>([0-9A-Za-z]+)</span>',
76 webpage, 'openload ID')
77
78 decoded = ''
79 a = ol_id[0:24]
80 b = []
81 for i in range(0, len(a), 8):
82 b.append(int(a[i:i + 8] or '0', 16))
83 ol_id = ol_id[24:]
84 j = 0
85 k = 0
86 while j < len(ol_id):
87 c = 128
88 d = 0
89 e = 0
90 f = 0
91 _more = True
92 while _more:
93 if j + 1 >= len(ol_id):
94 c = 143
95 f = int(ol_id[j:j + 2] or '0', 16)
96 j += 2
97 d += (f & 127) << e
98 e += 7
99 _more = f >= c
100 g = d ^ b[k % 3]
101 for i in range(4):
102 char_dec = (g >> 8 * i) & (c + 127)
103 char = compat_chr(char_dec)
104 if char != '#':
105 decoded += char
106 k += 1
107
108 video_url = 'https://openload.co/stream/%s?mime=true'
109 video_url = video_url % decoded
110
111 title = self._og_search_title(webpage, default=None) or self._search_regex(
112 r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
113 'title', default=None) or self._html_search_meta(
114 'description', webpage, 'title', fatal=True)
115
116 entries = self._parse_html5_media_entries(url, webpage, video_id)
117 subtitles = entries[0]['subtitles'] if entries else None
118
119 info_dict = {
120 'id': video_id,
121 'title': title,
122 'thumbnail': self._og_search_thumbnail(webpage, default=None),
123 'url': video_url,
124 # Seems all videos have extensions in their titles
125 'ext': determine_ext(title, 'mp4'),
126 'subtitles': subtitles,
127 }
128 return info_dict