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