]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/wistia.py
debian/changelog: Start new release.
[youtubedl] / youtube_dl / extractor / wistia.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7
8
9 class WistiaIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)'
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 mobj = re.match(self._VALID_URL, url)
25 video_id = mobj.group('id')
26
27 webpage = self._download_webpage(url, video_id)
28 data_json = self._html_search_regex(
29 r'Wistia\.iframeInit\((.*?), {}\);', webpage, 'video data')
30
31 data = json.loads(data_json)
32
33 formats = []
34 thumbnails = []
35 for atype, a in data['assets'].items():
36 if atype == 'still':
37 thumbnails.append({
38 'url': a['url'],
39 'resolution': '%dx%d' % (a['width'], a['height']),
40 })
41 continue
42 if atype == 'preview':
43 continue
44 formats.append({
45 'format_id': atype,
46 'url': a['url'],
47 'width': a['width'],
48 'height': a['height'],
49 'filesize': a['size'],
50 'ext': a['ext'],
51 'preference': 1 if atype == 'original' else None,
52 })
53
54 self._sort_formats(formats)
55
56 return {
57 'id': video_id,
58 'title': data['name'],
59 'formats': formats,
60 'thumbnails': thumbnails,
61 'duration': data.get('duration'),
62 }