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