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