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.

42 lines
2.0 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?://.+?\.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. # Prevent advertisement from embedding into m3u8 playlist (see
  19. # https://github.com/rg3/youtube-dl/issues/8893#issuecomment-199912684)
  20. adaptive_format['url'] = re.sub(
  21. r'\badsegmentlength=\d+', r'adsegmentlength=0', adaptive_format['url'])
  22. rendition_id = self._search_regex(
  23. r'/now/media/playlist/[^/]+/[^/]+/([^/]+)',
  24. adaptive_format['url'], 'redition id', default=None)
  25. if rendition_id:
  26. progressive_format = adaptive_format.copy()
  27. progressive_format.update({
  28. 'url': self.PROGRESSIVE_URL_TEMPLATE % (
  29. domain_id, application_id, rendition_id, media_item_id),
  30. 'format_id': adaptive_format['format_id'].replace(
  31. 'hls', 'http'),
  32. 'protocol': 'http',
  33. })
  34. progressive_formats.append(progressive_format)
  35. self._check_formats(progressive_formats, media_item_id)
  36. formats.extend(progressive_formats)
  37. return formats