1 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from .theplatform import ThePlatformIE
8 from .adobepass import AdobePassIE
19 class NBCIE(AdobePassIE):
20 _VALID_URL = r'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>n?\d+))'
24 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237',
28 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
29 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
30 'timestamp': 1424246400,
31 'upload_date': '20150218',
32 'uploader': 'NBCU-COM',
36 'skip_download': True,
40 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
44 'title': 'Star Wars Teaser',
45 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
46 'timestamp': 1417852800,
47 'upload_date': '20141206',
48 'uploader': 'NBCU-COM',
52 'skip_download': True,
54 'skip': 'Only works from US',
57 # HLS streams requires the 'hdnea3' cookie
58 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
60 'id': '101528f5a9e8127b107e98c5e6ce4638',
63 '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.',
64 'timestamp': 1237100400,
65 'upload_date': '20090315',
66 'uploader': 'NBCU-COM',
69 'skip_download': True,
71 'skip': 'Only works from US',
74 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310',
75 'only_matching': True,
79 def _real_extract(self, url):
80 permalink, video_id = re.match(self._VALID_URL, url).groups()
81 permalink = 'http' + permalink
82 response = self._download_json(
83 'https://api.nbc.com/v3/videos', video_id, query={
84 'filter[permalink]': permalink,
85 'fields[videos]': 'description,entitlement,episodeNumber,guid,keywords,seasonNumber,title,vChipRating',
86 'fields[shows]': 'shortTitle',
87 'include': 'show.shortTitle',
89 video_data = response['data'][0]['attributes']
94 video_id = video_data['guid']
95 title = video_data['title']
96 if video_data.get('entitlement') == 'auth':
97 resource = self._get_mvpd_resource(
98 'nbcentertainment', title, video_id,
99 video_data.get('vChipRating'))
100 query['auth'] = self._extract_mvpd_auth(
101 url, video_id, 'nbcentertainment', resource)
102 theplatform_url = smuggle_url(update_url_query(
103 'http://link.theplatform.com/s/NnzsPC/media/guid/2410887629/' + video_id,
104 query), {'force_smil_url': True})
106 '_type': 'url_transparent',
109 'url': theplatform_url,
110 'description': video_data.get('description'),
111 'tags': video_data.get('keywords'),
112 'season_number': int_or_none(video_data.get('seasonNumber')),
113 'episode_number': int_or_none(video_data.get('episodeNumber')),
115 'series': try_get(response, lambda x: x['included'][0]['attributes']['shortTitle']),
116 'ie_key': 'ThePlatform',
120 class NBCSportsVPlayerIE(InfoExtractor):
121 _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
124 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI',
126 'id': '9CsDKds0kvHI',
128 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
129 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
130 'timestamp': 1426270238,
131 'upload_date': '20150313',
132 'uploader': 'NBCU-SPORTS',
135 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/_hqLjQ95yx8Z',
136 'only_matching': True,
140 def _extract_url(webpage):
141 iframe_m = re.search(
142 r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
144 return iframe_m.group('url')
146 def _real_extract(self, url):
147 video_id = self._match_id(url)
148 webpage = self._download_webpage(url, video_id)
149 theplatform_url = self._og_search_video_url(webpage).replace(
150 'vplayer.nbcsports.com', 'player.theplatform.com')
151 return self.url_result(theplatform_url, 'ThePlatform')
154 class NBCSportsIE(InfoExtractor):
155 # Does not include https because its certificate is invalid
156 _VALID_URL = r'https?://(?:www\.)?nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
159 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
161 'id': 'PHJSaFWbrTY9',
163 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
164 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
165 'uploader': 'NBCU-SPORTS',
166 'upload_date': '20150330',
167 'timestamp': 1427726529,
171 def _real_extract(self, url):
172 video_id = self._match_id(url)
173 webpage = self._download_webpage(url, video_id)
174 return self.url_result(
175 NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
178 class CSNNEIE(InfoExtractor):
179 _VALID_URL = r'https?://(?:www\.)?csnne\.com/video/(?P<id>[0-9a-z-]+)'
182 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
184 'id': 'yvBLLUgQ8WU0',
186 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
187 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
188 'timestamp': 1459369979,
189 'upload_date': '20160330',
190 'uploader': 'NBCU-SPORTS',
194 def _real_extract(self, url):
195 display_id = self._match_id(url)
196 webpage = self._download_webpage(url, display_id)
198 '_type': 'url_transparent',
199 'ie_key': 'ThePlatform',
200 'url': self._html_search_meta('twitter:player:stream', webpage),
201 'display_id': display_id,
205 class NBCNewsIE(ThePlatformIE):
206 _VALID_URL = r'''(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/
207 (?:video/.+?/(?P<id>\d+)|
208 ([^/]+/)*(?:.*-)?(?P<mpx_id>[^/?]+))
213 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
214 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
218 'title': 'Crew emerges after four-month Mars food study',
219 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
223 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
224 'md5': 'af1adfa51312291a017720403826bb64',
226 'id': 'p_tweet_snow_140529',
228 'title': 'How Twitter Reacted To The Snowden Interview',
229 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
230 'uploader': 'NBCU-NEWS',
231 'timestamp': 1401363060,
232 'upload_date': '20140529',
236 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
237 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
239 'id': '529953347624',
241 'title': 'FULL EPISODE: Family Business',
242 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
244 'skip': 'This page is unavailable.',
247 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
248 'md5': '73135a2e0ef819107bbb55a5a9b2a802',
250 'id': 'nn_netcast_150204',
252 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
253 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
254 'timestamp': 1423104900,
255 'uploader': 'NBCU-NEWS',
256 'upload_date': '20150205',
260 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
261 'md5': 'a49e173825e5fcd15c13fc297fced39d',
263 'id': 'x_lon_vwhorn_150922',
265 'title': 'Volkswagen U.S. Chief:\xa0 We Have Totally Screwed Up',
266 'description': 'md5:c8be487b2d80ff0594c005add88d8351',
267 'upload_date': '20150922',
268 'timestamp': 1442917800,
269 'uploader': 'NBCU-NEWS',
273 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
274 'md5': '118d7ca3f0bea6534f119c68ef539f71',
276 'id': 'tdy_al_space_160420',
278 'title': 'See the aurora borealis from space in stunning new NASA video',
279 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
280 'upload_date': '20160420',
281 'timestamp': 1461152093,
282 'uploader': 'NBCU-NEWS',
286 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
287 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
289 'id': 'n_hayes_Aimm_140801_272214',
291 'title': 'The chaotic GOP immigration vote',
292 '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.',
293 'thumbnail': r're:^https?://.*\.jpg$',
294 'timestamp': 1406937606,
295 'upload_date': '20140802',
296 'uploader': 'NBCU-NEWS',
300 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
301 'only_matching': True,
304 # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
305 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
306 'only_matching': True,
310 def _real_extract(self, url):
311 mobj = re.match(self._VALID_URL, url)
312 video_id = mobj.group('id')
313 if video_id is not None:
314 all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
315 info = all_info.find('video')
319 'title': info.find('headline').text,
321 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
322 'description': info.find('caption').text,
323 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
326 # "feature" and "nightly-news" pages use theplatform.com
327 video_id = mobj.group('mpx_id')
328 webpage = self._download_webpage(url, video_id)
330 filter_param = 'byId'
331 bootstrap_json = self._search_regex(
332 [r'(?m)(?:var\s+(?:bootstrapJson|playlistData)|NEWS\.videoObj)\s*=\s*({.+});?\s*$',
333 r'videoObj\s*:\s*({.+})', r'data-video="([^"]+)"',
334 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);'],
335 webpage, 'bootstrap json', default=None)
337 bootstrap = self._parse_json(
338 bootstrap_json, video_id, transform_source=unescapeHTML)
341 if 'results' in bootstrap:
342 info = bootstrap['results'][0]['video']
343 elif 'video' in bootstrap:
344 info = bootstrap['video']
345 elif 'msnbcVideoInfo' in bootstrap:
346 info = bootstrap['msnbcVideoInfo']['meta']
347 elif 'msnbcThePlatform' in bootstrap:
348 info = bootstrap['msnbcThePlatform']['videoPlayer']['video']
353 video_id = info['guid']
354 filter_param = 'byGuid'
355 elif 'mpxId' in info:
356 video_id = info['mpxId']
359 '_type': 'url_transparent',
361 # http://feed.theplatform.com/f/2E2eJC/nbcnews also works
362 'url': update_url_query('http://feed.theplatform.com/f/2E2eJC/nnd_NBCNews', {filter_param: video_id}),
363 'ie_key': 'ThePlatformFeed',
367 class NBCOlympicsIE(InfoExtractor):
368 IE_NAME = 'nbcolympics'
369 _VALID_URL = r'https?://www\.nbcolympics\.com/video/(?P<id>[a-z-]+)'
372 # Geo-restricted to US
373 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold',
374 'md5': '54fecf846d05429fbaa18af557ee523a',
376 'id': 'WjTBzDXx5AUq',
377 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold',
379 'title': 'Rose\'s son Leo was in tears after his dad won gold',
380 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.',
381 'timestamp': 1471274964,
382 'upload_date': '20160815',
383 'uploader': 'NBCU-SPORTS',
387 def _real_extract(self, url):
388 display_id = self._match_id(url)
390 webpage = self._download_webpage(url, display_id)
392 drupal_settings = self._parse_json(self._search_regex(
393 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
394 webpage, 'drupal settings'), display_id)
396 iframe_url = drupal_settings['vod']['iframe_url']
397 theplatform_url = iframe_url.replace(
398 'vplayer.nbcolympics.com', 'player.theplatform.com')
401 '_type': 'url_transparent',
402 'url': theplatform_url,
403 'ie_key': ThePlatformIE.ie_key(),
404 'display_id': display_id,
408 class NBCOlympicsStreamIE(AdobePassIE):
409 IE_NAME = 'nbcolympics:stream'
410 _VALID_URL = r'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)'
412 'url': 'http://stream.nbcolympics.com/2018-winter-olympics-nbcsn-evening-feb-8',
416 'title': 're:Curling, Alpine, Luge [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
420 'skip_download': True,
423 _DATA_URL_TEMPLATE = 'http://stream.nbcolympics.com/data/%s_%s.json'
425 def _real_extract(self, url):
426 display_id = self._match_id(url)
427 webpage = self._download_webpage(url, display_id)
428 pid = self._search_regex(r'pid\s*=\s*(\d+);', webpage, 'pid')
429 resource = self._search_regex(
430 r"resource\s*=\s*'(.+)';", webpage,
431 'resource').replace("' + pid + '", pid)
432 event_config = self._download_json(
433 self._DATA_URL_TEMPLATE % ('event_config', pid),
435 title = self._live_title(event_config['eventTitle'])
436 source_url = self._download_json(
437 self._DATA_URL_TEMPLATE % ('live_sources', pid),
438 pid)['videoSources'][0]['sourceUrl']
439 media_token = self._extract_mvpd_auth(
440 url, pid, event_config.get('requestorId', 'NBCOlympics'), resource)
441 formats = self._extract_m3u8_formats(self._download_webpage(
442 'http://sp.auth.adobe.com/tvs/v1/sign', pid, query={
444 'mediaToken': base64.b64encode(media_token.encode()),
445 'resource': base64.b64encode(resource.encode()),
448 self._sort_formats(formats)
452 'display_id': display_id,