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.

62 lines
1.7 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. class WistiaIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)'
  7. _TEST = {
  8. 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
  9. 'md5': 'cafeb56ec0c53c18c97405eecb3133df',
  10. 'info_dict': {
  11. 'id': 'sh7fpupwlt',
  12. 'ext': 'mov',
  13. 'title': 'Being Resourceful',
  14. 'duration': 117,
  15. },
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. video_id = mobj.group('id')
  20. webpage = self._download_webpage(url, video_id)
  21. data_json = self._html_search_regex(
  22. r'Wistia\.iframeInit\((.*?), {}\);', webpage, 'video data')
  23. data = json.loads(data_json)
  24. formats = []
  25. thumbnails = []
  26. for atype, a in data['assets'].items():
  27. if atype == 'still':
  28. thumbnails.append({
  29. 'url': a['url'],
  30. 'resolution': '%dx%d' % (a['width'], a['height']),
  31. })
  32. continue
  33. if atype == 'preview':
  34. continue
  35. formats.append({
  36. 'format_id': atype,
  37. 'url': a['url'],
  38. 'width': a['width'],
  39. 'height': a['height'],
  40. 'filesize': a['size'],
  41. 'ext': a['ext'],
  42. 'preference': 1 if atype == 'original' else None,
  43. })
  44. self._sort_formats(formats)
  45. return {
  46. 'id': video_id,
  47. 'title': data['name'],
  48. 'formats': formats,
  49. 'thumbnails': thumbnails,
  50. 'duration': data.get('duration'),
  51. }