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.

38 lines
1.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class OnceIE(InfoExtractor):
  6. _VALID_URL = r'https?://once\.unicornmedia\.com/now/[^/]+/[^/]+/(?P<domain_id>[^/]+)/(?P<application_id>[^/]+)/(?:[^/]+/)?(?P<media_item_id>[^/]+)/content\.(?:once|m3u8|mp4)'
  7. ADAPTIVE_URL_TEMPLATE = 'http://once.unicornmedia.com/now/master/playlist/%s/%s/%s/content.m3u8'
  8. PROGRESSIVE_URL_TEMPLATE = 'http://once.unicornmedia.com/now/media/progressive/%s/%s/%s/%s/content.mp4'
  9. def _extract_once_formats(self, url):
  10. domain_id, application_id, media_item_id = re.match(
  11. OnceIE._VALID_URL, url).groups()
  12. formats = self._extract_m3u8_formats(
  13. self.ADAPTIVE_URL_TEMPLATE % (
  14. domain_id, application_id, media_item_id),
  15. media_item_id, 'mp4', m3u8_id='hls', fatal=False)
  16. progressive_formats = []
  17. for adaptive_format in formats:
  18. rendition_id = self._search_regex(
  19. r'/now/media/playlist/[^/]+/[^/]+/([^/]+)',
  20. adaptive_format['url'], 'redition id', default=None)
  21. if rendition_id:
  22. progressive_format = adaptive_format.copy()
  23. progressive_format.update({
  24. 'url': self.PROGRESSIVE_URL_TEMPLATE % (
  25. domain_id, application_id, rendition_id, media_item_id),
  26. 'format_id': adaptive_format['format_id'].replace(
  27. 'hls', 'http'),
  28. 'protocol': 'http',
  29. })
  30. progressive_formats.append(progressive_format)
  31. self._check_formats(progressive_formats, media_item_id)
  32. formats.extend(progressive_formats)
  33. return formats