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.

68 lines
2.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. float_or_none,
  7. ExtractorError,
  8. )
  9. class UplynkIE(InfoExtractor):
  10. IE_NAME = 'uplynk'
  11. _VALID_URL = r'https?://.*?\.uplynk\.com/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.(?:m3u8|json)(?:.*?\bpbs=(?P<session_id>[^&]+))?'
  12. _TEST = {
  13. 'url': 'http://content.uplynk.com/e89eaf2ce9054aa89d92ddb2d817a52e.m3u8',
  14. 'info_dict': {
  15. 'id': 'e89eaf2ce9054aa89d92ddb2d817a52e',
  16. 'ext': 'mp4',
  17. 'title': '030816-kgo-530pm-solar-eclipse-vid_web.mp4',
  18. 'uploader_id': '4413701bf5a1488db55b767f8ae9d4fa',
  19. },
  20. 'params': {
  21. # m3u8 download
  22. 'skip_download': True,
  23. },
  24. }
  25. def _extract_uplynk_info(self, uplynk_content_url):
  26. path, external_id, video_id, session_id = re.match(UplynkIE._VALID_URL, uplynk_content_url).groups()
  27. display_id = video_id or external_id
  28. formats = self._extract_m3u8_formats('http://content.uplynk.com/%s.m3u8' % path, display_id, 'mp4')
  29. if session_id:
  30. for f in formats:
  31. f['extra_param_to_segment_url'] = 'pbs=' + session_id
  32. self._sort_formats(formats)
  33. asset = self._download_json('http://content.uplynk.com/player/assetinfo/%s.json' % path, display_id)
  34. if asset.get('error') == 1:
  35. raise ExtractorError('% said: %s' % (self.IE_NAME, asset['msg']), expected=True)
  36. return {
  37. 'id': asset['asset'],
  38. 'title': asset['desc'],
  39. 'thumbnail': asset.get('default_poster_url'),
  40. 'duration': float_or_none(asset.get('duration')),
  41. 'uploader_id': asset.get('owner'),
  42. 'formats': formats,
  43. }
  44. def _real_extract(self, url):
  45. return self._extract_uplynk_info(url)
  46. class UplynkPreplayIE(UplynkIE):
  47. IE_NAME = 'uplynk:preplay'
  48. _VALID_URL = r'https?://.*?\.uplynk\.com/preplay2?/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.json'
  49. _TEST = None
  50. def _real_extract(self, url):
  51. path, external_id, video_id = re.match(self._VALID_URL, url).groups()
  52. display_id = video_id or external_id
  53. preplay = self._download_json(url, display_id)
  54. content_url = 'http://content.uplynk.com/%s.m3u8' % path
  55. session_id = preplay.get('sid')
  56. if session_id:
  57. content_url += '?pbs=' + session_id
  58. return self._extract_uplynk_info(content_url)