1 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from .theplatform
import ThePlatformIE
9 from .adobepass
import AdobePassIE
10 from ..compat
import compat_urllib_parse_unquote
21 class NBCIE(AdobePassIE
):
22 _VALID_URL
= r
'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>n?\d+))'
26 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237',
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.',
32 'timestamp': 1424246400,
33 'upload_date': '20150218',
34 'uploader': 'NBCU-COM',
38 'skip_download': True,
42 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
46 'title': 'Star Wars Teaser',
47 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
48 'timestamp': 1417852800,
49 'upload_date': '20141206',
50 'uploader': 'NBCU-COM',
54 'skip_download': True,
56 'skip': 'Only works from US',
59 # HLS streams requires the 'hdnea3' cookie
60 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
62 'id': '101528f5a9e8127b107e98c5e6ce4638',
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',
71 'skip_download': True,
73 'skip': 'Only works from US',
76 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310',
77 'only_matching': True,
81 'url': 'https://www.nbc.com/up-all-night/video/day-after-valentine%27s-day/n2189',
82 'only_matching': True,
86 def _real_extract(self
, url
):
87 permalink
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
88 permalink
= 'http' + compat_urllib_parse_unquote(permalink
)
89 video_data
= self
._download
_json
(
90 'https://friendship.nbc.co/v2/graphql', video_id
, query
={
91 'query': '''query bonanzaPage(
92 $app: NBCUBrands! = nbc
95 $platform: SupportedPlatforms! = web
96 $type: EntityPageType! = VIDEO
108 ... on VideoPageData {
124 'variables': json
.dumps({
129 })['data']['bonanzaPage']['metadata']
134 video_id
= video_data
['mpxGuid']
135 title
= video_data
['secondaryTitle']
136 if video_data
.get('locked'):
137 resource
= self
._get
_mvpd
_resource
(
138 video_data
.get('resourceId') or 'nbcentertainment',
139 title
, video_id
, video_data
.get('rating'))
140 query
['auth'] = self
._extract
_mvpd
_auth
(
141 url
, video_id
, 'nbcentertainment', resource
)
142 theplatform_url
= smuggle_url(update_url_query(
143 'http://link.theplatform.com/s/NnzsPC/media/guid/%s/%s' % (video_data
.get('mpxAccountId') or '2410887629', video_id
),
144 query
), {'force_smil_url': True}
)
146 '_type': 'url_transparent',
149 'url': theplatform_url
,
150 'description': video_data
.get('description'),
151 'tags': video_data
.get('keywords'),
152 'season_number': int_or_none(video_data
.get('seasonNumber')),
153 'episode_number': int_or_none(video_data
.get('episodeNumber')),
155 'series': video_data
.get('seriesShortTitle'),
156 'ie_key': 'ThePlatform',
160 class NBCSportsVPlayerIE(InfoExtractor
):
161 _VALID_URL
= r
'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
164 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI',
166 'id': '9CsDKds0kvHI',
168 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
169 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
170 'timestamp': 1426270238,
171 'upload_date': '20150313',
172 'uploader': 'NBCU-SPORTS',
175 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/_hqLjQ95yx8Z',
176 'only_matching': True,
180 def _extract_url(webpage
):
181 iframe_m
= re
.search(
182 r
'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage
)
184 return iframe_m
.group('url')
186 def _real_extract(self
, url
):
187 video_id
= self
._match
_id
(url
)
188 webpage
= self
._download
_webpage
(url
, video_id
)
189 theplatform_url
= self
._og
_search
_video
_url
(webpage
).replace(
190 'vplayer.nbcsports.com', 'player.theplatform.com')
191 return self
.url_result(theplatform_url
, 'ThePlatform')
194 class NBCSportsIE(InfoExtractor
):
195 # Does not include https because its certificate is invalid
196 _VALID_URL
= r
'https?://(?:www\.)?nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
199 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
201 'id': 'PHJSaFWbrTY9',
203 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
204 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
205 'uploader': 'NBCU-SPORTS',
206 'upload_date': '20150330',
207 'timestamp': 1427726529,
211 def _real_extract(self
, url
):
212 video_id
= self
._match
_id
(url
)
213 webpage
= self
._download
_webpage
(url
, video_id
)
214 return self
.url_result(
215 NBCSportsVPlayerIE
._extract
_url
(webpage
), 'NBCSportsVPlayer')
218 class NBCSportsStreamIE(AdobePassIE
):
219 _VALID_URL
= r
'https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)'
221 'url': 'http://stream.nbcsports.com/nbcsn/generic?pid=206559',
225 'title': 'Amgen Tour of California Women\'s Recap',
226 'description': 'md5:66520066b3b5281ada7698d0ea2aa894',
230 'skip_download': True,
232 'skip': 'Requires Adobe Pass Authentication',
235 def _real_extract(self
, url
):
236 video_id
= self
._match
_id
(url
)
237 live_source
= self
._download
_json
(
238 'http://stream.nbcsports.com/data/live_sources_%s.json' % video_id
,
240 video_source
= live_source
['videoSources'][0]
241 title
= video_source
['title']
243 for k
in ('source', 'msl4source', 'iossource', 'hlsv4'):
245 source_url
= video_source
.get(sk
) or video_source
.get(sk
+ 'Alt')
249 source_url
= video_source
['ottStreamUrl']
250 is_live
= video_source
.get('type') == 'live' or video_source
.get('status') == 'Live'
251 resource
= self
._get
_mvpd
_resource
('nbcsports', title
, video_id
, '')
252 token
= self
._extract
_mvpd
_auth
(url
, video_id
, 'nbcsports', resource
)
253 tokenized_url
= self
._download
_json
(
254 'https://token.playmakerservices.com/cdn',
255 video_id
, data
=json
.dumps({
256 'requestorId': 'nbcsports',
258 'application': 'NBCSports',
260 'platform': 'desktop',
262 'url': video_source
['sourceUrl'],
263 'token': base64
.b64encode(token
.encode()).decode(),
264 'resourceId': base64
.b64encode(resource
.encode()).decode(),
265 }).encode())['tokenizedUrl']
266 formats
= self
._extract
_m
3u8_formats
(tokenized_url
, video_id
, 'mp4')
267 self
._sort
_formats
(formats
)
270 'title': self
._live
_title
(title
) if is_live
else title
,
271 'description': live_source
.get('description'),
277 class CSNNEIE(InfoExtractor
):
278 _VALID_URL
= r
'https?://(?:www\.)?csnne\.com/video/(?P<id>[0-9a-z-]+)'
281 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
283 'id': 'yvBLLUgQ8WU0',
285 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
286 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
287 'timestamp': 1459369979,
288 'upload_date': '20160330',
289 'uploader': 'NBCU-SPORTS',
293 def _real_extract(self
, url
):
294 display_id
= self
._match
_id
(url
)
295 webpage
= self
._download
_webpage
(url
, display_id
)
297 '_type': 'url_transparent',
298 'ie_key': 'ThePlatform',
299 'url': self
._html
_search
_meta
('twitter:player:stream', webpage
),
300 'display_id': display_id
,
304 class NBCNewsIE(ThePlatformIE
):
305 _VALID_URL
= r
'(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)'
309 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
310 'md5': 'cf4bc9e6ce0130f00f545d80ecedd4bf',
312 'id': '269389891880',
314 'title': 'How Twitter Reacted To The Snowden Interview',
315 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
316 'timestamp': 1401363060,
317 'upload_date': '20140529',
321 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
322 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
324 'id': '529953347624',
326 'title': 'FULL EPISODE: Family Business',
327 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
329 'skip': 'This page is unavailable.',
332 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
333 'md5': '8eb831eca25bfa7d25ddd83e85946548',
335 'id': '394064451844',
337 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
338 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
339 'timestamp': 1423104900,
340 'upload_date': '20150205',
344 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
345 'md5': '4a8c4cec9e1ded51060bdda36ff0a5c0',
349 'title': "Volkswagen U.S. Chief: We 'Totally Screwed Up'",
350 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
351 'upload_date': '20150922',
352 'timestamp': 1442917800,
356 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
357 'md5': '118d7ca3f0bea6534f119c68ef539f71',
359 'id': '669831235788',
361 'title': 'See the aurora borealis from space in stunning new NASA video',
362 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
363 'upload_date': '20160420',
364 'timestamp': 1461152093,
368 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
369 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
371 'id': '314487875924',
373 'title': 'The chaotic GOP immigration vote',
374 '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.',
375 'thumbnail': r
're:^https?://.*\.jpg$',
376 'timestamp': 1406937606,
377 'upload_date': '20140802',
381 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
382 'only_matching': True,
385 # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
386 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
387 'only_matching': True,
391 def _real_extract(self
, url
):
392 video_id
= self
._match
_id
(url
)
393 webpage
= self
._download
_webpage
(url
, video_id
)
395 data
= self
._parse
_json
(self
._search
_regex
(
396 r
'<script[^>]+id="__NEXT_DATA__"[^>]*>({.+?})</script>',
397 webpage
, 'bootstrap json'), video_id
)['props']['initialState']
398 video_data
= try_get(data
, lambda x
: x
['video']['current'], dict)
400 video_data
= data
['article']['content'][0]['primaryMedia']['video']
401 title
= video_data
['headline']['primary']
404 for va
in video_data
.get('videoAssets', []):
405 public_url
= va
.get('publicUrl')
408 if '://link.theplatform.com/' in public_url
:
409 public_url
= update_url_query(public_url
, {'format': 'redirect'}
)
410 format_id
= va
.get('format')
411 if format_id
== 'M3U':
412 formats
.extend(self
._extract
_m
3u8_formats
(
413 public_url
, video_id
, 'mp4', 'm3u8_native',
414 m3u8_id
=format_id
, fatal
=False))
416 tbr
= int_or_none(va
.get('bitrate'), 1000)
418 format_id
+= '-%d' % tbr
420 'format_id': format_id
,
422 'width': int_or_none(va
.get('width')),
423 'height': int_or_none(va
.get('height')),
427 self
._sort
_formats
(formats
)
430 closed_captioning
= video_data
.get('closedCaptioning')
431 if closed_captioning
:
432 for cc_url
in closed_captioning
.values():
435 subtitles
.setdefault('en', []).append({
442 'description': try_get(video_data
, lambda x
: x
['description']['primary']),
443 'thumbnail': try_get(video_data
, lambda x
: x
['primaryImage']['url']['primary']),
444 'duration': parse_duration(video_data
.get('duration')),
445 'timestamp': unified_timestamp(video_data
.get('datePublished')),
447 'subtitles': subtitles
,
451 class NBCOlympicsIE(InfoExtractor
):
452 IE_NAME
= 'nbcolympics'
453 _VALID_URL
= r
'https?://www\.nbcolympics\.com/video/(?P<id>[a-z-]+)'
456 # Geo-restricted to US
457 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold',
458 'md5': '54fecf846d05429fbaa18af557ee523a',
460 'id': 'WjTBzDXx5AUq',
461 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold',
463 'title': 'Rose\'s son Leo was in tears after his dad won gold',
464 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.',
465 'timestamp': 1471274964,
466 'upload_date': '20160815',
467 'uploader': 'NBCU-SPORTS',
471 def _real_extract(self
, url
):
472 display_id
= self
._match
_id
(url
)
474 webpage
= self
._download
_webpage
(url
, display_id
)
476 drupal_settings
= self
._parse
_json
(self
._search
_regex
(
477 r
'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
478 webpage
, 'drupal settings'), display_id
)
480 iframe_url
= drupal_settings
['vod']['iframe_url']
481 theplatform_url
= iframe_url
.replace(
482 'vplayer.nbcolympics.com', 'player.theplatform.com')
485 '_type': 'url_transparent',
486 'url': theplatform_url
,
487 'ie_key': ThePlatformIE
.ie_key(),
488 'display_id': display_id
,
492 class NBCOlympicsStreamIE(AdobePassIE
):
493 IE_NAME
= 'nbcolympics:stream'
494 _VALID_URL
= r
'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)'
496 'url': 'http://stream.nbcolympics.com/2018-winter-olympics-nbcsn-evening-feb-8',
500 'title': 're:Curling, Alpine, Luge [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
504 'skip_download': True,
507 _DATA_URL_TEMPLATE
= 'http://stream.nbcolympics.com/data/%s_%s.json'
509 def _real_extract(self
, url
):
510 display_id
= self
._match
_id
(url
)
511 webpage
= self
._download
_webpage
(url
, display_id
)
512 pid
= self
._search
_regex
(r
'pid\s*=\s*(\d+);', webpage
, 'pid')
513 resource
= self
._search
_regex
(
514 r
"resource\s*=\s*'(.+)';", webpage
,
515 'resource').replace("' + pid + '", pid
)
516 event_config
= self
._download
_json
(
517 self
._DATA
_URL
_TEMPLATE
% ('event_config', pid
),
519 title
= self
._live
_title
(event_config
['eventTitle'])
520 source_url
= self
._download
_json
(
521 self
._DATA
_URL
_TEMPLATE
% ('live_sources', pid
),
522 pid
)['videoSources'][0]['sourceUrl']
523 media_token
= self
._extract
_mvpd
_auth
(
524 url
, pid
, event_config
.get('requestorId', 'NBCOlympics'), resource
)
525 formats
= self
._extract
_m
3u8_formats
(self
._download
_webpage
(
526 'http://sp.auth.adobe.com/tvs/v1/sign', pid
, query
={
528 'mediaToken': base64
.b64encode(media_token
.encode()),
529 'resource': base64
.b64encode(resource
.encode()),
532 self
._sort
_formats
(formats
)
536 'display_id': display_id
,