logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

uplynk.py (2625B)


  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(
  29. 'http://content.uplynk.com/%s.m3u8' % path,
  30. display_id, 'mp4', 'm3u8_native')
  31. if session_id:
  32. for f in formats:
  33. f['extra_param_to_segment_url'] = 'pbs=' + session_id
  34. self._sort_formats(formats)
  35. asset = self._download_json('http://content.uplynk.com/player/assetinfo/%s.json' % path, display_id)
  36. if asset.get('error') == 1:
  37. raise ExtractorError('% said: %s' % (self.IE_NAME, asset['msg']), expected=True)
  38. return {
  39. 'id': asset['asset'],
  40. 'title': asset['desc'],
  41. 'thumbnail': asset.get('default_poster_url'),
  42. 'duration': float_or_none(asset.get('duration')),
  43. 'uploader_id': asset.get('owner'),
  44. 'formats': formats,
  45. }
  46. def _real_extract(self, url):
  47. return self._extract_uplynk_info(url)
  48. class UplynkPreplayIE(UplynkIE):
  49. IE_NAME = 'uplynk:preplay'
  50. _VALID_URL = r'https?://.*?\.uplynk\.com/preplay2?/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.json'
  51. _TEST = None
  52. def _real_extract(self, url):
  53. path, external_id, video_id = re.match(self._VALID_URL, url).groups()
  54. display_id = video_id or external_id
  55. preplay = self._download_json(url, display_id)
  56. content_url = 'http://content.uplynk.com/%s.m3u8' % path
  57. session_id = preplay.get('sid')
  58. if session_id:
  59. content_url += '?pbs=' + session_id
  60. return self._extract_uplynk_info(content_url)