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