wistia.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. sanitized_Request,
  6. )
  7. class WistiaIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)'
  9. _API_URL = 'http://fast.wistia.com/embed/medias/{0:}.json'
  10. _TEST = {
  11. 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
  12. 'md5': 'cafeb56ec0c53c18c97405eecb3133df',
  13. 'info_dict': {
  14. 'id': 'sh7fpupwlt',
  15. 'ext': 'mov',
  16. 'title': 'Being Resourceful',
  17. 'duration': 117,
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. request = sanitized_Request(self._API_URL.format(video_id))
  23. request.add_header('Referer', url) # Some videos require this.
  24. data_json = self._download_json(request, video_id)
  25. if data_json.get('error'):
  26. raise ExtractorError('Error while getting the playlist',
  27. expected=True)
  28. data = data_json['media']
  29. formats = []
  30. thumbnails = []
  31. for a in data['assets']:
  32. atype = a.get('type')
  33. if atype == 'still':
  34. thumbnails.append({
  35. 'url': a['url'],
  36. 'resolution': '%dx%d' % (a['width'], a['height']),
  37. })
  38. continue
  39. if atype == 'preview':
  40. continue
  41. formats.append({
  42. 'format_id': atype,
  43. 'url': a['url'],
  44. 'width': a['width'],
  45. 'height': a['height'],
  46. 'filesize': a['size'],
  47. 'ext': a['ext'],
  48. 'preference': 1 if atype == 'original' else None,
  49. })
  50. self._sort_formats(formats)
  51. return {
  52. 'id': video_id,
  53. 'title': data['name'],
  54. 'formats': formats,
  55. 'thumbnails': thumbnails,
  56. 'duration': data.get('duration'),
  57. }