]>
Commit | Line | Data |
---|---|---|
6f90d098 PH |
1 | from __future__ import unicode_literals |
2 | ||
e2dc351d | 3 | import json |
4 | ||
15369766 | 5 | from .common import InfoExtractor |
1cc79574 | 6 | from ..utils import ( |
e2dc351d | 7 | determine_ext, |
8 | clean_html, | |
71fa56b8 | 9 | int_or_none, |
782e0568 | 10 | float_or_none, |
5c2266df | 11 | sanitized_Request, |
15369766 PH |
12 | ) |
13 | ||
14 | ||
e2dc351d | 15 | def _decrypt_config(key, string): |
16 | a = '' | |
17 | i = '' | |
18 | r = '' | |
19 | ||
20 | while len(a) < (len(string) / 2): | |
21 | a += key | |
22 | ||
23 | a = a[0:int(len(string) / 2)] | |
24 | ||
25 | t = 0 | |
26 | while t < len(string): | |
27 | i += chr(int(string[t] + string[t + 1], 16)) | |
28 | t += 2 | |
29 | ||
30 | icko = [s for s in i] | |
31 | ||
32 | for t, c in enumerate(a): | |
33 | r += chr(ord(c) ^ ord(icko[t])) | |
34 | ||
35 | return r | |
36 | ||
37 | ||
15369766 | 38 | class EscapistIE(InfoExtractor): |
90b4b0ea | 39 | _VALID_URL = r'https?://?(?:www\.)?escapistmagazine\.com/videos/view/[^/?#]+/(?P<id>[0-9]+)-[^/?#]*(?:$|[?#])' |
e2dc351d | 40 | _TESTS = [{ |
6f90d098 | 41 | 'url': 'http://www.escapistmagazine.com/videos/view/the-escapist-presents/6618-Breaking-Down-Baldurs-Gate', |
cec04ef3 | 42 | 'md5': 'ab3a706c681efca53f0a35f1415cf0d1', |
6f90d098 PH |
43 | 'info_dict': { |
44 | 'id': '6618', | |
45 | 'ext': 'mp4', | |
46 | 'description': "Baldur's Gate: Original, Modded or Enhanced Edition? I'll break down what you can expect from the new Baldur's Gate: Enhanced Edition.", | |
6f90d098 | 47 | 'title': "Breaking Down Baldur's Gate", |
3da0db62 | 48 | 'thumbnail': 're:^https?://.*\.jpg$', |
8237bec4 | 49 | 'duration': 264, |
b2f82360 | 50 | 'uploader': 'The Escapist', |
6f5ac90c | 51 | } |
e2dc351d | 52 | }, { |
53 | 'url': 'http://www.escapistmagazine.com/videos/view/zero-punctuation/10044-Evolve-One-vs-Multiplayer', | |
cec04ef3 | 54 | 'md5': '9e8c437b0dbb0387d3bd3255ca77f6bf', |
e2dc351d | 55 | 'info_dict': { |
56 | 'id': '10044', | |
57 | 'ext': 'mp4', | |
58 | 'description': 'This week, Zero Punctuation reviews Evolve.', | |
59 | 'title': 'Evolve - One vs Multiplayer', | |
60 | 'thumbnail': 're:^https?://.*\.jpg$', | |
61 | 'duration': 304, | |
b2f82360 | 62 | 'uploader': 'The Escapist', |
e2dc351d | 63 | } |
64 | }] | |
15369766 PH |
65 | |
66 | def _real_extract(self, url): | |
596ac6e3 | 67 | video_id = self._match_id(url) |
e2dc351d | 68 | webpage = self._download_webpage(url, video_id) |
69 | ||
782e0568 | 70 | ims_video = self._parse_json( |
290a5a8d S |
71 | self._search_regex( |
72 | r'imsVideo\.play\(({.+?})\);', webpage, 'imsVideo'), | |
73 | video_id) | |
782e0568 S |
74 | video_id = ims_video['videoID'] |
75 | key = ims_video['hash'] | |
e2dc351d | 76 | |
5c2266df | 77 | config_req = sanitized_Request( |
71fa56b8 S |
78 | 'http://www.escapistmagazine.com/videos/' |
79 | 'vidconfig.php?videoID=%s&hash=%s' % (video_id, key)) | |
80 | config_req.add_header('Referer', url) | |
81 | config = self._download_webpage(config_req, video_id, 'Downloading video config') | |
15369766 | 82 | |
71fa56b8 | 83 | data = json.loads(_decrypt_config(key, config)) |
e2dc351d | 84 | |
782e0568 S |
85 | video_data = data['videoData'] |
86 | ||
87 | title = clean_html(video_data['title']) | |
88 | duration = float_or_none(video_data.get('duration'), 1000) | |
89 | uploader = video_data.get('publisher') | |
e2dc351d | 90 | |
71fa56b8 S |
91 | formats = [{ |
92 | 'url': video['src'], | |
93 | 'format_id': '%s-%sp' % (determine_ext(video['src']), video['res']), | |
94 | 'height': int_or_none(video.get('res')), | |
95 | } for video in data['files']['videos']] | |
96 | self._sort_formats(formats) | |
e2dc351d | 97 | |
98 | return { | |
6f90d098 | 99 | 'id': video_id, |
100959a6 | 100 | 'formats': formats, |
15369766 | 101 | 'title': title, |
46720279 | 102 | 'thumbnail': self._og_search_thumbnail(webpage), |
e2dc351d | 103 | 'description': self._og_search_description(webpage), |
8237bec4 | 104 | 'duration': duration, |
782e0568 | 105 | 'uploader': uploader, |
15369766 | 106 | } |