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