]>
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, | |
cf45ed78 | 7 | int_or_none, |
5c2266df | 8 | ) |
ef4fd848 PH |
9 | |
10 | ||
11 | class WistiaIE(InfoExtractor): | |
e423e0ba | 12 | _VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)' |
746c67d7 | 13 | _API_URL = 'http://fast.wistia.com/embed/medias/{0:}.json' |
ef4fd848 PH |
14 | |
15 | _TEST = { | |
e423e0ba S |
16 | 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt', |
17 | 'md5': 'cafeb56ec0c53c18c97405eecb3133df', | |
18 | 'info_dict': { | |
19 | 'id': 'sh7fpupwlt', | |
20 | 'ext': 'mov', | |
21 | 'title': 'Being Resourceful', | |
cf45ed78 | 22 | 'description': 'a Clients From Hell Video Series video from worldwidewebhosting', |
23 | 'upload_date': '20131204', | |
24 | 'timestamp': 1386185018, | |
e423e0ba | 25 | 'duration': 117, |
ef4fd848 PH |
26 | }, |
27 | } | |
28 | ||
29 | def _real_extract(self, url): | |
1cc79574 | 30 | video_id = self._match_id(url) |
ef4fd848 | 31 | |
5c2266df | 32 | request = sanitized_Request(self._API_URL.format(video_id)) |
746c67d7 NJ |
33 | request.add_header('Referer', url) # Some videos require this. |
34 | data_json = self._download_json(request, video_id) | |
35 | if data_json.get('error'): | |
36 | raise ExtractorError('Error while getting the playlist', | |
37 | expected=True) | |
38 | data = data_json['media'] | |
cf45ed78 | 39 | title = data['name'] |
ef4fd848 PH |
40 | |
41 | formats = [] | |
42 | thumbnails = [] | |
66ca2cfd | 43 | for a in data['assets']: |
cf45ed78 | 44 | astatus = a.get('status') |
66ca2cfd | 45 | atype = a.get('type') |
cf45ed78 | 46 | if (astatus is not None and astatus != 2) or atype == 'preview': |
47 | continue | |
48 | elif atype in ('still', 'still_image'): | |
ef4fd848 PH |
49 | thumbnails.append({ |
50 | 'url': a['url'], | |
51 | 'resolution': '%dx%d' % (a['width'], a['height']), | |
52 | }) | |
cf45ed78 | 53 | else: |
54 | formats.append({ | |
55 | 'format_id': atype, | |
56 | 'url': a['url'], | |
57 | 'tbr': int_or_none(a.get('bitrate')), | |
58 | 'vbr': int_or_none(a.get('opt_vbitrate')), | |
59 | 'width': int_or_none(a.get('width')), | |
60 | 'height': int_or_none(a.get('height')), | |
61 | 'filesize': int_or_none(a.get('size')), | |
62 | 'vcodec': a.get('codec'), | |
63 | 'container': a.get('container'), | |
64 | 'ext': a.get('ext'), | |
65 | 'preference': 1 if atype == 'original' else None, | |
66 | }) | |
539179f4 PH |
67 | |
68 | self._sort_formats(formats) | |
ef4fd848 PH |
69 | |
70 | return { | |
71 | 'id': video_id, | |
cf45ed78 | 72 | 'title': title, |
73 | 'description': data.get('seoDescription'), | |
ef4fd848 PH |
74 | 'formats': formats, |
75 | 'thumbnails': thumbnails, | |
cf45ed78 | 76 | 'duration': int_or_none(data.get('duration')), |
77 | 'timestamp': int_or_none(data.get('createdAt')), | |
ef4fd848 | 78 | } |