]>
Commit | Line | Data |
---|---|---|
1 | import random | |
2 | import re | |
3 | import string | |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
7 | ExtractorError, | |
8 | int_or_none, | |
9 | mimetype2ext, | |
10 | parse_codecs, | |
11 | parse_qs, | |
12 | update_url_query, | |
13 | urljoin, | |
14 | xpath_element, | |
15 | xpath_text, | |
16 | ) | |
17 | from ..compat import ( | |
18 | compat_b64decode, | |
19 | compat_ord, | |
20 | compat_struct_pack, | |
21 | ) | |
22 | ||
23 | ||
24 | class VideaIE(InfoExtractor): | |
25 | _VALID_URL = r'''(?x) | |
26 | https?:// | |
27 | videa(?:kid)?\.hu/ | |
28 | (?: | |
29 | videok/(?:[^/]+/)*[^?#&]+-| | |
30 | (?:videojs_)?player\?.*?\bv=| | |
31 | player/v/ | |
32 | ) | |
33 | (?P<id>[^?#&]+) | |
34 | ''' | |
35 | _TESTS = [{ | |
36 | 'url': 'http://videa.hu/videok/allatok/az-orult-kigyasz-285-kigyot-kigyo-8YfIAjxwWGwT8HVQ', | |
37 | 'md5': '97a7af41faeaffd9f1fc864a7c7e7603', | |
38 | 'info_dict': { | |
39 | 'id': '8YfIAjxwWGwT8HVQ', | |
40 | 'ext': 'mp4', | |
41 | 'title': 'Az őrült kígyász 285 kígyót enged szabadon', | |
42 | 'thumbnail': r're:^https?://.*', | |
43 | 'duration': 21, | |
44 | }, | |
45 | }, { | |
46 | 'url': 'http://videa.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH', | |
47 | 'md5': 'd57ccd8812c7fd491d33b1eab8c99975', | |
48 | 'info_dict': { | |
49 | 'id': 'jAHDWfWSJH5XuFhH', | |
50 | 'ext': 'mp4', | |
51 | 'title': 'Supercars előzés', | |
52 | 'thumbnail': r're:^https?://.*', | |
53 | 'duration': 64, | |
54 | }, | |
55 | }, { | |
56 | 'url': 'http://videa.hu/player?v=8YfIAjxwWGwT8HVQ', | |
57 | 'md5': '97a7af41faeaffd9f1fc864a7c7e7603', | |
58 | 'info_dict': { | |
59 | 'id': '8YfIAjxwWGwT8HVQ', | |
60 | 'ext': 'mp4', | |
61 | 'title': 'Az őrült kígyász 285 kígyót enged szabadon', | |
62 | 'thumbnail': r're:^https?://.*', | |
63 | 'duration': 21, | |
64 | }, | |
65 | }, { | |
66 | 'url': 'http://videa.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1', | |
67 | 'only_matching': True, | |
68 | }, { | |
69 | 'url': 'https://videakid.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH', | |
70 | 'only_matching': True, | |
71 | }, { | |
72 | 'url': 'https://videakid.hu/player?v=8YfIAjxwWGwT8HVQ', | |
73 | 'only_matching': True, | |
74 | }, { | |
75 | 'url': 'https://videakid.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1', | |
76 | 'only_matching': True, | |
77 | }] | |
78 | _STATIC_SECRET = 'xHb0ZvME5q8CBcoQi6AngerDu3FGO9fkUlwPmLVY_RTzj2hJIS4NasXWKy1td7p' | |
79 | ||
80 | @staticmethod | |
81 | def _extract_urls(webpage): | |
82 | return [url for _, url in re.findall( | |
83 | r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//videa\.hu/player\?.*?\bv=.+?)\1', | |
84 | webpage)] | |
85 | ||
86 | @staticmethod | |
87 | def rc4(cipher_text, key): | |
88 | res = b'' | |
89 | ||
90 | key_len = len(key) | |
91 | S = list(range(256)) | |
92 | ||
93 | j = 0 | |
94 | for i in range(256): | |
95 | j = (j + S[i] + ord(key[i % key_len])) % 256 | |
96 | S[i], S[j] = S[j], S[i] | |
97 | ||
98 | i = 0 | |
99 | j = 0 | |
100 | for m in range(len(cipher_text)): | |
101 | i = (i + 1) % 256 | |
102 | j = (j + S[i]) % 256 | |
103 | S[i], S[j] = S[j], S[i] | |
104 | k = S[(S[i] + S[j]) % 256] | |
105 | res += compat_struct_pack('B', k ^ compat_ord(cipher_text[m])) | |
106 | ||
107 | return res.decode() | |
108 | ||
109 | def _real_extract(self, url): | |
110 | video_id = self._match_id(url) | |
111 | video_page = self._download_webpage(url, video_id) | |
112 | ||
113 | if 'videa.hu/player' in url: | |
114 | player_url = url | |
115 | player_page = video_page | |
116 | else: | |
117 | player_url = self._search_regex( | |
118 | r'<iframe.*?src="(/player\?[^"]+)"', video_page, 'player url') | |
119 | player_url = urljoin(url, player_url) | |
120 | player_page = self._download_webpage(player_url, video_id) | |
121 | ||
122 | nonce = self._search_regex( | |
123 | r'_xt\s*=\s*"([^"]+)"', player_page, 'nonce') | |
124 | l = nonce[:32] | |
125 | s = nonce[32:] | |
126 | result = '' | |
127 | for i in range(0, 32): | |
128 | result += s[i - (self._STATIC_SECRET.index(l[i]) - 31)] | |
129 | ||
130 | query = parse_qs(player_url) | |
131 | random_seed = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8)) | |
132 | query['_s'] = random_seed | |
133 | query['_t'] = result[:16] | |
134 | ||
135 | b64_info, handle = self._download_webpage_handle( | |
136 | 'http://videa.hu/videaplayer_get_xml.php', video_id, query=query) | |
137 | if b64_info.startswith('<?xml'): | |
138 | info = self._parse_xml(b64_info, video_id) | |
139 | else: | |
140 | key = result[16:] + random_seed + handle.headers['x-videa-xs'] | |
141 | info = self._parse_xml(self.rc4( | |
142 | compat_b64decode(b64_info), key), video_id) | |
143 | ||
144 | video = xpath_element(info, './video', 'video') | |
145 | if video is None: | |
146 | raise ExtractorError(xpath_element( | |
147 | info, './error', fatal=True), expected=True) | |
148 | sources = xpath_element( | |
149 | info, './video_sources', 'sources', fatal=True) | |
150 | hash_values = xpath_element( | |
151 | info, './hash_values', 'hash values', fatal=False) | |
152 | ||
153 | title = xpath_text(video, './title', fatal=True) | |
154 | ||
155 | formats = [] | |
156 | for source in sources.findall('./video_source'): | |
157 | source_url = source.text | |
158 | source_name = source.get('name') | |
159 | source_exp = source.get('exp') | |
160 | if not (source_url and source_name): | |
161 | continue | |
162 | hash_value = ( | |
163 | xpath_text(hash_values, 'hash_value_' + source_name) | |
164 | if hash_values is not None else None) | |
165 | if hash_value and source_exp: | |
166 | source_url = update_url_query(source_url, { | |
167 | 'md5': hash_value, | |
168 | 'expires': source_exp, | |
169 | }) | |
170 | f = parse_codecs(source.get('codecs')) | |
171 | f.update({ | |
172 | 'url': self._proto_relative_url(source_url), | |
173 | 'ext': mimetype2ext(source.get('mimetype')) or 'mp4', | |
174 | 'format_id': source.get('name'), | |
175 | 'width': int_or_none(source.get('width')), | |
176 | 'height': int_or_none(source.get('height')), | |
177 | }) | |
178 | formats.append(f) | |
179 | self._sort_formats(formats) | |
180 | ||
181 | thumbnail = self._proto_relative_url(xpath_text(video, './poster_src')) | |
182 | ||
183 | age_limit = None | |
184 | is_adult = xpath_text(video, './is_adult_content', default=None) | |
185 | if is_adult: | |
186 | age_limit = 18 if is_adult == '1' else 0 | |
187 | ||
188 | return { | |
189 | 'id': video_id, | |
190 | 'title': title, | |
191 | 'thumbnail': thumbnail, | |
192 | 'duration': int_or_none(xpath_text(video, './duration')), | |
193 | 'age_limit': age_limit, | |
194 | 'formats': formats, | |
195 | } |