]>
Commit | Line | Data |
---|---|---|
0436ec0e | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | ||
8 | ||
9 | class OnceIE(InfoExtractor): | |
782195a9 | 10 | _VALID_URL = r'https?://.+?\.unicornmedia\.com/now/(?:ads/vmap/)?[^/]+/[^/]+/(?P<domain_id>[^/]+)/(?P<application_id>[^/]+)/(?:[^/]+/)?(?P<media_item_id>[^/]+)/content\.(?:once|m3u8|mp4)' |
0436ec0e | 11 | ADAPTIVE_URL_TEMPLATE = 'http://once.unicornmedia.com/now/master/playlist/%s/%s/%s/content.m3u8' |
12 | PROGRESSIVE_URL_TEMPLATE = 'http://once.unicornmedia.com/now/media/progressive/%s/%s/%s/%s/content.mp4' | |
13 | ||
d4e31b72 | 14 | def _extract_once_formats(self, url, http_formats_preference=None): |
0436ec0e | 15 | domain_id, application_id, media_item_id = re.match( |
16 | OnceIE._VALID_URL, url).groups() | |
61870915 | 17 | formats = self._extract_m3u8_formats( |
0436ec0e | 18 | self.ADAPTIVE_URL_TEMPLATE % ( |
19 | domain_id, application_id, media_item_id), | |
20 | media_item_id, 'mp4', m3u8_id='hls', fatal=False) | |
61870915 | 21 | progressive_formats = [] |
22 | for adaptive_format in formats: | |
c6ca11f1 S |
23 | # Prevent advertisement from embedding into m3u8 playlist (see |
24 | # https://github.com/rg3/youtube-dl/issues/8893#issuecomment-199912684) | |
25 | adaptive_format['url'] = re.sub( | |
26 | r'\badsegmentlength=\d+', r'adsegmentlength=0', adaptive_format['url']) | |
0436ec0e | 27 | rendition_id = self._search_regex( |
28 | r'/now/media/playlist/[^/]+/[^/]+/([^/]+)', | |
29 | adaptive_format['url'], 'redition id', default=None) | |
d4e31b72 | 30 | if rendition_id: |
0436ec0e | 31 | progressive_format = adaptive_format.copy() |
32 | progressive_format.update({ | |
33 | 'url': self.PROGRESSIVE_URL_TEMPLATE % ( | |
34 | domain_id, application_id, rendition_id, media_item_id), | |
35 | 'format_id': adaptive_format['format_id'].replace( | |
36 | 'hls', 'http'), | |
37 | 'protocol': 'http', | |
d4e31b72 | 38 | 'preference': http_formats_preference, |
0436ec0e | 39 | }) |
61870915 | 40 | progressive_formats.append(progressive_format) |
41 | self._check_formats(progressive_formats, media_item_id) | |
42 | formats.extend(progressive_formats) | |
0436ec0e | 43 | return formats |