]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/escapist.py
[escapist] Modernize
[yt-dlp.git] / youtube_dl / extractor / escapist.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import (
5 compat_urllib_parse,
6 )
7 from ..utils import (
8 ExtractorError,
9 js_to_json,
10 )
11
12
13 class EscapistIE(InfoExtractor):
14 _VALID_URL = r'https?://?(www\.)?escapistmagazine\.com/videos/view/[^/?#]+/(?P<id>[0-9]+)-[^/?#]*(?:$|[?#])'
15 _TEST = {
16 'url': 'http://www.escapistmagazine.com/videos/view/the-escapist-presents/6618-Breaking-Down-Baldurs-Gate',
17 'md5': 'ab3a706c681efca53f0a35f1415cf0d1',
18 'info_dict': {
19 'id': '6618',
20 'ext': 'mp4',
21 '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.",
22 'uploader_id': 'the-escapist-presents',
23 'uploader': 'The Escapist Presents',
24 'title': "Breaking Down Baldur's Gate",
25 }
26 }
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30 webpage = self._download_webpage(url, video_id)
31
32 uploader_id = self._html_search_regex(
33 r"<h1 class='headline'><a href='/videos/view/(.*?)'",
34 webpage, 'uploader ID', fatal=False)
35 uploader = self._html_search_regex(
36 r"<h1 class='headline'>(.*?)</a>",
37 webpage, 'uploader', fatal=False)
38 description = self._html_search_meta('description', webpage)
39
40 raw_title = self._html_search_meta('title', webpage, fatal=True)
41 title = raw_title.partition(' : ')[2]
42
43 player_url = self._og_search_video_url(webpage, name='player URL')
44 config_url = compat_urllib_parse.unquote(self._search_regex(
45 r'config=(.*)$', player_url, 'config URL'))
46
47 formats = []
48
49 def _add_format(name, cfgurl, quality):
50 config = self._download_json(
51 cfgurl, video_id,
52 'Downloading ' + name + ' configuration',
53 'Unable to download ' + name + ' configuration',
54 transform_source=js_to_json)
55
56 playlist = config['playlist']
57 formats.append({
58 'url': playlist[1]['url'],
59 'format_id': name,
60 'quality': quality,
61 })
62
63 _add_format('normal', config_url, quality=0)
64 hq_url = (config_url +
65 ('&hq=1' if '?' in config_url else config_url + '?hq=1'))
66 try:
67 _add_format('hq', hq_url, quality=1)
68 except ExtractorError:
69 pass # That's fine, we'll just use normal quality
70
71 self._sort_formats(formats)
72
73 return {
74 'id': video_id,
75 'formats': formats,
76 'uploader': uploader,
77 'uploader_id': uploader_id,
78 'title': title,
79 'thumbnail': self._og_search_thumbnail(webpage),
80 'description': description,
81 'player_url': player_url,
82 }