3 from .common
import InfoExtractor
15 class MainStreamingIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:webtools-?)?(?P<host>[A-Za-z0-9-]*\.msvdn\.net)/(?:embed|amp_embed|content)/(?P<id>\w+)'
17 _EMBED_REGEX
= [rf
'<iframe[^>]+?src=["\']?(?P<url>{_VALID_URL})["\']?']
18 IE_DESC
= 'MainStreaming Player'
22 # Live stream offline, has alternative content id
23 'url': 'https://webtools-e18da6642b684f8aa9ae449862783a56.msvdn.net/embed/53EN6GxbWaJC',
26 'title': 'Diretta homepage 2021-12-31 12:00',
28 'live_status': 'was_live',
30 'thumbnail': r
're:https?://[A-Za-z0-9-]*\.msvdn.net/image/\w+/poster',
32 'expected_warnings': [
33 'Ignoring alternative content ID: WDAF1KOWUpH3',
34 'MainStreaming said: Live event is OFFLINE'
36 'skip': 'live stream offline'
39 'url': 'https://webtools-e18da6642b684f8aa9ae449862783a56.msvdn.net/embed/WDAF1KOWUpH3',
42 'title': 'Playlist homepage',
44 'playlist_mincount': 2
47 'url': 'https://webtools-859c1818ed614cc5b0047439470927b0.msvdn.net/embed/tDoFkZD3T1Lw',
50 'title': r
're:Class CNBC Live \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
51 'live_status': 'is_live',
53 'thumbnail': r
're:https?://[A-Za-z0-9-]*\.msvdn.net/image/\w+/poster',
57 'url': 'https://webtools-f5842579ff984c1c98d63b8d789673eb.msvdn.net/embed/EUlZfGWkGpOd?autoPlay=false',
60 'title': 'La Settimana ',
61 'description': '03 Ottobre ore 02:00',
63 'live_status': 'not_live',
64 'thumbnail': r
're:https?://[A-Za-z0-9-]*\.msvdn.net/image/\w+/poster',
68 # video without webtools- prefix
69 'url': 'https://f5842579ff984c1c98d63b8d789673eb.msvdn.net/embed/MfuWmzL2lGkA?autoplay=false&T=1635860445',
72 'title': 'TG Mattina',
73 'description': '06 Ottobre ore 08:00',
75 'live_status': 'not_live',
76 'thumbnail': r
're:https?://[A-Za-z0-9-]*\.msvdn.net/image/\w+/poster',
80 # always-on livestream with DVR
81 'url': 'https://webtools-f5842579ff984c1c98d63b8d789673eb.msvdn.net/embed/HVvPMzy',
84 'title': r
're:^Diretta LaC News24 \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
85 'description': 'canale all news',
86 'live_status': 'is_live',
88 'thumbnail': r
're:https?://[A-Za-z0-9-]*\.msvdn.net/image/\w+/poster',
91 'skip_download': True,
95 'url': 'https://webtools.msvdn.net/embed/MfuWmzL2lGkA',
98 'url': 'https://859c1818ed614cc5b0047439470927b0.msvdn.net/amp_embed/tDoFkZD3T1Lw',
101 'url': 'https://859c1818ed614cc5b0047439470927b0.msvdn.net/content/tDoFkZD3T1Lw#',
102 'only_matching': True
106 def _playlist_entries(self
, host
, playlist_content
):
107 for entry
in playlist_content
:
108 content_id
= entry
.get('contentID')
111 'ie_key': MainStreamingIE
.ie_key(),
113 'duration': int_or_none(traverse_obj(entry
, ('duration', 'totalSeconds'))),
114 'title': entry
.get('title'),
115 'url': f
'https://{host}/embed/{content_id}'
119 def _get_webtools_host(host
):
120 if not host
.startswith('webtools'):
121 host
= 'webtools' + ('-' if not host
.startswith('.') else '') + host
124 def _get_webtools_base_url(self
, host
):
125 return f
'{self.http_scheme()}//{self._get_webtools_host(host)}'
127 def _call_api(self
, host
: str, path
: str, item_id
: str, query
=None, note
='Downloading API JSON', fatal
=False):
128 # JSON API, does not appear to be documented
129 return self
._call
_webtools
_api
(host
, '/api/v2/' + path
, item_id
, query
, note
, fatal
)
131 def _call_webtools_api(self
, host
: str, path
: str, item_id
: str, query
=None, note
='Downloading webtools API JSON', fatal
=False):
132 # webtools docs: https://webtools.msvdn.net/
133 return self
._download
_json
(
134 urljoin(self
._get
_webtools
_base
_url
(host
), path
), item_id
, query
=query
, note
=note
, fatal
=fatal
)
136 def _real_extract(self
, url
):
137 host
, video_id
= self
._match
_valid
_url
(url
).groups()
138 content_info
= try_get(
140 host
, f
'content/{video_id}', video_id
, note
='Downloading content info API JSON'), lambda x
: x
['playerContentInfo'])
143 webpage
= self
._download
_webpage
(url
, video_id
)
144 player_config
= self
._parse
_json
(
146 r
'config\s*=\s*({.+?})\s*;', webpage
, 'mainstreaming player config',
147 default
='{}', flags
=re
.DOTALL
),
148 video_id
, transform_source
=js_to_json
, fatal
=False) or {}
149 content_info
= player_config
['contentInfo']
151 host
= content_info
.get('host') or host
152 video_id
= content_info
.get('contentID') or video_id
153 title
= content_info
.get('title')
154 description
= traverse_obj(content_info
, 'longDescription', 'shortDescription', expected_type
=str)
155 live_status
= 'not_live'
156 if content_info
.get('drmEnabled'):
157 self
.report_drm(video_id
)
159 alternative_content_id
= content_info
.get('alternativeContentID')
160 if alternative_content_id
:
161 self
.report_warning(f
'Ignoring alternative content ID: {alternative_content_id}')
163 content_type
= int_or_none(content_info
.get('contentType'))
164 format_base_url
= None
168 if content_type
== 20:
169 dvr_enabled
= traverse_obj(content_info
, ('playerSettings', 'dvrEnabled'), expected_type
=bool)
170 format_base_url
= f
"https://{host}/live/{content_info['liveSourceID']}/{video_id}/%s{'?DVR' if dvr_enabled else ''}"
171 live_status
= 'is_live'
172 heartbeat
= self
._call
_api
(host
, f
'heartbeat/{video_id}', video_id
, note
='Checking stream status') or {}
173 if heartbeat
.get('heartBeatUp') is False:
174 self
.raise_no_formats(f
'MainStreaming said: {heartbeat.get("responseMessage")}', expected
=True)
175 live_status
= 'was_live'
178 elif content_type
== 31:
179 return self
.playlist_result(
180 self
._playlist
_entries
(host
, content_info
.get('playlistContents')), video_id
, title
, description
)
181 # Normal video content?
182 elif content_type
== 10:
183 format_base_url
= f
'https://{host}/vod/{video_id}/%s'
185 # Note: in https://webtools.msvdn.net/loader/playerV2.js there is mention of original.mp3 format,
186 # however it seems to be the same as original.mp4?
187 formats
.append({'url': format_base_url
% 'original.mp4', 'format_note': 'original', 'quality': 1})
189 self
.raise_no_formats(f
'Unknown content type {content_type}')
192 m3u8_formats
, m3u8_subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
193 format_base_url
% 'playlist.m3u8', video_id
=video_id
, fatal
=False)
194 mpd_formats
, mpd_subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
195 format_base_url
% 'manifest.mpd', video_id
=video_id
, fatal
=False)
197 subtitles
= self
._merge
_subtitles
(m3u8_subs
, mpd_subs
)
198 formats
.extend(m3u8_formats
+ mpd_formats
)
203 'description': description
,
205 'live_status': live_status
,
206 'duration': parse_duration(content_info
.get('duration')),
207 'tags': content_info
.get('tags'),
208 'subtitles': subtitles
,
209 'thumbnail': urljoin(self
._get
_webtools
_base
_url
(host
), f
'image/{video_id}/poster')