wistia.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. aurl = a.get('url')
  44. if not aurl:
  45. continue
  46. astatus = a.get('status')
  47. atype = a.get('type')
  48. if (astatus is not None and astatus != 2) or atype in ('preview', 'storyboard'):
  49. continue
  50. elif atype in ('still', 'still_image'):
  51. thumbnails.append({
  52. 'url': aurl,
  53. 'width': int_or_none(a.get('width')),
  54. 'height': int_or_none(a.get('height')),
  55. })
  56. else:
  57. formats.append({
  58. 'format_id': atype,
  59. 'url': aurl,
  60. 'tbr': int_or_none(a.get('bitrate')),
  61. 'vbr': int_or_none(a.get('opt_vbitrate')),
  62. 'width': int_or_none(a.get('width')),
  63. 'height': int_or_none(a.get('height')),
  64. 'filesize': int_or_none(a.get('size')),
  65. 'vcodec': a.get('codec'),
  66. 'container': a.get('container'),
  67. 'ext': a.get('ext'),
  68. 'preference': 1 if atype == 'original' else None,
  69. })
  70. self._sort_formats(formats)
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'description': data.get('seoDescription'),
  75. 'formats': formats,
  76. 'thumbnails': thumbnails,
  77. 'duration': int_or_none(data.get('duration')),
  78. 'timestamp': int_or_none(data.get('createdAt')),
  79. }