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_BASE
= r
'https?://(?:vplayer\.nbcsports\.com|(?:www\.)?nbcsports\.com/vplayer)/'
162 _VALID_URL
= _VALID_URL_BASE
+ r
'(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
165 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI',
167 'id': '9CsDKds0kvHI',
169 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
170 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
171 'timestamp': 1426270238,
172 'upload_date': '20150313',
173 'uploader': 'NBCU-SPORTS',
176 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/_hqLjQ95yx8Z',
177 'only_matching': True,
179 'url': 'https://www.nbcsports.com/vplayer/p/BxmELC/nbcsports/select/PHJSaFWbrTY9?form=html&autoPlay=true',
180 'only_matching': True,
184 def _extract_url(webpage
):
185 iframe_m
= re
.search(
186 r
'<(?:iframe[^>]+|div[^>]+data-(?:mpx-)?)src="(?P<url>%s[^"]+)"' % NBCSportsVPlayerIE
._VALID
_URL
_BASE
, webpage
)
188 return iframe_m
.group('url')
190 def _real_extract(self
, url
):
191 video_id
= self
._match
_id
(url
)
192 webpage
= self
._download
_webpage
(url
, video_id
)
193 theplatform_url
= self
._og
_search
_video
_url
(webpage
).replace(
194 'vplayer.nbcsports.com', 'player.theplatform.com')
195 return self
.url_result(theplatform_url
, 'ThePlatform')
198 class NBCSportsIE(InfoExtractor
):
199 _VALID_URL
= r
'https?://(?:www\.)?nbcsports\.com//?(?!vplayer/)(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
203 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
205 'id': 'PHJSaFWbrTY9',
207 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
208 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
209 'uploader': 'NBCU-SPORTS',
210 'upload_date': '20150330',
211 'timestamp': 1427726529,
215 'url': 'https://www.nbcsports.com/philadelphia/philadelphia-phillies/bruce-bochy-hector-neris-hes-idiot',
216 'only_matching': True,
219 'url': 'https://www.nbcsports.com/boston/video/report-card-pats-secondary-no-match-josh-allen',
220 'only_matching': True,
223 def _real_extract(self
, url
):
224 video_id
= self
._match
_id
(url
)
225 webpage
= self
._download
_webpage
(url
, video_id
)
226 return self
.url_result(
227 NBCSportsVPlayerIE
._extract
_url
(webpage
), 'NBCSportsVPlayer')
230 class NBCSportsStreamIE(AdobePassIE
):
231 _VALID_URL
= r
'https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)'
233 'url': 'http://stream.nbcsports.com/nbcsn/generic?pid=206559',
237 'title': 'Amgen Tour of California Women\'s Recap',
238 'description': 'md5:66520066b3b5281ada7698d0ea2aa894',
242 'skip_download': True,
244 'skip': 'Requires Adobe Pass Authentication',
247 def _real_extract(self
, url
):
248 video_id
= self
._match
_id
(url
)
249 live_source
= self
._download
_json
(
250 'http://stream.nbcsports.com/data/live_sources_%s.json' % video_id
,
252 video_source
= live_source
['videoSources'][0]
253 title
= video_source
['title']
255 for k
in ('source', 'msl4source', 'iossource', 'hlsv4'):
257 source_url
= video_source
.get(sk
) or video_source
.get(sk
+ 'Alt')
261 source_url
= video_source
['ottStreamUrl']
262 is_live
= video_source
.get('type') == 'live' or video_source
.get('status') == 'Live'
263 resource
= self
._get
_mvpd
_resource
('nbcsports', title
, video_id
, '')
264 token
= self
._extract
_mvpd
_auth
(url
, video_id
, 'nbcsports', resource
)
265 tokenized_url
= self
._download
_json
(
266 'https://token.playmakerservices.com/cdn',
267 video_id
, data
=json
.dumps({
268 'requestorId': 'nbcsports',
270 'application': 'NBCSports',
272 'platform': 'desktop',
274 'url': video_source
['sourceUrl'],
275 'token': base64
.b64encode(token
.encode()).decode(),
276 'resourceId': base64
.b64encode(resource
.encode()).decode(),
277 }).encode())['tokenizedUrl']
278 formats
= self
._extract
_m
3u8_formats
(tokenized_url
, video_id
, 'mp4')
279 self
._sort
_formats
(formats
)
282 'title': self
._live
_title
(title
) if is_live
else title
,
283 'description': live_source
.get('description'),
289 class NBCNewsIE(ThePlatformIE
):
290 _VALID_URL
= r
'(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)'
294 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
295 'md5': 'cf4bc9e6ce0130f00f545d80ecedd4bf',
297 'id': '269389891880',
299 'title': 'How Twitter Reacted To The Snowden Interview',
300 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
301 'timestamp': 1401363060,
302 'upload_date': '20140529',
306 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
307 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
309 'id': '529953347624',
311 'title': 'FULL EPISODE: Family Business',
312 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
314 'skip': 'This page is unavailable.',
317 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
318 'md5': '8eb831eca25bfa7d25ddd83e85946548',
320 'id': '394064451844',
322 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
323 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
324 'timestamp': 1423104900,
325 'upload_date': '20150205',
329 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
330 'md5': '4a8c4cec9e1ded51060bdda36ff0a5c0',
334 'title': "Volkswagen U.S. Chief: We 'Totally Screwed Up'",
335 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
336 'upload_date': '20150922',
337 'timestamp': 1442917800,
341 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
342 'md5': '118d7ca3f0bea6534f119c68ef539f71',
344 'id': '669831235788',
346 'title': 'See the aurora borealis from space in stunning new NASA video',
347 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
348 'upload_date': '20160420',
349 'timestamp': 1461152093,
353 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
354 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
356 'id': '314487875924',
358 'title': 'The chaotic GOP immigration vote',
359 '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.',
360 'thumbnail': r
're:^https?://.*\.jpg$',
361 'timestamp': 1406937606,
362 'upload_date': '20140802',
366 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
367 'only_matching': True,
370 # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
371 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
372 'only_matching': True,
376 def _real_extract(self
, url
):
377 video_id
= self
._match
_id
(url
)
378 webpage
= self
._download
_webpage
(url
, video_id
)
380 data
= self
._parse
_json
(self
._search
_regex
(
381 r
'<script[^>]+id="__NEXT_DATA__"[^>]*>({.+?})</script>',
382 webpage
, 'bootstrap json'), video_id
)['props']['initialState']
383 video_data
= try_get(data
, lambda x
: x
['video']['current'], dict)
385 video_data
= data
['article']['content'][0]['primaryMedia']['video']
386 title
= video_data
['headline']['primary']
389 for va
in video_data
.get('videoAssets', []):
390 public_url
= va
.get('publicUrl')
393 if '://link.theplatform.com/' in public_url
:
394 public_url
= update_url_query(public_url
, {'format': 'redirect'}
)
395 format_id
= va
.get('format')
396 if format_id
== 'M3U':
397 formats
.extend(self
._extract
_m
3u8_formats
(
398 public_url
, video_id
, 'mp4', 'm3u8_native',
399 m3u8_id
=format_id
, fatal
=False))
401 tbr
= int_or_none(va
.get('bitrate'), 1000)
403 format_id
+= '-%d' % tbr
405 'format_id': format_id
,
407 'width': int_or_none(va
.get('width')),
408 'height': int_or_none(va
.get('height')),
412 self
._sort
_formats
(formats
)
415 closed_captioning
= video_data
.get('closedCaptioning')
416 if closed_captioning
:
417 for cc_url
in closed_captioning
.values():
420 subtitles
.setdefault('en', []).append({
427 'description': try_get(video_data
, lambda x
: x
['description']['primary']),
428 'thumbnail': try_get(video_data
, lambda x
: x
['primaryImage']['url']['primary']),
429 'duration': parse_duration(video_data
.get('duration')),
430 'timestamp': unified_timestamp(video_data
.get('datePublished')),
432 'subtitles': subtitles
,
436 class NBCOlympicsIE(InfoExtractor
):
437 IE_NAME
= 'nbcolympics'
438 _VALID_URL
= r
'https?://www\.nbcolympics\.com/video/(?P<id>[a-z-]+)'
441 # Geo-restricted to US
442 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold',
443 'md5': '54fecf846d05429fbaa18af557ee523a',
445 'id': 'WjTBzDXx5AUq',
446 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold',
448 'title': 'Rose\'s son Leo was in tears after his dad won gold',
449 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.',
450 'timestamp': 1471274964,
451 'upload_date': '20160815',
452 'uploader': 'NBCU-SPORTS',
456 def _real_extract(self
, url
):
457 display_id
= self
._match
_id
(url
)
459 webpage
= self
._download
_webpage
(url
, display_id
)
461 drupal_settings
= self
._parse
_json
(self
._search
_regex
(
462 r
'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
463 webpage
, 'drupal settings'), display_id
)
465 iframe_url
= drupal_settings
['vod']['iframe_url']
466 theplatform_url
= iframe_url
.replace(
467 'vplayer.nbcolympics.com', 'player.theplatform.com')
470 '_type': 'url_transparent',
471 'url': theplatform_url
,
472 'ie_key': ThePlatformIE
.ie_key(),
473 'display_id': display_id
,
477 class NBCOlympicsStreamIE(AdobePassIE
):
478 IE_NAME
= 'nbcolympics:stream'
479 _VALID_URL
= r
'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)'
481 'url': 'http://stream.nbcolympics.com/2018-winter-olympics-nbcsn-evening-feb-8',
485 'title': 're:Curling, Alpine, Luge [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
489 'skip_download': True,
492 _DATA_URL_TEMPLATE
= 'http://stream.nbcolympics.com/data/%s_%s.json'
494 def _real_extract(self
, url
):
495 display_id
= self
._match
_id
(url
)
496 webpage
= self
._download
_webpage
(url
, display_id
)
497 pid
= self
._search
_regex
(r
'pid\s*=\s*(\d+);', webpage
, 'pid')
498 resource
= self
._search
_regex
(
499 r
"resource\s*=\s*'(.+)';", webpage
,
500 'resource').replace("' + pid + '", pid
)
501 event_config
= self
._download
_json
(
502 self
._DATA
_URL
_TEMPLATE
% ('event_config', pid
),
504 title
= self
._live
_title
(event_config
['eventTitle'])
505 source_url
= self
._download
_json
(
506 self
._DATA
_URL
_TEMPLATE
% ('live_sources', pid
),
507 pid
)['videoSources'][0]['sourceUrl']
508 media_token
= self
._extract
_mvpd
_auth
(
509 url
, pid
, event_config
.get('requestorId', 'NBCOlympics'), resource
)
510 formats
= self
._extract
_m
3u8_formats
(self
._download
_webpage
(
511 'http://sp.auth.adobe.com/tvs/v1/sign', pid
, query
={
513 'mediaToken': base64
.b64encode(media_token
.encode()),
514 'resource': base64
.b64encode(resource
.encode()),
517 self
._sort
_formats
(formats
)
521 'display_id': display_id
,