wistia.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. )
  7. class WistiaIE(InfoExtractor):
  8. _VALID_URL = r'(?:wistia:|https?://(?:fast\.)?wistia\.net/embed/iframe/)(?P<id>[a-z0-9]+)'
  9. _API_URL = 'http://fast.wistia.com/embed/medias/%s.json'
  10. _IFRAME_URL = 'http://fast.wistia.net/embed/iframe/%s'
  11. _TESTS = [{
  12. 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
  13. 'md5': 'cafeb56ec0c53c18c97405eecb3133df',
  14. 'info_dict': {
  15. 'id': 'sh7fpupwlt',
  16. 'ext': 'mov',
  17. 'title': 'Being Resourceful',
  18. 'description': 'a Clients From Hell Video Series video from worldwidewebhosting',
  19. 'upload_date': '20131204',
  20. 'timestamp': 1386185018,
  21. 'duration': 117,
  22. },
  23. }, {
  24. 'url': 'wistia:sh7fpupwlt',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. data_json = self._download_json(
  30. self._API_URL % video_id, video_id,
  31. # Some videos require this.
  32. headers={
  33. 'Referer': url if url.startswith('http') else self._IFRAME_URL % video_id,
  34. })
  35. if data_json.get('error'):
  36. raise ExtractorError(
  37. 'Error while getting the playlist', expected=True)
  38. data = data_json['media']
  39. title = data['name']
  40. formats = []
  41. thumbnails = []
  42. for a in data['assets']:
  43. astatus = a.get('status')
  44. atype = a.get('type')
  45. if (astatus is not None and astatus != 2) or atype == 'preview':
  46. continue
  47. elif atype in ('still', 'still_image'):
  48. thumbnails.append({
  49. 'url': a['url'],
  50. 'resolution': '%dx%d' % (a['width'], a['height']),
  51. })
  52. else:
  53. formats.append({
  54. 'format_id': atype,
  55. 'url': a['url'],
  56. 'tbr': int_or_none(a.get('bitrate')),
  57. 'vbr': int_or_none(a.get('opt_vbitrate')),
  58. 'width': int_or_none(a.get('width')),
  59. 'height': int_or_none(a.get('height')),
  60. 'filesize': int_or_none(a.get('size')),
  61. 'vcodec': a.get('codec'),
  62. 'container': a.get('container'),
  63. 'ext': a.get('ext'),
  64. 'preference': 1 if atype == 'original' else None,
  65. })
  66. self._sort_formats(formats)
  67. return {
  68. 'id': video_id,
  69. 'title': title,
  70. 'description': data.get('seoDescription'),
  71. 'formats': formats,
  72. 'thumbnails': thumbnails,
  73. 'duration': int_or_none(data.get('duration')),
  74. 'timestamp': int_or_none(data.get('createdAt')),
  75. }