]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/nbc.py
[extractor/nebula] Add nebula.tv (#4918)
[yt-dlp.git] / yt_dlp / extractor / nbc.py
CommitLineData
58284890 1import base64
1139935d
RA
2import json
3import re
0bc56fa6
JMF
4
5from .common import InfoExtractor
574b2a73 6from .theplatform import ThePlatformIE
fdf9b959 7from .adobepass import AdobePassIE
d0c5fabc 8from ..compat import compat_urllib_parse_unquote
1cc79574 9from ..utils import (
895e5c03 10 int_or_none,
9160a0c6 11 parse_age_limit,
895e5c03 12 parse_duration,
3e376d18 13 RegexNotFoundError,
b46b65ed 14 smuggle_url,
895e5c03
RA
15 try_get,
16 unified_timestamp,
6e416b21 17 update_url_query,
37e64add 18)
0bc56fa6
JMF
19
20
9160a0c6 21class NBCIE(ThePlatformIE):
d673ab65 22 _VALID_URL = r'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>n?\d+))'
58c1f6f0
S
23
24 _TESTS = [
25 {
fdf9b959 26 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237',
58c1f6f0 27 'info_dict': {
fdf9b959 28 'id': '2848237',
e881c4bc 29 'ext': 'mp4',
5c8a3f86
JMF
30 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
31 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
79ba9140 32 'timestamp': 1424246400,
33 'upload_date': '20150218',
34 'uploader': 'NBCU-COM',
58c1f6f0 35 },
e881c4bc
YCH
36 'params': {
37 # m3u8 download
38 'skip_download': True,
39 },
020cf5eb 40 },
b9b3ab45
YCH
41 {
42 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
43 'info_dict': {
e881c4bc
YCH
44 'id': '2832821',
45 'ext': 'mp4',
b9b3ab45
YCH
46 'title': 'Star Wars Teaser',
47 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
79ba9140 48 'timestamp': 1417852800,
49 'upload_date': '20141206',
50 'uploader': 'NBCU-COM',
b9b3ab45 51 },
e881c4bc
YCH
52 'params': {
53 # m3u8 download
54 'skip_download': True,
55 },
b9b3ab45 56 'skip': 'Only works from US',
0fe2ff78 57 },
e6e90515
YCH
58 {
59 # HLS streams requires the 'hdnea3' cookie
60 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
61 'info_dict': {
fdf9b959 62 'id': '101528f5a9e8127b107e98c5e6ce4638',
e6e90515
YCH
63 'ext': 'mp4',
64 'title': 'Goliath',
65 'description': 'When an unknown soldier saves the life of the King\'s son in battle, he\'s thrust into the limelight and politics of the kingdom.',
66 'timestamp': 1237100400,
67 'upload_date': '20090315',
68 'uploader': 'NBCU-COM',
69 },
70 'params': {
71 'skip_download': True,
72 },
73 'skip': 'Only works from US',
d673ab65
L
74 },
75 {
76 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310',
77 'only_matching': True,
78 },
d0c5fabc
T
79 {
80 # Percent escaped url
81 'url': 'https://www.nbc.com/up-all-night/video/day-after-valentine%27s-day/n2189',
82 'only_matching': True,
83 }
58c1f6f0 84 ]
020cf5eb
JMF
85
86 def _real_extract(self, url):
5ad28e7f 87 permalink, video_id = self._match_valid_url(url).groups()
d0c5fabc 88 permalink = 'http' + compat_urllib_parse_unquote(permalink)
48ff5590 89 video_data = self._download_json(
311ee457 90 'https://friendship.nbc.co/v2/graphql', video_id, query={
48ff5590
RA
91 'query': '''query bonanzaPage(
92 $app: NBCUBrands! = nbc
93 $name: String!
94 $oneApp: Boolean
95 $platform: SupportedPlatforms! = web
96 $type: EntityPageType! = VIDEO
97 $userId: String!
98) {
99 bonanzaPage(
100 app: $app
101 name: $name
102 oneApp: $oneApp
103 platform: $platform
104 type: $type
105 userId: $userId
106 ) {
107 metadata {
311ee457
RA
108 ... on VideoPageData {
109 description
110 episodeNumber
111 keywords
112 locked
113 mpxAccountId
114 mpxGuid
115 rating
48ff5590 116 resourceId
311ee457
RA
117 seasonNumber
118 secondaryTitle
119 seriesShortTitle
120 }
121 }
122 }
48ff5590
RA
123}''',
124 'variables': json.dumps({
125 'name': permalink,
126 'oneApp': True,
127 'userId': '0',
128 }),
129 })['data']['bonanzaPage']['metadata']
2eeb588e
RA
130 query = {
131 'mbr': 'true',
132 'manifest': 'm3u',
133 }
311ee457 134 video_id = video_data['mpxGuid']
9160a0c6
TSJ
135 tp_path = 'NnzsPC/media/guid/%s/%s' % (video_data.get('mpxAccountId') or '2410887629', video_id)
136 tpm = self._download_theplatform_metadata(tp_path, video_id)
137 title = tpm.get('title') or video_data.get('secondaryTitle')
311ee457 138 if video_data.get('locked'):
2eeb588e 139 resource = self._get_mvpd_resource(
48ff5590
RA
140 video_data.get('resourceId') or 'nbcentertainment',
141 title, video_id, video_data.get('rating'))
2eeb588e
RA
142 query['auth'] = self._extract_mvpd_auth(
143 url, video_id, 'nbcentertainment', resource)
144 theplatform_url = smuggle_url(update_url_query(
311ee457 145 'http://link.theplatform.com/s/NnzsPC/media/guid/%s/%s' % (video_data.get('mpxAccountId') or '2410887629', video_id),
2eeb588e 146 query), {'force_smil_url': True})
9160a0c6
TSJ
147
148 # Empty string or 0 can be valid values for these. So the check must be `is None`
149 description = video_data.get('description')
150 if description is None:
151 description = tpm.get('description')
152 episode_number = int_or_none(video_data.get('episodeNumber'))
153 if episode_number is None:
154 episode_number = int_or_none(tpm.get('nbcu$airOrder'))
155 rating = video_data.get('rating')
156 if rating is None:
157 try_get(tpm, lambda x: x['ratings'][0]['rating'])
158 season_number = int_or_none(video_data.get('seasonNumber'))
159 if season_number is None:
160 season_number = int_or_none(tpm.get('nbcu$seasonNumber'))
161 series = video_data.get('seriesShortTitle')
162 if series is None:
163 series = tpm.get('nbcu$seriesShortTitle')
164 tags = video_data.get('keywords')
165 if tags is None or len(tags) == 0:
166 tags = tpm.get('keywords')
167
2eeb588e 168 return {
e881c4bc 169 '_type': 'url_transparent',
9160a0c6
TSJ
170 'age_limit': parse_age_limit(rating),
171 'description': description,
172 'episode': title,
173 'episode_number': episode_number,
e881c4bc 174 'id': video_id,
9160a0c6
TSJ
175 'ie_key': 'ThePlatform',
176 'season_number': season_number,
177 'series': series,
178 'tags': tags,
2eeb588e
RA
179 'title': title,
180 'url': theplatform_url,
e881c4bc 181 }
020cf5eb
JMF
182
183
a2a4d5fa 184class NBCSportsVPlayerIE(InfoExtractor):
29f7c58a 185 _VALID_URL_BASE = r'https?://(?:vplayer\.nbcsports\.com|(?:www\.)?nbcsports\.com/vplayer)/'
186 _VALID_URL = _VALID_URL_BASE + r'(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
bfd973ec 187 _EMBED_REGEX = [r'(?:iframe[^>]+|var video|div[^>]+data-(?:mpx-)?)[sS]rc\s?=\s?"(?P<url>%s[^\"]+)' % _VALID_URL_BASE]
a28ccbab 188
5cbb2699 189 _TESTS = [{
12ea5c79 190 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI',
a28ccbab
YCH
191 'info_dict': {
192 'id': '9CsDKds0kvHI',
12ea5c79 193 'ext': 'mp4',
a28ccbab
YCH
194 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
195 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
79ba9140 196 'timestamp': 1426270238,
197 'upload_date': '20150313',
198 'uploader': 'NBCU-SPORTS',
bfa0e270 199 'duration': 72.818,
200 'chapters': [],
201 'thumbnail': r're:^https?://.*\.jpg$'
a28ccbab 202 }
5cbb2699 203 }, {
bfa0e270 204 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/PEgOtlNcC_y2',
5cbb2699 205 'only_matching': True,
29f7c58a 206 }, {
207 'url': 'https://www.nbcsports.com/vplayer/p/BxmELC/nbcsports/select/PHJSaFWbrTY9?form=html&autoPlay=true',
208 'only_matching': True,
5cbb2699 209 }]
a28ccbab
YCH
210
211 def _real_extract(self, url):
212 video_id = self._match_id(url)
213 webpage = self._download_webpage(url, video_id)
bfa0e270 214 theplatform_url = self._html_search_regex(r'tp:releaseUrl="(.+?)"', webpage, 'url')
a28ccbab
YCH
215 return self.url_result(theplatform_url, 'ThePlatform')
216
217
a2a4d5fa 218class NBCSportsIE(InfoExtractor):
29f7c58a 219 _VALID_URL = r'https?://(?:www\.)?nbcsports\.com//?(?!vplayer/)(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
a2a4d5fa 220
29f7c58a 221 _TESTS = [{
222 # iframe src
a2a4d5fa 223 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
a2a4d5fa
YCH
224 'info_dict': {
225 'id': 'PHJSaFWbrTY9',
29f7c58a 226 'ext': 'mp4',
a2a4d5fa
YCH
227 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
228 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
0738187f
YCH
229 'uploader': 'NBCU-SPORTS',
230 'upload_date': '20150330',
231 'timestamp': 1427726529,
bfa0e270 232 'chapters': [],
233 'thumbnail': 'https://hdliveextra-a.akamaihd.net/HD/image_sports/NBCU_Sports_Group_-_nbcsports/253/303/izzodps.jpg',
234 'duration': 528.395,
a2a4d5fa 235 }
29f7c58a 236 }, {
237 # data-mpx-src
238 'url': 'https://www.nbcsports.com/philadelphia/philadelphia-phillies/bruce-bochy-hector-neris-hes-idiot',
239 'only_matching': True,
240 }, {
241 # data-src
242 'url': 'https://www.nbcsports.com/boston/video/report-card-pats-secondary-no-match-josh-allen',
243 'only_matching': True,
244 }]
a2a4d5fa
YCH
245
246 def _real_extract(self, url):
247 video_id = self._match_id(url)
248 webpage = self._download_webpage(url, video_id)
249 return self.url_result(
250 NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
251
252
1139935d
RA
253class NBCSportsStreamIE(AdobePassIE):
254 _VALID_URL = r'https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)'
255 _TEST = {
256 'url': 'http://stream.nbcsports.com/nbcsn/generic?pid=206559',
257 'info_dict': {
258 'id': '206559',
259 'ext': 'mp4',
260 'title': 'Amgen Tour of California Women\'s Recap',
261 'description': 'md5:66520066b3b5281ada7698d0ea2aa894',
262 },
263 'params': {
264 # m3u8 download
265 'skip_download': True,
266 },
267 'skip': 'Requires Adobe Pass Authentication',
268 }
269
270 def _real_extract(self, url):
271 video_id = self._match_id(url)
272 live_source = self._download_json(
273 'http://stream.nbcsports.com/data/live_sources_%s.json' % video_id,
274 video_id)
275 video_source = live_source['videoSources'][0]
276 title = video_source['title']
277 source_url = None
278 for k in ('source', 'msl4source', 'iossource', 'hlsv4'):
279 sk = k + 'Url'
280 source_url = video_source.get(sk) or video_source.get(sk + 'Alt')
281 if source_url:
282 break
283 else:
284 source_url = video_source['ottStreamUrl']
285 is_live = video_source.get('type') == 'live' or video_source.get('status') == 'Live'
286 resource = self._get_mvpd_resource('nbcsports', title, video_id, '')
287 token = self._extract_mvpd_auth(url, video_id, 'nbcsports', resource)
288 tokenized_url = self._download_json(
289 'https://token.playmakerservices.com/cdn',
290 video_id, data=json.dumps({
291 'requestorId': 'nbcsports',
292 'pid': video_id,
293 'application': 'NBCSports',
294 'version': 'v1',
295 'platform': 'desktop',
296 'cdn': 'akamai',
297 'url': video_source['sourceUrl'],
298 'token': base64.b64encode(token.encode()).decode(),
299 'resourceId': base64.b64encode(resource.encode()).decode(),
300 }).encode())['tokenizedUrl']
301 formats = self._extract_m3u8_formats(tokenized_url, video_id, 'mp4')
302 self._sort_formats(formats)
303 return {
304 'id': video_id,
39ca3b5c 305 'title': title,
1139935d
RA
306 'description': live_source.get('description'),
307 'formats': formats,
308 'is_live': is_live,
309 }
310
311
574b2a73 312class NBCNewsIE(ThePlatformIE):
a843464a 313 _VALID_URL = r'(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)'
bfd973ec 314 _EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//www\.nbcnews\.com/widget/video-embed/[^"\']+)\1']
0bc56fa6 315
87fe568c 316 _TESTS = [
87fe568c 317 {
574b2a73 318 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
895e5c03 319 'md5': 'cf4bc9e6ce0130f00f545d80ecedd4bf',
87fe568c 320 'info_dict': {
a843464a 321 'id': '269389891880',
10e3d734 322 'ext': 'mp4',
87fe568c
JMF
323 'title': 'How Twitter Reacted To The Snowden Interview',
324 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
0437307a
RA
325 'timestamp': 1401363060,
326 'upload_date': '20140529',
87fe568c 327 },
87fe568c 328 },
2df54b4b
S
329 {
330 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
331 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
332 'info_dict': {
0437307a 333 'id': '529953347624',
2df54b4b
S
334 'ext': 'mp4',
335 'title': 'FULL EPISODE: Family Business',
336 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
337 },
574b2a73 338 'skip': 'This page is unavailable.',
2df54b4b 339 },
d9aa2b78
RS
340 {
341 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
895e5c03 342 'md5': '8eb831eca25bfa7d25ddd83e85946548',
d9aa2b78 343 'info_dict': {
a843464a 344 'id': '394064451844',
d9aa2b78
RS
345 'ext': 'mp4',
346 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
347 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
0437307a 348 'timestamp': 1423104900,
0437307a 349 'upload_date': '20150205',
d9aa2b78
RS
350 },
351 },
574b2a73 352 {
353 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
895e5c03 354 'md5': '4a8c4cec9e1ded51060bdda36ff0a5c0',
574b2a73 355 'info_dict': {
895e5c03 356 'id': 'n431456',
574b2a73 357 'ext': 'mp4',
895e5c03
RA
358 'title': "Volkswagen U.S. Chief: We 'Totally Screwed Up'",
359 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
0437307a
RA
360 'upload_date': '20150922',
361 'timestamp': 1442917800,
574b2a73 362 },
574b2a73 363 },
cb7d4d0e 364 {
365 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
366 'md5': '118d7ca3f0bea6534f119c68ef539f71',
367 'info_dict': {
a843464a 368 'id': '669831235788',
cb7d4d0e 369 'ext': 'mp4',
370 'title': 'See the aurora borealis from space in stunning new NASA video',
371 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
372 'upload_date': '20160420',
373 'timestamp': 1461152093,
0437307a
RA
374 },
375 },
376 {
377 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
378 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
379 'info_dict': {
a843464a 380 'id': '314487875924',
0437307a
RA
381 'ext': 'mp4',
382 'title': 'The chaotic GOP immigration vote',
383 'description': 'The Republican House votes on a border bill that has no chance of getting through the Senate or signed by the President and is drawing criticism from all sides.',
ec85ded8 384 'thumbnail': r're:^https?://.*\.jpg$',
0437307a
RA
385 'timestamp': 1406937606,
386 'upload_date': '20140802',
cb7d4d0e 387 },
388 },
3f125c8c
S
389 {
390 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
391 'only_matching': True,
392 },
5de008e8
YCH
393 {
394 # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
395 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
396 'only_matching': True,
397 },
87fe568c 398 ]
0bc56fa6
JMF
399
400 def _real_extract(self, url):
a843464a 401 video_id = self._match_id(url)
895e5c03
RA
402 webpage = self._download_webpage(url, video_id)
403
135dfa2c 404 data = self._search_nextjs_data(webpage, video_id)['props']['initialState']
895e5c03
RA
405 video_data = try_get(data, lambda x: x['video']['current'], dict)
406 if not video_data:
407 video_data = data['article']['content'][0]['primaryMedia']['video']
408 title = video_data['headline']['primary']
409
410 formats = []
411 for va in video_data.get('videoAssets', []):
412 public_url = va.get('publicUrl')
413 if not public_url:
414 continue
415 if '://link.theplatform.com/' in public_url:
416 public_url = update_url_query(public_url, {'format': 'redirect'})
417 format_id = va.get('format')
418 if format_id == 'M3U':
419 formats.extend(self._extract_m3u8_formats(
420 public_url, video_id, 'mp4', 'm3u8_native',
421 m3u8_id=format_id, fatal=False))
422 continue
423 tbr = int_or_none(va.get('bitrate'), 1000)
424 if tbr:
425 format_id += '-%d' % tbr
426 formats.append({
427 'format_id': format_id,
428 'url': public_url,
429 'width': int_or_none(va.get('width')),
430 'height': int_or_none(va.get('height')),
431 'tbr': tbr,
432 'ext': 'mp4',
433 })
434 self._sort_formats(formats)
6e416b21 435
895e5c03
RA
436 subtitles = {}
437 closed_captioning = video_data.get('closedCaptioning')
438 if closed_captioning:
439 for cc_url in closed_captioning.values():
440 if not cc_url:
441 continue
442 subtitles.setdefault('en', []).append({
443 'url': cc_url,
444 })
6e416b21 445
a843464a 446 return {
a843464a 447 'id': video_id,
895e5c03
RA
448 'title': title,
449 'description': try_get(video_data, lambda x: x['description']['primary']),
450 'thumbnail': try_get(video_data, lambda x: x['primaryImage']['url']['primary']),
451 'duration': parse_duration(video_data.get('duration')),
452 'timestamp': unified_timestamp(video_data.get('datePublished')),
453 'formats': formats,
454 'subtitles': subtitles,
a843464a 455 }
be457302
YCH
456
457
458class NBCOlympicsIE(InfoExtractor):
58284890 459 IE_NAME = 'nbcolympics'
3e376d18 460 _VALID_URL = r'https?://www\.nbcolympics\.com/videos?/(?P<id>[0-9a-z-]+)'
be457302
YCH
461
462 _TEST = {
463 # Geo-restricted to US
464 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold',
465 'md5': '54fecf846d05429fbaa18af557ee523a',
466 'info_dict': {
467 'id': 'WjTBzDXx5AUq',
468 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold',
469 'ext': 'mp4',
470 'title': 'Rose\'s son Leo was in tears after his dad won gold',
471 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.',
472 'timestamp': 1471274964,
473 'upload_date': '20160815',
474 'uploader': 'NBCU-SPORTS',
475 },
476 }
477
478 def _real_extract(self, url):
479 display_id = self._match_id(url)
480
481 webpage = self._download_webpage(url, display_id)
482
3e376d18
W
483 try:
484 drupal_settings = self._parse_json(self._search_regex(
485 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
486 webpage, 'drupal settings'), display_id)
487
488 iframe_url = drupal_settings['vod']['iframe_url']
489 theplatform_url = iframe_url.replace(
490 'vplayer.nbcolympics.com', 'player.theplatform.com')
491 except RegexNotFoundError:
492 theplatform_url = self._search_regex(
493 r"([\"'])embedUrl\1: *([\"'])(?P<embedUrl>.+)\2",
494 webpage, 'embedding URL', group="embedUrl")
be457302
YCH
495
496 return {
497 '_type': 'url_transparent',
498 'url': theplatform_url,
499 'ie_key': ThePlatformIE.ie_key(),
500 'display_id': display_id,
501 }
58284890
RA
502
503
504class NBCOlympicsStreamIE(AdobePassIE):
505 IE_NAME = 'nbcolympics:stream'
506 _VALID_URL = r'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)'
bb36a55c 507 _TESTS = [
508 {
509 'note': 'Tokenized m3u8 source URL',
510 'url': 'https://stream.nbcolympics.com/womens-soccer-group-round-11',
511 'info_dict': {
512 'id': '2019740',
513 'ext': 'mp4',
514 'title': r"re:Women's Group Stage - Netherlands vs\. Brazil [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$",
515 },
516 'params': {
517 'skip_download': 'm3u8',
518 },
519 }, {
520 'note': 'Plain m3u8 source URL',
521 'url': 'https://stream.nbcolympics.com/gymnastics-event-finals-mens-floor-pommel-horse-womens-vault-bars',
522 'info_dict': {
523 'id': '2021729',
524 'ext': 'mp4',
525 'title': r're:Event Finals: M Floor, W Vault, M Pommel, W Uneven Bars [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
526 },
527 'params': {
528 'skip_download': 'm3u8',
529 },
58284890 530 },
bb36a55c 531 ]
58284890
RA
532
533 def _real_extract(self, url):
534 display_id = self._match_id(url)
535 webpage = self._download_webpage(url, display_id)
536 pid = self._search_regex(r'pid\s*=\s*(\d+);', webpage, 'pid')
bb36a55c 537
58284890 538 event_config = self._download_json(
bb36a55c 539 f'http://stream.nbcolympics.com/data/event_config_{pid}.json',
540 pid, 'Downloading event config')['eventConfig']
541
542 title = event_config['eventTitle']
543 is_live = {'live': True, 'replay': False}.get(event_config.get('eventStatus'))
bb36a55c 544
58284890 545 source_url = self._download_json(
bb36a55c 546 f'https://api-leap.nbcsports.com/feeds/assets/{pid}?application=NBCOlympics&platform=desktop&format=nbc-player&env=staging',
547 pid, 'Downloading leap config'
548 )['videoSources'][0]['cdnSources']['primary'][0]['sourceUrl']
549
550 if event_config.get('cdnToken'):
551 ap_resource = self._get_mvpd_resource(
552 event_config.get('resourceId', 'NBCOlympics'),
553 re.sub(r'[^\w\d ]+', '', event_config['eventTitle']), pid,
554 event_config.get('ratingId', 'NO VALUE'))
555 media_token = self._extract_mvpd_auth(url, pid, event_config.get('requestorId', 'NBCOlympics'), ap_resource)
556
557 source_url = self._download_json(
558 'https://tokens.playmakerservices.com/', pid, 'Retrieving tokenized URL',
559 data=json.dumps({
560 'application': 'NBCSports',
561 'authentication-type': 'adobe-pass',
562 'cdn': 'akamai',
563 'pid': pid,
564 'platform': 'desktop',
565 'requestorId': 'NBCOlympics',
566 'resourceId': base64.b64encode(ap_resource.encode()).decode(),
567 'token': base64.b64encode(media_token.encode()).decode(),
568 'url': source_url,
569 'version': 'v1',
570 }).encode(),
571 )['akamai'][0]['tokenizedUrl']
572
573 formats = self._extract_m3u8_formats(source_url, pid, 'mp4', live=is_live)
574 for f in formats:
575 # -http_seekable requires ffmpeg 4.3+ but it doesnt seem possible to
576 # download with ffmpeg without this option
0a5a191a 577 f['downloader_options'] = {'ffmpeg_args': ['-seekable', '0', '-http_seekable', '0', '-icy', '0']}
58284890
RA
578 self._sort_formats(formats)
579
580 return {
581 'id': pid,
582 'display_id': display_id,
583 'title': title,
584 'formats': formats,
bb36a55c 585 'is_live': is_live,
58284890 586 }