1 from __future__ import unicode_literals
3 from .common import InfoExtractor
14 class EscapistIE(InfoExtractor):
15 _VALID_URL = r'https?://?(www\.)?escapistmagazine\.com/videos/view/[^/?#]+/(?P<id>[0-9]+)-[^/?#]*(?:$|[?#])'
16 _USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'
18 'url': 'http://www.escapistmagazine.com/videos/view/the-escapist-presents/6618-Breaking-Down-Baldurs-Gate',
19 'md5': 'ab3a706c681efca53f0a35f1415cf0d1',
23 '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.",
24 'uploader_id': 'the-escapist-presents',
25 'uploader': 'The Escapist Presents',
26 'title': "Breaking Down Baldur's Gate",
27 'thumbnail': 're:^https?://.*\.jpg$',
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 webpage_req = compat_urllib_request.Request(url)
34 webpage_req.add_header('User-Agent', self._USER_AGENT)
35 webpage = self._download_webpage(webpage_req, video_id)
37 uploader_id = self._html_search_regex(
38 r"<h1\s+class='headline'>\s*<a\s+href='/videos/view/(.*?)'",
39 webpage, 'uploader ID', fatal=False)
40 uploader = self._html_search_regex(
41 r"<h1\s+class='headline'>(.*?)</a>",
42 webpage, 'uploader', fatal=False)
43 description = self._html_search_meta('description', webpage)
45 raw_title = self._html_search_meta('title', webpage, fatal=True)
46 title = raw_title.partition(' : ')[2]
48 config_url = compat_urllib_parse.unquote(self._html_search_regex(
51 <param\s+name="flashvars".*?\s+value="config=|
52 flashvars="config=
56 webpage, 'config URL'))
61 def _add_format(name, cfg_url, quality):
62 cfg_req = compat_urllib_request.Request(cfg_url)
63 cfg_req.add_header('User-Agent', self._USER_AGENT)
64 config = self._download_json(
66 'Downloading ' + name + ' configuration',
67 'Unable to download ' + name + ' configuration',
68 transform_source=js_to_json)
70 playlist = config['playlist']
72 if p.get('eventCategory') == 'Video':
74 elif p.get('eventCategory') == 'Video Postroll':
84 'User-Agent': self._USER_AGENT,
88 _add_format('normal', config_url, quality=0)
89 hq_url = (config_url +
90 ('&hq=1' if '?' in config_url else config_url + '?hq=1'))
92 _add_format('hq', hq_url, quality=1)
93 except ExtractorError:
94 pass # That's fine, we'll just use normal quality
95 self._sort_formats(formats)
97 if '/escapist/sales-marketing/' in formats[-1]['url']:
98 raise ExtractorError('This IP address has been blocked by The Escapist', expected=True)
103 'uploader': uploader,
104 'uploader_id': uploader_id,
106 'thumbnail': self._og_search_thumbnail(webpage),
107 'description': description,
110 if self._downloader.params.get('include_ads') and ad_formats:
111 self._sort_formats(ad_formats)
113 'id': '%s-ad' % video_id,
114 'title': '%s (Postroll)' % title,
115 'formats': ad_formats,
119 'entries': [res, ad_res],