]>
Commit | Line | Data |
---|---|---|
6f90d098 PH |
1 | from __future__ import unicode_literals |
2 | ||
15369766 | 3 | from .common import InfoExtractor |
1cc79574 | 4 | from ..compat import ( |
15369766 | 5 | compat_urllib_parse, |
1cc79574 PH |
6 | ) |
7 | from ..utils import ( | |
15369766 | 8 | ExtractorError, |
596ac6e3 | 9 | js_to_json, |
15369766 PH |
10 | ) |
11 | ||
12 | ||
13 | class EscapistIE(InfoExtractor): | |
596ac6e3 | 14 | _VALID_URL = r'https?://?(www\.)?escapistmagazine\.com/videos/view/[^/?#]+/(?P<id>[0-9]+)-[^/?#]*(?:$|[?#])' |
6f5ac90c | 15 | _TEST = { |
6f90d098 PH |
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.", | |
596ac6e3 PH |
22 | 'uploader_id': 'the-escapist-presents', |
23 | 'uploader': 'The Escapist Presents', | |
6f90d098 | 24 | 'title': "Breaking Down Baldur's Gate", |
3da0db62 | 25 | 'thumbnail': 're:^https?://.*\.jpg$', |
6f5ac90c PH |
26 | } |
27 | } | |
15369766 PH |
28 | |
29 | def _real_extract(self, url): | |
596ac6e3 | 30 | video_id = self._match_id(url) |
6f90d098 | 31 | webpage = self._download_webpage(url, video_id) |
15369766 | 32 | |
596ac6e3 | 33 | uploader_id = self._html_search_regex( |
c010af6f | 34 | r"<h1\s+class='headline'>\s*<a\s+href='/videos/view/(.*?)'", |
596ac6e3 PH |
35 | webpage, 'uploader ID', fatal=False) |
36 | uploader = self._html_search_regex( | |
c010af6f | 37 | r"<h1\s+class='headline'>(.*?)</a>", |
596ac6e3 PH |
38 | webpage, 'uploader', fatal=False) |
39 | description = self._html_search_meta('description', webpage) | |
15369766 | 40 | |
596ac6e3 PH |
41 | raw_title = self._html_search_meta('title', webpage, fatal=True) |
42 | title = raw_title.partition(' : ')[2] | |
15369766 | 43 | |
3da0db62 | 44 | config_url = compat_urllib_parse.unquote(self._html_search_regex( |
54233c90 PH |
45 | r'''(?x) |
46 | (?: | |
1c69bca2 | 47 | <param\s+name="flashvars".*?\s+value="config=| |
54233c90 PH |
48 | flashvars="config= |
49 | ) | |
1c69bca2 | 50 | (https?://[^"&]+) |
54233c90 PH |
51 | ''', |
52 | webpage, 'config URL')) | |
15369766 | 53 | |
100959a6 | 54 | formats = [] |
9a48926a | 55 | ad_formats = [] |
15369766 | 56 | |
6f90d098 PH |
57 | def _add_format(name, cfgurl, quality): |
58 | config = self._download_json( | |
59 | cfgurl, video_id, | |
60 | 'Downloading ' + name + ' configuration', | |
61 | 'Unable to download ' + name + ' configuration', | |
596ac6e3 | 62 | transform_source=js_to_json) |
15369766 | 63 | |
100959a6 | 64 | playlist = config['playlist'] |
9a48926a PH |
65 | for p in playlist: |
66 | if p.get('eventCategory') == 'Video': | |
67 | ar = formats | |
68 | elif p.get('eventCategory') == 'Video Postroll': | |
69 | ar = ad_formats | |
70 | else: | |
71 | continue | |
72 | ||
73 | ar.append({ | |
74 | 'url': p['url'], | |
75 | 'format_id': name, | |
76 | 'quality': quality, | |
77 | }) | |
15369766 | 78 | |
596ac6e3 PH |
79 | _add_format('normal', config_url, quality=0) |
80 | hq_url = (config_url + | |
81 | ('&hq=1' if '?' in config_url else config_url + '?hq=1')) | |
100959a6 | 82 | try: |
6f90d098 | 83 | _add_format('hq', hq_url, quality=1) |
15ff3c83 PH |
84 | except ExtractorError: |
85 | pass # That's fine, we'll just use normal quality | |
6f90d098 PH |
86 | self._sort_formats(formats) |
87 | ||
9a48926a | 88 | res = { |
6f90d098 | 89 | 'id': video_id, |
100959a6 | 90 | 'formats': formats, |
596ac6e3 PH |
91 | 'uploader': uploader, |
92 | 'uploader_id': uploader_id, | |
15369766 | 93 | 'title': title, |
46720279 | 94 | 'thumbnail': self._og_search_thumbnail(webpage), |
596ac6e3 | 95 | 'description': description, |
15369766 | 96 | } |
9a48926a PH |
97 | |
98 | if self._downloader.params.get('include_ads') and ad_formats: | |
99 | self._sort_formats(ad_formats) | |
100 | ad_res = { | |
101 | 'id': '%s-ad' % video_id, | |
102 | 'title': '%s (Postroll)' % title, | |
103 | 'formats': ad_formats, | |
104 | } | |
105 | return { | |
106 | '_type': 'playlist', | |
107 | 'entries': [res, ad_res], | |
108 | 'title': title, | |
109 | 'id': video_id, | |
110 | } | |
111 | ||
112 | return res |