]>
Commit | Line | Data |
---|---|---|
15369766 PH |
1 | import json |
2 | import re | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | compat_str, | |
7 | compat_urllib_parse, | |
8 | ||
9 | ExtractorError, | |
10 | ) | |
11 | ||
12 | ||
13 | class EscapistIE(InfoExtractor): | |
100959a6 | 14 | _VALID_URL = r'^https?://?(www\.)?escapistmagazine\.com/videos/view/(?P<showname>[^/]+)/(?P<episode>[^/?]+)[/?]?.*$' |
6f5ac90c PH |
15 | _TEST = { |
16 | u'url': u'http://www.escapistmagazine.com/videos/view/the-escapist-presents/6618-Breaking-Down-Baldurs-Gate', | |
17 | u'file': u'6618-Breaking-Down-Baldurs-Gate.mp4', | |
100959a6 | 18 | u'md5': u'ab3a706c681efca53f0a35f1415cf0d1', |
6f5ac90c PH |
19 | u'info_dict': { |
20 | u"description": u"Baldur's Gate: Original, Modded or Enhanced Edition? I'll break down what you can expect from the new Baldur's Gate: Enhanced Edition.", | |
21 | u"uploader": u"the-escapist-presents", | |
22 | u"title": u"Breaking Down Baldur's Gate" | |
23 | } | |
24 | } | |
15369766 PH |
25 | |
26 | def _real_extract(self, url): | |
27 | mobj = re.match(self._VALID_URL, url) | |
15369766 PH |
28 | showName = mobj.group('showname') |
29 | videoId = mobj.group('episode') | |
30 | ||
31 | self.report_extraction(videoId) | |
32 | webpage = self._download_webpage(url, videoId) | |
33 | ||
100959a6 PH |
34 | videoDesc = self._html_search_regex( |
35 | r'<meta name="description" content="([^"]*)"', | |
15369766 PH |
36 | webpage, u'description', fatal=False) |
37 | ||
da6a795f | 38 | playerUrl = self._og_search_video_url(webpage, name=u'player URL') |
15369766 | 39 | |
100959a6 | 40 | title = self._html_search_regex( |
da6a795f PH |
41 | r'<meta name="title" content="([^"]*)"', |
42 | webpage, u'title').split(' : ')[-1] | |
15369766 | 43 | |
c5edcde2 | 44 | configUrl = self._search_regex('config=(.*)$', playerUrl, u'config URL') |
15369766 PH |
45 | configUrl = compat_urllib_parse.unquote(configUrl) |
46 | ||
100959a6 | 47 | formats = [] |
15369766 | 48 | |
100959a6 PH |
49 | def _add_format(name, cfgurl): |
50 | configJSON = self._download_webpage( | |
51 | cfgurl, videoId, | |
52 | u'Downloading ' + name + ' configuration', | |
53 | u'Unable to download ' + name + ' configuration') | |
15369766 | 54 | |
100959a6 PH |
55 | # Technically, it's JavaScript, not JSON |
56 | configJSON = configJSON.replace("'", '"') | |
15369766 | 57 | |
100959a6 PH |
58 | try: |
59 | config = json.loads(configJSON) | |
60 | except (ValueError,) as err: | |
61 | raise ExtractorError(u'Invalid JSON in configuration file: ' + compat_str(err)) | |
62 | playlist = config['playlist'] | |
63 | formats.append({ | |
64 | 'url': playlist[1]['url'], | |
65 | 'format_id': name, | |
66 | }) | |
15369766 | 67 | |
100959a6 | 68 | _add_format(u'normal', configUrl) |
15ff3c83 PH |
69 | hq_url = (configUrl + |
70 | ('&hq=1' if '?' in configUrl else configUrl + '?hq=1')) | |
100959a6 | 71 | try: |
15ff3c83 PH |
72 | _add_format(u'hq', hq_url) |
73 | except ExtractorError: | |
74 | pass # That's fine, we'll just use normal quality | |
100959a6 PH |
75 | |
76 | return { | |
15369766 | 77 | 'id': videoId, |
100959a6 | 78 | 'formats': formats, |
15369766 | 79 | 'uploader': showName, |
15369766 | 80 | 'title': title, |
46720279 | 81 | 'thumbnail': self._og_search_thumbnail(webpage), |
15369766 PH |
82 | 'description': videoDesc, |
83 | 'player_url': playerUrl, | |
84 | } |