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