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