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
23 class NBCIE(ThePlatformIE
):
24 _VALID_URL
= r
'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>n?\d+))'
28 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237',
32 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
33 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
34 'timestamp': 1424246400,
35 'upload_date': '20150218',
36 'uploader': 'NBCU-COM',
40 'skip_download': True,
44 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
48 'title': 'Star Wars Teaser',
49 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
50 'timestamp': 1417852800,
51 'upload_date': '20141206',
52 'uploader': 'NBCU-COM',
56 'skip_download': True,
58 'skip': 'Only works from US',
61 # HLS streams requires the 'hdnea3' cookie
62 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
64 'id': '101528f5a9e8127b107e98c5e6ce4638',
67 '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.',
68 'timestamp': 1237100400,
69 'upload_date': '20090315',
70 'uploader': 'NBCU-COM',
73 'skip_download': True,
75 'skip': 'Only works from US',
78 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310',
79 'only_matching': True,
83 'url': 'https://www.nbc.com/up-all-night/video/day-after-valentine%27s-day/n2189',
84 'only_matching': True,
88 def _real_extract(self
, url
):
89 permalink
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
90 permalink
= 'http' + compat_urllib_parse_unquote(permalink
)
91 video_data
= self
._download
_json
(
92 'https://friendship.nbc.co/v2/graphql', video_id
, query
={
93 'query': '''query bonanzaPage(
94 $app: NBCUBrands! = nbc
97 $platform: SupportedPlatforms! = web
98 $type: EntityPageType! = VIDEO
110 ... on VideoPageData {
126 'variables': json
.dumps({
131 })['data']['bonanzaPage']['metadata']
136 video_id
= video_data
['mpxGuid']
137 tp_path
= 'NnzsPC/media/guid/%s/%s' % (video_data
.get('mpxAccountId') or '2410887629', video_id
)
138 tpm
= self
._download
_theplatform
_metadata
(tp_path
, video_id
)
139 title
= tpm
.get('title') or video_data
.get('secondaryTitle')
140 if video_data
.get('locked'):
141 resource
= self
._get
_mvpd
_resource
(
142 video_data
.get('resourceId') or 'nbcentertainment',
143 title
, video_id
, video_data
.get('rating'))
144 query
['auth'] = self
._extract
_mvpd
_auth
(
145 url
, video_id
, 'nbcentertainment', resource
)
146 theplatform_url
= smuggle_url(update_url_query(
147 'http://link.theplatform.com/s/NnzsPC/media/guid/%s/%s' % (video_data
.get('mpxAccountId') or '2410887629', video_id
),
148 query
), {'force_smil_url': True}
)
150 # Empty string or 0 can be valid values for these. So the check must be `is None`
151 description
= video_data
.get('description')
152 if description
is None:
153 description
= tpm
.get('description')
154 episode_number
= int_or_none(video_data
.get('episodeNumber'))
155 if episode_number
is None:
156 episode_number
= int_or_none(tpm
.get('nbcu$airOrder'))
157 rating
= video_data
.get('rating')
159 try_get(tpm
, lambda x
: x
['ratings'][0]['rating'])
160 season_number
= int_or_none(video_data
.get('seasonNumber'))
161 if season_number
is None:
162 season_number
= int_or_none(tpm
.get('nbcu$seasonNumber'))
163 series
= video_data
.get('seriesShortTitle')
165 series
= tpm
.get('nbcu$seriesShortTitle')
166 tags
= video_data
.get('keywords')
167 if tags
is None or len(tags
) == 0:
168 tags
= tpm
.get('keywords')
171 '_type': 'url_transparent',
172 'age_limit': parse_age_limit(rating
),
173 'description': description
,
175 'episode_number': episode_number
,
177 'ie_key': 'ThePlatform',
178 'season_number': season_number
,
182 'url': theplatform_url
,
186 class NBCSportsVPlayerIE(InfoExtractor
):
187 _VALID_URL_BASE
= r
'https?://(?:vplayer\.nbcsports\.com|(?:www\.)?nbcsports\.com/vplayer)/'
188 _VALID_URL
= _VALID_URL_BASE
+ r
'(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
191 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI',
193 'id': '9CsDKds0kvHI',
195 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
196 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
197 'timestamp': 1426270238,
198 'upload_date': '20150313',
199 'uploader': 'NBCU-SPORTS',
202 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/_hqLjQ95yx8Z',
203 'only_matching': True,
205 'url': 'https://www.nbcsports.com/vplayer/p/BxmELC/nbcsports/select/PHJSaFWbrTY9?form=html&autoPlay=true',
206 'only_matching': True,
210 def _extract_url(webpage
):
211 iframe_m
= re
.search(
212 r
'<(?:iframe[^>]+|div[^>]+data-(?:mpx-)?)src="(?P<url>%s[^"]+)"' % NBCSportsVPlayerIE
._VALID
_URL
_BASE
, webpage
)
214 return iframe_m
.group('url')
216 def _real_extract(self
, url
):
217 video_id
= self
._match
_id
(url
)
218 webpage
= self
._download
_webpage
(url
, video_id
)
219 theplatform_url
= self
._og
_search
_video
_url
(webpage
).replace(
220 'vplayer.nbcsports.com', 'player.theplatform.com')
221 return self
.url_result(theplatform_url
, 'ThePlatform')
224 class NBCSportsIE(InfoExtractor
):
225 _VALID_URL
= r
'https?://(?:www\.)?nbcsports\.com//?(?!vplayer/)(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
229 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
231 'id': 'PHJSaFWbrTY9',
233 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
234 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
235 'uploader': 'NBCU-SPORTS',
236 'upload_date': '20150330',
237 'timestamp': 1427726529,
241 'url': 'https://www.nbcsports.com/philadelphia/philadelphia-phillies/bruce-bochy-hector-neris-hes-idiot',
242 'only_matching': True,
245 'url': 'https://www.nbcsports.com/boston/video/report-card-pats-secondary-no-match-josh-allen',
246 'only_matching': True,
249 def _real_extract(self
, url
):
250 video_id
= self
._match
_id
(url
)
251 webpage
= self
._download
_webpage
(url
, video_id
)
252 return self
.url_result(
253 NBCSportsVPlayerIE
._extract
_url
(webpage
), 'NBCSportsVPlayer')
256 class NBCSportsStreamIE(AdobePassIE
):
257 _VALID_URL
= r
'https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)'
259 'url': 'http://stream.nbcsports.com/nbcsn/generic?pid=206559',
263 'title': 'Amgen Tour of California Women\'s Recap',
264 'description': 'md5:66520066b3b5281ada7698d0ea2aa894',
268 'skip_download': True,
270 'skip': 'Requires Adobe Pass Authentication',
273 def _real_extract(self
, url
):
274 video_id
= self
._match
_id
(url
)
275 live_source
= self
._download
_json
(
276 'http://stream.nbcsports.com/data/live_sources_%s.json' % video_id
,
278 video_source
= live_source
['videoSources'][0]
279 title
= video_source
['title']
281 for k
in ('source', 'msl4source', 'iossource', 'hlsv4'):
283 source_url
= video_source
.get(sk
) or video_source
.get(sk
+ 'Alt')
287 source_url
= video_source
['ottStreamUrl']
288 is_live
= video_source
.get('type') == 'live' or video_source
.get('status') == 'Live'
289 resource
= self
._get
_mvpd
_resource
('nbcsports', title
, video_id
, '')
290 token
= self
._extract
_mvpd
_auth
(url
, video_id
, 'nbcsports', resource
)
291 tokenized_url
= self
._download
_json
(
292 'https://token.playmakerservices.com/cdn',
293 video_id
, data
=json
.dumps({
294 'requestorId': 'nbcsports',
296 'application': 'NBCSports',
298 'platform': 'desktop',
300 'url': video_source
['sourceUrl'],
301 'token': base64
.b64encode(token
.encode()).decode(),
302 'resourceId': base64
.b64encode(resource
.encode()).decode(),
303 }).encode())['tokenizedUrl']
304 formats
= self
._extract
_m
3u8_formats
(tokenized_url
, video_id
, 'mp4')
305 self
._sort
_formats
(formats
)
308 'title': self
._live
_title
(title
) if is_live
else title
,
309 'description': live_source
.get('description'),
315 class NBCNewsIE(ThePlatformIE
):
316 _VALID_URL
= r
'(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)'
320 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
321 'md5': 'cf4bc9e6ce0130f00f545d80ecedd4bf',
323 'id': '269389891880',
325 'title': 'How Twitter Reacted To The Snowden Interview',
326 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
327 'timestamp': 1401363060,
328 'upload_date': '20140529',
332 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
333 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
335 'id': '529953347624',
337 'title': 'FULL EPISODE: Family Business',
338 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
340 'skip': 'This page is unavailable.',
343 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
344 'md5': '8eb831eca25bfa7d25ddd83e85946548',
346 'id': '394064451844',
348 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
349 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
350 'timestamp': 1423104900,
351 'upload_date': '20150205',
355 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
356 'md5': '4a8c4cec9e1ded51060bdda36ff0a5c0',
360 'title': "Volkswagen U.S. Chief: We 'Totally Screwed Up'",
361 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
362 'upload_date': '20150922',
363 'timestamp': 1442917800,
367 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
368 'md5': '118d7ca3f0bea6534f119c68ef539f71',
370 'id': '669831235788',
372 'title': 'See the aurora borealis from space in stunning new NASA video',
373 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
374 'upload_date': '20160420',
375 'timestamp': 1461152093,
379 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
380 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
382 'id': '314487875924',
384 'title': 'The chaotic GOP immigration vote',
385 '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.',
386 'thumbnail': r
're:^https?://.*\.jpg$',
387 'timestamp': 1406937606,
388 'upload_date': '20140802',
392 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
393 'only_matching': True,
396 # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
397 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
398 'only_matching': True,
402 def _real_extract(self
, url
):
403 video_id
= self
._match
_id
(url
)
404 webpage
= self
._download
_webpage
(url
, video_id
)
406 data
= self
._parse
_json
(self
._search
_regex
(
407 r
'<script[^>]+id="__NEXT_DATA__"[^>]*>({.+?})</script>',
408 webpage
, 'bootstrap json'), video_id
)['props']['initialState']
409 video_data
= try_get(data
, lambda x
: x
['video']['current'], dict)
411 video_data
= data
['article']['content'][0]['primaryMedia']['video']
412 title
= video_data
['headline']['primary']
415 for va
in video_data
.get('videoAssets', []):
416 public_url
= va
.get('publicUrl')
419 if '://link.theplatform.com/' in public_url
:
420 public_url
= update_url_query(public_url
, {'format': 'redirect'}
)
421 format_id
= va
.get('format')
422 if format_id
== 'M3U':
423 formats
.extend(self
._extract
_m
3u8_formats
(
424 public_url
, video_id
, 'mp4', 'm3u8_native',
425 m3u8_id
=format_id
, fatal
=False))
427 tbr
= int_or_none(va
.get('bitrate'), 1000)
429 format_id
+= '-%d' % tbr
431 'format_id': format_id
,
433 'width': int_or_none(va
.get('width')),
434 'height': int_or_none(va
.get('height')),
438 self
._sort
_formats
(formats
)
441 closed_captioning
= video_data
.get('closedCaptioning')
442 if closed_captioning
:
443 for cc_url
in closed_captioning
.values():
446 subtitles
.setdefault('en', []).append({
453 'description': try_get(video_data
, lambda x
: x
['description']['primary']),
454 'thumbnail': try_get(video_data
, lambda x
: x
['primaryImage']['url']['primary']),
455 'duration': parse_duration(video_data
.get('duration')),
456 'timestamp': unified_timestamp(video_data
.get('datePublished')),
458 'subtitles': subtitles
,
462 class NBCOlympicsIE(InfoExtractor
):
463 IE_NAME
= 'nbcolympics'
464 _VALID_URL
= r
'https?://www\.nbcolympics\.com/videos?/(?P<id>[0-9a-z-]+)'
467 # Geo-restricted to US
468 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold',
469 'md5': '54fecf846d05429fbaa18af557ee523a',
471 'id': 'WjTBzDXx5AUq',
472 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold',
474 'title': 'Rose\'s son Leo was in tears after his dad won gold',
475 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.',
476 'timestamp': 1471274964,
477 'upload_date': '20160815',
478 'uploader': 'NBCU-SPORTS',
482 def _real_extract(self
, url
):
483 display_id
= self
._match
_id
(url
)
485 webpage
= self
._download
_webpage
(url
, display_id
)
488 drupal_settings
= self
._parse
_json
(self
._search
_regex
(
489 r
'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
490 webpage
, 'drupal settings'), display_id
)
492 iframe_url
= drupal_settings
['vod']['iframe_url']
493 theplatform_url
= iframe_url
.replace(
494 'vplayer.nbcolympics.com', 'player.theplatform.com')
495 except RegexNotFoundError
:
496 theplatform_url
= self
._search
_regex
(
497 r
"([\"'])embedUrl\1: *([\"'])(?P
<embedUrl
>.+)\
2",
498 webpage, 'embedding URL', group="embedUrl
")
501 '_type': 'url_transparent',
502 'url': theplatform_url,
503 'ie_key': ThePlatformIE.ie_key(),
504 'display_id': display_id,
508 class NBCOlympicsStreamIE(AdobePassIE):
509 IE_NAME = 'nbcolympics:stream'
510 _VALID_URL = r'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)'
512 'url': 'http://stream.nbcolympics.com/2018-winter-olympics-nbcsn-evening-feb-8',
516 'title': 're:Curling, Alpine, Luge [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
520 'skip_download': True,
523 _DATA_URL_TEMPLATE = 'http://stream.nbcolympics.com/data/%s_%s.json'
525 def _real_extract(self, url):
526 display_id = self._match_id(url)
527 webpage = self._download_webpage(url, display_id)
528 pid = self._search_regex(r'pid\s*=\s*(\d+);', webpage, 'pid')
529 resource = self._search_regex(
530 r"resource\s
*=\s
*'(.+)';", webpage,
531 'resource').replace("' + pid + '", pid)
532 event_config = self._download_json(
533 self._DATA_URL_TEMPLATE % ('event_config', pid),
535 title = self._live_title(event_config['eventTitle'])
536 source_url = self._download_json(
537 self._DATA_URL_TEMPLATE % ('live_sources', pid),
538 pid)['videoSources'][0]['sourceUrl']
539 media_token = self._extract_mvpd_auth(
540 url, pid, event_config.get('requestorId', 'NBCOlympics'), resource)
541 formats = self._extract_m3u8_formats(self._download_webpage(
542 'http://sp.auth.adobe.com/tvs/v1/sign', pid, query={
544 'mediaToken': base64.b64encode(media_token.encode()),
545 'resource': base64.b64encode(resource.encode()),
548 self._sort_formats(formats)
552 'display_id': display_id,