]>
Commit | Line | Data |
---|---|---|
e423e0ba S |
1 | from __future__ import unicode_literals |
2 | ||
ef4fd848 | 3 | from .common import InfoExtractor |
5c2266df S |
4 | from ..utils import ( |
5 | ExtractorError, | |
6 | sanitized_Request, | |
7 | ) | |
ef4fd848 PH |
8 | |
9 | ||
10 | class WistiaIE(InfoExtractor): | |
e423e0ba | 11 | _VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)' |
746c67d7 | 12 | _API_URL = 'http://fast.wistia.com/embed/medias/{0:}.json' |
ef4fd848 PH |
13 | |
14 | _TEST = { | |
e423e0ba S |
15 | 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt', |
16 | 'md5': 'cafeb56ec0c53c18c97405eecb3133df', | |
17 | 'info_dict': { | |
18 | 'id': 'sh7fpupwlt', | |
19 | 'ext': 'mov', | |
20 | 'title': 'Being Resourceful', | |
21 | 'duration': 117, | |
ef4fd848 PH |
22 | }, |
23 | } | |
24 | ||
25 | def _real_extract(self, url): | |
1cc79574 | 26 | video_id = self._match_id(url) |
ef4fd848 | 27 | |
5c2266df | 28 | request = sanitized_Request(self._API_URL.format(video_id)) |
746c67d7 NJ |
29 | request.add_header('Referer', url) # Some videos require this. |
30 | data_json = self._download_json(request, video_id) | |
31 | if data_json.get('error'): | |
32 | raise ExtractorError('Error while getting the playlist', | |
33 | expected=True) | |
34 | data = data_json['media'] | |
ef4fd848 PH |
35 | |
36 | formats = [] | |
37 | thumbnails = [] | |
38 | for atype, a in data['assets'].items(): | |
39 | if atype == 'still': | |
40 | thumbnails.append({ | |
41 | 'url': a['url'], | |
42 | 'resolution': '%dx%d' % (a['width'], a['height']), | |
43 | }) | |
44 | continue | |
45 | if atype == 'preview': | |
46 | continue | |
47 | formats.append({ | |
48 | 'format_id': atype, | |
49 | 'url': a['url'], | |
50 | 'width': a['width'], | |
51 | 'height': a['height'], | |
52 | 'filesize': a['size'], | |
53 | 'ext': a['ext'], | |
08d13955 | 54 | 'preference': 1 if atype == 'original' else None, |
ef4fd848 | 55 | }) |
539179f4 PH |
56 | |
57 | self._sort_formats(formats) | |
ef4fd848 PH |
58 | |
59 | return { | |
60 | 'id': video_id, | |
61 | 'title': data['name'], | |
62 | 'formats': formats, | |
63 | 'thumbnails': thumbnails, | |
e423e0ba | 64 | 'duration': data.get('duration'), |
ef4fd848 | 65 | } |