2014-06-24 21:34:39 +09:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2013-12-06 17:15:04 +09:00
|
|
|
from .common import InfoExtractor
|
2015-11-22 01:18:17 +09:00
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
|
|
|
sanitized_Request,
|
|
|
|
)
|
2013-12-06 17:15:04 +09:00
|
|
|
|
|
|
|
|
|
|
|
class WistiaIE(InfoExtractor):
|
2014-06-24 21:34:39 +09:00
|
|
|
_VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)'
|
2014-09-20 09:02:11 +09:00
|
|
|
_API_URL = 'http://fast.wistia.com/embed/medias/{0:}.json'
|
2013-12-06 17:15:04 +09:00
|
|
|
|
|
|
|
_TEST = {
|
2014-06-24 21:34:39 +09: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 17:15:04 +09:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2014-12-13 20:24:42 +09:00
|
|
|
video_id = self._match_id(url)
|
2013-12-06 17:15:04 +09:00
|
|
|
|
2015-11-22 01:18:17 +09:00
|
|
|
request = sanitized_Request(self._API_URL.format(video_id))
|
2014-09-20 09:02:11 +09:00
|
|
|
request.add_header('Referer', url) # Some videos require this.
|
|
|
|
data_json = self._download_json(request, video_id)
|
|
|
|
if data_json.get('error'):
|
|
|
|
raise ExtractorError('Error while getting the playlist',
|
|
|
|
expected=True)
|
|
|
|
data = data_json['media']
|
2013-12-06 17:15:04 +09:00
|
|
|
|
|
|
|
formats = []
|
|
|
|
thumbnails = []
|
2016-03-02 02:26:53 +09:00
|
|
|
for a in data['assets']:
|
|
|
|
atype = a.get('type')
|
2013-12-06 17:15:04 +09:00
|
|
|
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-02 04:23:47 +09:00
|
|
|
'preference': 1 if atype == 'original' else None,
|
2013-12-06 17:15:04 +09:00
|
|
|
})
|
2013-12-25 23:20:14 +09:00
|
|
|
|
|
|
|
self._sort_formats(formats)
|
2013-12-06 17:15:04 +09:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': data['name'],
|
|
|
|
'formats': formats,
|
|
|
|
'thumbnails': thumbnails,
|
2014-06-24 21:34:39 +09:00
|
|
|
'duration': data.get('duration'),
|
2013-12-06 17:15:04 +09:00
|
|
|
}
|