]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/once.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / once.py
CommitLineData
0436ec0e 1import re
2
3from .common import InfoExtractor
4
5
6368e2e6 6class OnceIE(InfoExtractor): # XXX: Conventionally, base classes should end with BaseIE/InfoExtractor
782195a9 7 _VALID_URL = r'https?://.+?\.unicornmedia\.com/now/(?:ads/vmap/)?[^/]+/[^/]+/(?P<domain_id>[^/]+)/(?P<application_id>[^/]+)/(?:[^/]+/)?(?P<media_item_id>[^/]+)/content\.(?:once|m3u8|mp4)'
0436ec0e 8 ADAPTIVE_URL_TEMPLATE = 'http://once.unicornmedia.com/now/master/playlist/%s/%s/%s/content.m3u8'
9 PROGRESSIVE_URL_TEMPLATE = 'http://once.unicornmedia.com/now/media/progressive/%s/%s/%s/%s/content.mp4'
10
d4e31b72 11 def _extract_once_formats(self, url, http_formats_preference=None):
0436ec0e 12 domain_id, application_id, media_item_id = re.match(
13 OnceIE._VALID_URL, url).groups()
61870915 14 formats = self._extract_m3u8_formats(
0436ec0e 15 self.ADAPTIVE_URL_TEMPLATE % (
16 domain_id, application_id, media_item_id),
17 media_item_id, 'mp4', m3u8_id='hls', fatal=False)
61870915 18 progressive_formats = []
19 for adaptive_format in formats:
c6ca11f1 20 # Prevent advertisement from embedding into m3u8 playlist (see
067aa17e 21 # https://github.com/ytdl-org/youtube-dl/issues/8893#issuecomment-199912684)
c6ca11f1
S
22 adaptive_format['url'] = re.sub(
23 r'\badsegmentlength=\d+', r'adsegmentlength=0', adaptive_format['url'])
0436ec0e 24 rendition_id = self._search_regex(
25 r'/now/media/playlist/[^/]+/[^/]+/([^/]+)',
26 adaptive_format['url'], 'redition id', default=None)
d4e31b72 27 if rendition_id:
0436ec0e 28 progressive_format = adaptive_format.copy()
29 progressive_format.update({
30 'url': self.PROGRESSIVE_URL_TEMPLATE % (
31 domain_id, application_id, rendition_id, media_item_id),
32 'format_id': adaptive_format['format_id'].replace(
33 'hls', 'http'),
34 'protocol': 'http',
d4e31b72 35 'preference': http_formats_preference,
0436ec0e 36 })
61870915 37 progressive_formats.append(progressive_format)
38 self._check_formats(progressive_formats, media_item_id)
39 formats.extend(progressive_formats)
0436ec0e 40 return formats