You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

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