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.

65 lines
2.0 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import ExtractorError, compat_urllib_request
  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. mobj = re.match(self._VALID_URL, url)
  20. video_id = mobj.group('id')
  21. request = compat_urllib_request.Request(self._API_URL.format(video_id))
  22. request.add_header('Referer', url) # Some videos require this.
  23. data_json = self._download_json(request, video_id)
  24. if data_json.get('error'):
  25. raise ExtractorError('Error while getting the playlist',
  26. expected=True)
  27. data = data_json['media']
  28. formats = []
  29. thumbnails = []
  30. for atype, a in data['assets'].items():
  31. if atype == 'still':
  32. thumbnails.append({
  33. 'url': a['url'],
  34. 'resolution': '%dx%d' % (a['width'], a['height']),
  35. })
  36. continue
  37. if atype == 'preview':
  38. continue
  39. formats.append({
  40. 'format_id': atype,
  41. 'url': a['url'],
  42. 'width': a['width'],
  43. 'height': a['height'],
  44. 'filesize': a['size'],
  45. 'ext': a['ext'],
  46. 'preference': 1 if atype == 'original' else None,
  47. })
  48. self._sort_formats(formats)
  49. return {
  50. 'id': video_id,
  51. 'title': data['name'],
  52. 'formats': formats,
  53. 'thumbnails': thumbnails,
  54. 'duration': data.get('duration'),
  55. }