]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/wistia.py
Merge tag 'upstream/2015.11.10'
[youtubedl] / youtube_dl / extractor / wistia.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_urllib_request
5 from ..utils import ExtractorError
6
7
8 class WistiaIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)'
10 _API_URL = 'http://fast.wistia.com/embed/medias/{0:}.json'
11
12 _TEST = {
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,
20 },
21 }
22
23 def _real_extract(self, url):
24 video_id = self._match_id(url)
25
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']
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'],
52 'preference': 1 if atype == 'original' else None,
53 })
54
55 self._sort_formats(formats)
56
57 return {
58 'id': video_id,
59 'title': data['name'],
60 'formats': formats,
61 'thumbnails': thumbnails,
62 'duration': data.get('duration'),
63 }