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
22 class NBCIE(ThePlatformIE
):
23 _VALID_URL
= r
'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>n?\d+))'
27 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237',
31 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
32 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
33 'timestamp': 1424246400,
34 'upload_date': '20150218',
35 'uploader': 'NBCU-COM',
39 'skip_download': True,
43 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
47 'title': 'Star Wars Teaser',
48 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
49 'timestamp': 1417852800,
50 'upload_date': '20141206',
51 'uploader': 'NBCU-COM',
55 'skip_download': True,
57 'skip': 'Only works from US',
60 # HLS streams requires the 'hdnea3' cookie
61 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
63 'id': '101528f5a9e8127b107e98c5e6ce4638',
66 '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.',
67 'timestamp': 1237100400,
68 'upload_date': '20090315',
69 'uploader': 'NBCU-COM',
72 'skip_download': True,
74 'skip': 'Only works from US',
77 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310',
78 'only_matching': True,
82 'url': 'https://www.nbc.com/up-all-night/video/day-after-valentine%27s-day/n2189',
83 'only_matching': True,
87 def _real_extract(self
, url
):
88 permalink
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
89 permalink
= 'http' + compat_urllib_parse_unquote(permalink
)
90 video_data
= self
._download
_json
(
91 'https://friendship.nbc.co/v2/graphql', video_id
, query
={
92 'query': '''query bonanzaPage(
93 $app: NBCUBrands! = nbc
96 $platform: SupportedPlatforms! = web
97 $type: EntityPageType! = VIDEO
109 ... on VideoPageData {
125 'variables': json
.dumps({
130 })['data']['bonanzaPage']['metadata']
135 video_id
= video_data
['mpxGuid']
136 tp_path
= 'NnzsPC/media/guid/%s/%s' % (video_data
.get('mpxAccountId') or '2410887629', video_id
)
137 tpm
= self
._download
_theplatform
_metadata
(tp_path
, video_id
)
138 title
= tpm
.get('title') or video_data
.get('secondaryTitle')
139 if video_data
.get('locked'):
140 resource
= self
._get
_mvpd
_resource
(
141 video_data
.get('resourceId') or 'nbcentertainment',
142 title
, video_id
, video_data
.get('rating'))
143 query
['auth'] = self
._extract
_mvpd
_auth
(
144 url
, video_id
, 'nbcentertainment', resource
)
145 theplatform_url
= smuggle_url(update_url_query(
146 'http://link.theplatform.com/s/NnzsPC/media/guid/%s/%s' % (video_data
.get('mpxAccountId') or '2410887629', video_id
),
147 query
), {'force_smil_url': True}
)
149 # Empty string or 0 can be valid values for these. So the check must be `is None`
150 description
= video_data
.get('description')
151 if description
is None:
152 description
= tpm
.get('description')
153 episode_number
= int_or_none(video_data
.get('episodeNumber'))
154 if episode_number
is None:
155 episode_number
= int_or_none(tpm
.get('nbcu$airOrder'))
156 rating
= video_data
.get('rating')
158 try_get(tpm
, lambda x
: x
['ratings'][0]['rating'])
159 season_number
= int_or_none(video_data
.get('seasonNumber'))
160 if season_number
is None:
161 season_number
= int_or_none(tpm
.get('nbcu$seasonNumber'))
162 series
= video_data
.get('seriesShortTitle')
164 series
= tpm
.get('nbcu$seriesShortTitle')
165 tags
= video_data
.get('keywords')
166 if tags
is None or len(tags
) == 0:
167 tags
= tpm
.get('keywords')
170 '_type': 'url_transparent',
171 'age_limit': parse_age_limit(rating
),
172 'description': description
,
174 'episode_number': episode_number
,
176 'ie_key': 'ThePlatform',
177 'season_number': season_number
,
181 'url': theplatform_url
,
185 class NBCSportsVPlayerIE(InfoExtractor
):
186 _VALID_URL_BASE
= r
'https?://(?:vplayer\.nbcsports\.com|(?:www\.)?nbcsports\.com/vplayer)/'
187 _VALID_URL
= _VALID_URL_BASE
+ r
'(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
190 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI',
192 'id': '9CsDKds0kvHI',
194 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
195 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
196 'timestamp': 1426270238,
197 'upload_date': '20150313',
198 'uploader': 'NBCU-SPORTS',
201 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/_hqLjQ95yx8Z',
202 'only_matching': True,
204 'url': 'https://www.nbcsports.com/vplayer/p/BxmELC/nbcsports/select/PHJSaFWbrTY9?form=html&autoPlay=true',
205 'only_matching': True,
209 def _extract_url(webpage
):
210 iframe_m
= re
.search(
211 r
'<(?:iframe[^>]+|div[^>]+data-(?:mpx-)?)src="(?P<url>%s[^"]+)"' % NBCSportsVPlayerIE
._VALID
_URL
_BASE
, webpage
)
213 return iframe_m
.group('url')
215 def _real_extract(self
, url
):
216 video_id
= self
._match
_id
(url
)
217 webpage
= self
._download
_webpage
(url
, video_id
)
218 theplatform_url
= self
._og
_search
_video
_url
(webpage
).replace(
219 'vplayer.nbcsports.com', 'player.theplatform.com')
220 return self
.url_result(theplatform_url
, 'ThePlatform')
223 class NBCSportsIE(InfoExtractor
):
224 _VALID_URL
= r
'https?://(?:www\.)?nbcsports\.com//?(?!vplayer/)(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
228 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
230 'id': 'PHJSaFWbrTY9',
232 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
233 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
234 'uploader': 'NBCU-SPORTS',
235 'upload_date': '20150330',
236 'timestamp': 1427726529,
240 'url': 'https://www.nbcsports.com/philadelphia/philadelphia-phillies/bruce-bochy-hector-neris-hes-idiot',
241 'only_matching': True,
244 'url': 'https://www.nbcsports.com/boston/video/report-card-pats-secondary-no-match-josh-allen',
245 'only_matching': True,
248 def _real_extract(self
, url
):
249 video_id
= self
._match
_id
(url
)
250 webpage
= self
._download
_webpage
(url
, video_id
)
251 return self
.url_result(
252 NBCSportsVPlayerIE
._extract
_url
(webpage
), 'NBCSportsVPlayer')
255 class NBCSportsStreamIE(AdobePassIE
):
256 _VALID_URL
= r
'https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)'
258 'url': 'http://stream.nbcsports.com/nbcsn/generic?pid=206559',
262 'title': 'Amgen Tour of California Women\'s Recap',
263 'description': 'md5:66520066b3b5281ada7698d0ea2aa894',
267 'skip_download': True,
269 'skip': 'Requires Adobe Pass Authentication',
272 def _real_extract(self
, url
):
273 video_id
= self
._match
_id
(url
)
274 live_source
= self
._download
_json
(
275 'http://stream.nbcsports.com/data/live_sources_%s.json' % video_id
,
277 video_source
= live_source
['videoSources'][0]
278 title
= video_source
['title']
280 for k
in ('source', 'msl4source', 'iossource', 'hlsv4'):
282 source_url
= video_source
.get(sk
) or video_source
.get(sk
+ 'Alt')
286 source_url
= video_source
['ottStreamUrl']
287 is_live
= video_source
.get('type') == 'live' or video_source
.get('status') == 'Live'
288 resource
= self
._get
_mvpd
_resource
('nbcsports', title
, video_id
, '')
289 token
= self
._extract
_mvpd
_auth
(url
, video_id
, 'nbcsports', resource
)
290 tokenized_url
= self
._download
_json
(
291 'https://token.playmakerservices.com/cdn',
292 video_id
, data
=json
.dumps({
293 'requestorId': 'nbcsports',
295 'application': 'NBCSports',
297 'platform': 'desktop',
299 'url': video_source
['sourceUrl'],
300 'token': base64
.b64encode(token
.encode()).decode(),
301 'resourceId': base64
.b64encode(resource
.encode()).decode(),
302 }).encode())['tokenizedUrl']
303 formats
= self
._extract
_m
3u8_formats
(tokenized_url
, video_id
, 'mp4')
304 self
._sort
_formats
(formats
)
307 'title': self
._live
_title
(title
) if is_live
else title
,
308 'description': live_source
.get('description'),
314 class NBCNewsIE(ThePlatformIE
):
315 _VALID_URL
= r
'(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)'
319 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
320 'md5': 'cf4bc9e6ce0130f00f545d80ecedd4bf',
322 'id': '269389891880',
324 'title': 'How Twitter Reacted To The Snowden Interview',
325 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
326 'timestamp': 1401363060,
327 'upload_date': '20140529',
331 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
332 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
334 'id': '529953347624',
336 'title': 'FULL EPISODE: Family Business',
337 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
339 'skip': 'This page is unavailable.',
342 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
343 'md5': '8eb831eca25bfa7d25ddd83e85946548',
345 'id': '394064451844',
347 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
348 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
349 'timestamp': 1423104900,
350 'upload_date': '20150205',
354 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
355 'md5': '4a8c4cec9e1ded51060bdda36ff0a5c0',
359 'title': "Volkswagen U.S. Chief: We 'Totally Screwed Up'",
360 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
361 'upload_date': '20150922',
362 'timestamp': 1442917800,
366 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
367 'md5': '118d7ca3f0bea6534f119c68ef539f71',
369 'id': '669831235788',
371 'title': 'See the aurora borealis from space in stunning new NASA video',
372 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
373 'upload_date': '20160420',
374 'timestamp': 1461152093,
378 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
379 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
381 'id': '314487875924',
383 'title': 'The chaotic GOP immigration vote',
384 '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.',
385 'thumbnail': r
're:^https?://.*\.jpg$',
386 'timestamp': 1406937606,
387 'upload_date': '20140802',
391 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
392 'only_matching': True,
395 # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
396 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
397 'only_matching': True,
401 def _real_extract(self
, url
):
402 video_id
= self
._match
_id
(url
)
403 webpage
= self
._download
_webpage
(url
, video_id
)
405 data
= self
._parse
_json
(self
._search
_regex
(
406 r
'<script[^>]+id="__NEXT_DATA__"[^>]*>({.+?})</script>',
407 webpage
, 'bootstrap json'), video_id
)['props']['initialState']
408 video_data
= try_get(data
, lambda x
: x
['video']['current'], dict)
410 video_data
= data
['article']['content'][0]['primaryMedia']['video']
411 title
= video_data
['headline']['primary']
414 for va
in video_data
.get('videoAssets', []):
415 public_url
= va
.get('publicUrl')
418 if '://link.theplatform.com/' in public_url
:
419 public_url
= update_url_query(public_url
, {'format': 'redirect'}
)
420 format_id
= va
.get('format')
421 if format_id
== 'M3U':
422 formats
.extend(self
._extract
_m
3u8_formats
(
423 public_url
, video_id
, 'mp4', 'm3u8_native',
424 m3u8_id
=format_id
, fatal
=False))
426 tbr
= int_or_none(va
.get('bitrate'), 1000)
428 format_id
+= '-%d' % tbr
430 'format_id': format_id
,
432 'width': int_or_none(va
.get('width')),
433 'height': int_or_none(va
.get('height')),
437 self
._sort
_formats
(formats
)
440 closed_captioning
= video_data
.get('closedCaptioning')
441 if closed_captioning
:
442 for cc_url
in closed_captioning
.values():
445 subtitles
.setdefault('en', []).append({
452 'description': try_get(video_data
, lambda x
: x
['description']['primary']),
453 'thumbnail': try_get(video_data
, lambda x
: x
['primaryImage']['url']['primary']),
454 'duration': parse_duration(video_data
.get('duration')),
455 'timestamp': unified_timestamp(video_data
.get('datePublished')),
457 'subtitles': subtitles
,
461 class NBCOlympicsIE(InfoExtractor
):
462 IE_NAME
= 'nbcolympics'
463 _VALID_URL
= r
'https?://www\.nbcolympics\.com/video/(?P<id>[a-z-]+)'
466 # Geo-restricted to US
467 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold',
468 'md5': '54fecf846d05429fbaa18af557ee523a',
470 'id': 'WjTBzDXx5AUq',
471 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold',
473 'title': 'Rose\'s son Leo was in tears after his dad won gold',
474 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.',
475 'timestamp': 1471274964,
476 'upload_date': '20160815',
477 'uploader': 'NBCU-SPORTS',
481 def _real_extract(self
, url
):
482 display_id
= self
._match
_id
(url
)
484 webpage
= self
._download
_webpage
(url
, display_id
)
486 drupal_settings
= self
._parse
_json
(self
._search
_regex
(
487 r
'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
488 webpage
, 'drupal settings'), display_id
)
490 iframe_url
= drupal_settings
['vod']['iframe_url']
491 theplatform_url
= iframe_url
.replace(
492 'vplayer.nbcolympics.com', 'player.theplatform.com')
495 '_type': 'url_transparent',
496 'url': theplatform_url
,
497 'ie_key': ThePlatformIE
.ie_key(),
498 'display_id': display_id
,
502 class NBCOlympicsStreamIE(AdobePassIE
):
503 IE_NAME
= 'nbcolympics:stream'
504 _VALID_URL
= r
'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)'
506 'url': 'http://stream.nbcolympics.com/2018-winter-olympics-nbcsn-evening-feb-8',
510 'title': 're:Curling, Alpine, Luge [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
514 'skip_download': True,
517 _DATA_URL_TEMPLATE
= 'http://stream.nbcolympics.com/data/%s_%s.json'
519 def _real_extract(self
, url
):
520 display_id
= self
._match
_id
(url
)
521 webpage
= self
._download
_webpage
(url
, display_id
)
522 pid
= self
._search
_regex
(r
'pid\s*=\s*(\d+);', webpage
, 'pid')
523 resource
= self
._search
_regex
(
524 r
"resource\s*=\s*'(.+)';", webpage
,
525 'resource').replace("' + pid + '", pid
)
526 event_config
= self
._download
_json
(
527 self
._DATA
_URL
_TEMPLATE
% ('event_config', pid
),
529 title
= self
._live
_title
(event_config
['eventTitle'])
530 source_url
= self
._download
_json
(
531 self
._DATA
_URL
_TEMPLATE
% ('live_sources', pid
),
532 pid
)['videoSources'][0]['sourceUrl']
533 media_token
= self
._extract
_mvpd
_auth
(
534 url
, pid
, event_config
.get('requestorId', 'NBCOlympics'), resource
)
535 formats
= self
._extract
_m
3u8_formats
(self
._download
_webpage
(
536 'http://sp.auth.adobe.com/tvs/v1/sign', pid
, query
={
538 'mediaToken': base64
.b64encode(media_token
.encode()),
539 'resource': base64
.b64encode(resource
.encode()),
542 self
._sort
_formats
(formats
)
546 'display_id': display_id
,