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.

56 lines
1.6 KiB

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