]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/once.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 class OnceIE(InfoExtractor
):
10 _VALID_URL
= r
'https?://.+?\.unicornmedia\.com/now/(?:ads/vmap/)?[^/]+/[^/]+/(?P<domain_id>[^/]+)/(?P<application_id>[^/]+)/(?:[^/]+/)?(?P<media_item_id>[^/]+)/content\.(?:once|m3u8|mp4)'
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'
14 def _extract_once_formats(self
, url
):
15 domain_id
, application_id
, media_item_id
= re
.match(
16 OnceIE
._VALID
_URL
, url
).groups()
17 formats
= self
._extract
_m
3u8_formats
(
18 self
.ADAPTIVE_URL_TEMPLATE
% (
19 domain_id
, application_id
, media_item_id
),
20 media_item_id
, 'mp4', m3u8_id
='hls', fatal
=False)
21 progressive_formats
= []
22 for adaptive_format
in formats
:
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'])
27 rendition_id
= self
._search
_regex
(
28 r
'/now/media/playlist/[^/]+/[^/]+/([^/]+)',
29 adaptive_format
['url'], 'redition id', default
=None)
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(
39 progressive_formats
.append(progressive_format
)
40 self
._check
_formats
(progressive_formats
, media_item_id
)
41 formats
.extend(progressive_formats
)