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