Merge pull request #8611 from remitamine/ffmpegfd
[youtube-dl] / youtube_dl / extractor / wistia.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     ExtractorError,
6     sanitized_Request,
7 )
8
9
10 class WistiaIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)'
12     _API_URL = 'http://fast.wistia.com/embed/medias/{0:}.json'
13
14     _TEST = {
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,
22         },
23     }
24
25     def _real_extract(self, url):
26         video_id = self._match_id(url)
27
28         request = sanitized_Request(self._API_URL.format(video_id))
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']
35
36         formats = []
37         thumbnails = []
38         for a in data['assets']:
39             atype = a.get('type')
40             if atype == 'still':
41                 thumbnails.append({
42                     'url': a['url'],
43                     'resolution': '%dx%d' % (a['width'], a['height']),
44                 })
45                 continue
46             if atype == 'preview':
47                 continue
48             formats.append({
49                 'format_id': atype,
50                 'url': a['url'],
51                 'width': a['width'],
52                 'height': a['height'],
53                 'filesize': a['size'],
54                 'ext': a['ext'],
55                 'preference': 1 if atype == 'original' else None,
56             })
57
58         self._sort_formats(formats)
59
60         return {
61             'id': video_id,
62             'title': data['name'],
63             'formats': formats,
64             'thumbnails': thumbnails,
65             'duration': data.get('duration'),
66         }