2014-06-24 12:34:39 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2013-12-06 08:15:04 +00:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
|
|
|
|
|
|
|
class WistiaIE(InfoExtractor):
|
2014-06-24 12:34:39 +00:00
|
|
|
_VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)'
|
2013-12-06 08:15:04 +00:00
|
|
|
|
|
|
|
_TEST = {
|
2014-06-24 12:34:39 +00:00
|
|
|
'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
|
|
|
|
'md5': 'cafeb56ec0c53c18c97405eecb3133df',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'sh7fpupwlt',
|
|
|
|
'ext': 'mov',
|
|
|
|
'title': 'Being Resourceful',
|
|
|
|
'duration': 117,
|
2013-12-06 08:15:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
video_id = mobj.group('id')
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
data_json = self._html_search_regex(
|
2014-06-24 12:34:39 +00:00
|
|
|
r'Wistia\.iframeInit\((.*?), {}\);', webpage, 'video data')
|
2013-12-06 08:15:04 +00:00
|
|
|
|
|
|
|
data = json.loads(data_json)
|
|
|
|
|
|
|
|
formats = []
|
|
|
|
thumbnails = []
|
|
|
|
for atype, a in data['assets'].items():
|
|
|
|
if atype == 'still':
|
|
|
|
thumbnails.append({
|
|
|
|
'url': a['url'],
|
|
|
|
'resolution': '%dx%d' % (a['width'], a['height']),
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
if atype == 'preview':
|
|
|
|
continue
|
|
|
|
formats.append({
|
|
|
|
'format_id': atype,
|
|
|
|
'url': a['url'],
|
|
|
|
'width': a['width'],
|
|
|
|
'height': a['height'],
|
|
|
|
'filesize': a['size'],
|
|
|
|
'ext': a['ext'],
|
2014-01-01 19:23:47 +00:00
|
|
|
'preference': 1 if atype == 'original' else None,
|
2013-12-06 08:15:04 +00:00
|
|
|
})
|
2013-12-25 14:20:14 +00:00
|
|
|
|
|
|
|
self._sort_formats(formats)
|
2013-12-06 08:15:04 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': data['name'],
|
|
|
|
'formats': formats,
|
|
|
|
'thumbnails': thumbnails,
|
2014-06-24 12:34:39 +00:00
|
|
|
'duration': data.get('duration'),
|
2013-12-06 08:15:04 +00:00
|
|
|
}
|