]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/once.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / once.py
1 import re
2
3 from .common import InfoExtractor
4
5
6 class OnceIE(InfoExtractor): # XXX: Conventionally, base classes should end with BaseIE/InfoExtractor
7 _VALID_URL = r'https?://.+?\.unicornmedia\.com/now/(?:ads/vmap/)?[^/]+/[^/]+/(?P<domain_id>[^/]+)/(?P<application_id>[^/]+)/(?:[^/]+/)?(?P<media_item_id>[^/]+)/content\.(?:once|m3u8|mp4)'
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
11 def _extract_once_formats(self, url, http_formats_preference=None):
12 domain_id, application_id, media_item_id = re.match(
13 OnceIE._VALID_URL, url).groups()
14 formats = self._extract_m3u8_formats(
15 self.ADAPTIVE_URL_TEMPLATE % (
16 domain_id, application_id, media_item_id),
17 media_item_id, 'mp4', m3u8_id='hls', fatal=False)
18 progressive_formats = []
19 for adaptive_format in formats:
20 # Prevent advertisement from embedding into m3u8 playlist (see
21 # https://github.com/ytdl-org/youtube-dl/issues/8893#issuecomment-199912684)
22 adaptive_format['url'] = re.sub(
23 r'\badsegmentlength=\d+', r'adsegmentlength=0', adaptive_format['url'])
24 rendition_id = self._search_regex(
25 r'/now/media/playlist/[^/]+/[^/]+/([^/]+)',
26 adaptive_format['url'], 'redition id', default=None)
27 if rendition_id:
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',
35 'preference': http_formats_preference,
36 })
37 progressive_formats.append(progressive_format)
38 self._check_formats(progressive_formats, media_item_id)
39 formats.extend(progressive_formats)
40 return formats