1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from .theplatform import ThePlatformIE
19 class NBCIE(InfoExtractor):
20 _VALID_URL = r'https?://www\.nbc\.com/(?:[^/]+/)+(?P<id>n?\d+)'
24 'url': 'http://www.nbc.com/the-tonight-show/segments/112966',
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/the-tonight-show/episodes/176',
44 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen',
45 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.',
47 'skip': '404 Not Found',
50 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
54 'title': 'Star Wars Teaser',
55 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
56 'timestamp': 1417852800,
57 'upload_date': '20141206',
58 'uploader': 'NBCU-COM',
62 'skip_download': True,
64 'skip': 'Only works from US',
67 # This video has expired but with an escaped embedURL
68 'url': 'http://www.nbc.com/parenthood/episode-guide/season-5/just-like-at-home/515',
69 'only_matching': True,
72 # HLS streams requires the 'hdnea3' cookie
73 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
78 '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.',
79 'timestamp': 1237100400,
80 'upload_date': '20090315',
81 'uploader': 'NBCU-COM',
84 'skip_download': True,
86 'skip': 'Only works from US',
90 def _real_extract(self, url):
91 video_id = self._match_id(url)
92 webpage = self._download_webpage(url, video_id)
93 theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
95 r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
96 r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
97 r'"embedURL"\s*:\s*"([^"]+)"'
99 webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
100 if theplatform_url.startswith('//'):
101 theplatform_url = 'http:' + theplatform_url
103 '_type': 'url_transparent',
104 'ie_key': 'ThePlatform',
105 'url': smuggle_url(theplatform_url, {'source_url': url}),
110 class NBCSportsVPlayerIE(InfoExtractor):
111 _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
114 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
116 'id': '9CsDKds0kvHI',
118 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
119 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
120 'timestamp': 1426270238,
121 'upload_date': '20150313',
122 'uploader': 'NBCU-SPORTS',
125 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
126 'only_matching': True,
130 def _extract_url(webpage):
131 iframe_m = re.search(
132 r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
134 return iframe_m.group('url')
136 def _real_extract(self, url):
137 video_id = self._match_id(url)
138 webpage = self._download_webpage(url, video_id)
139 theplatform_url = self._og_search_video_url(webpage)
140 return self.url_result(theplatform_url, 'ThePlatform')
143 class NBCSportsIE(InfoExtractor):
144 # Does not include https because its certificate is invalid
145 _VALID_URL = r'https?://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
148 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
150 'id': 'PHJSaFWbrTY9',
152 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
153 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
154 'uploader': 'NBCU-SPORTS',
155 'upload_date': '20150330',
156 'timestamp': 1427726529,
160 def _real_extract(self, url):
161 video_id = self._match_id(url)
162 webpage = self._download_webpage(url, video_id)
163 return self.url_result(
164 NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
167 class CSNNEIE(InfoExtractor):
168 _VALID_URL = r'https?://www\.csnne\.com/video/(?P<id>[0-9a-z-]+)'
171 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
173 'id': 'yvBLLUgQ8WU0',
175 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
176 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
177 'timestamp': 1459369979,
178 'upload_date': '20160330',
179 'uploader': 'NBCU-SPORTS',
183 def _real_extract(self, url):
184 display_id = self._match_id(url)
185 webpage = self._download_webpage(url, display_id)
187 '_type': 'url_transparent',
188 'ie_key': 'ThePlatform',
189 'url': self._html_search_meta('twitter:player:stream', webpage),
190 'display_id': display_id,
194 class NBCNewsIE(ThePlatformIE):
195 _VALID_URL = r'''(?x)https?://(?:www\.)?(?:nbcnews|today)\.com/
196 (?:video/.+?/(?P<id>\d+)|
197 ([^/]+/)*(?P<display_id>[^/?]+))
202 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
203 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
207 'title': 'Crew emerges after four-month Mars food study',
208 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
212 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
213 'md5': 'af1adfa51312291a017720403826bb64',
215 'id': '269389891880',
217 'title': 'How Twitter Reacted To The Snowden Interview',
218 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
222 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
223 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
225 'id': 'Wjf9EDR3A_60',
227 'title': 'FULL EPISODE: Family Business',
228 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
230 'skip': 'This page is unavailable.',
233 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
234 'md5': '73135a2e0ef819107bbb55a5a9b2a802',
236 'id': '394064451844',
238 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
239 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
243 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
244 'md5': 'a49e173825e5fcd15c13fc297fced39d',
246 'id': '529953347624',
248 'title': 'Volkswagen U.S. Chief: We \'Totally Screwed Up\'',
249 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
251 'expected_warnings': ['http-6000 is not available']
254 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
255 'md5': '118d7ca3f0bea6534f119c68ef539f71',
257 'id': '669831235788',
259 'title': 'See the aurora borealis from space in stunning new NASA video',
260 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
261 'upload_date': '20160420',
262 'timestamp': 1461152093,
266 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
267 'only_matching': True,
271 def _real_extract(self, url):
272 mobj = re.match(self._VALID_URL, url)
273 video_id = mobj.group('id')
274 if video_id is not None:
275 all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
276 info = all_info.find('video')
280 'title': info.find('headline').text,
282 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
283 'description': info.find('caption').text,
284 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
287 # "feature" and "nightly-news" pages use theplatform.com
288 display_id = mobj.group('display_id')
289 webpage = self._download_webpage(url, display_id)
291 bootstrap_json = self._search_regex(
292 r'(?m)var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
293 webpage, 'bootstrap json', default=None)
295 bootstrap = self._parse_json(bootstrap_json, display_id)
296 info = bootstrap['results'][0]['video']
298 player_instance_json = self._search_regex(
299 r'videoObj\s*:\s*({.+})', webpage, 'player instance', default=None)
300 if not player_instance_json:
301 player_instance_json = self._html_search_regex(
302 r'data-video="([^"]+)"', webpage, 'video json')
303 info = self._parse_json(player_instance_json, display_id)
304 video_id = info['mpxId']
305 title = info['title']
308 caption_links = info.get('captionLinks')
310 for (sub_key, sub_ext) in (('smpte-tt', 'ttml'), ('web-vtt', 'vtt'), ('srt', 'srt')):
311 sub_url = caption_links.get(sub_key)
313 subtitles.setdefault('en', []).append({
319 for video_asset in info['videoAssets']:
320 video_url = video_asset.get('publicUrl')
323 container = video_asset.get('format')
324 asset_type = video_asset.get('assetType') or ''
325 if container == 'ISM' or asset_type == 'FireTV-Once':
327 elif asset_type == 'OnceURL':
328 tp_formats, tp_subtitles = self._extract_theplatform_smil(
330 formats.extend(tp_formats)
331 subtitles = self._merge_subtitles(subtitles, tp_subtitles)
333 tbr = int_or_none(video_asset.get('bitRate') or video_asset.get('bitrate'), 1000)
334 format_id = 'http%s' % ('-%d' % tbr if tbr else '')
335 video_url = update_url_query(
336 video_url, {'format': 'redirect'})
337 # resolve the url so that we can check availability and detect the correct extension
338 head = self._request_webpage(
339 HEADRequest(video_url), video_id,
340 'Checking %s url' % format_id,
341 '%s is not available' % format_id,
344 video_url = head.geturl()
346 'format_id': format_id,
348 'width': int_or_none(video_asset.get('width')),
349 'height': int_or_none(video_asset.get('height')),
351 'container': video_asset.get('format'),
353 self._sort_formats(formats)
358 'description': info.get('description'),
359 'thumbnail': info.get('thumbnail'),
360 'duration': int_or_none(info.get('duration')),
361 'timestamp': parse_iso8601(info.get('pubDate') or info.get('pub_date')),
363 'subtitles': subtitles,
367 class MSNBCIE(InfoExtractor):
368 # https URLs redirect to corresponding http ones
369 _VALID_URL = r'https?://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
371 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
372 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
374 'id': 'n_hayes_Aimm_140801_272214',
376 'title': 'The chaotic GOP immigration vote',
377 '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.',
378 'thumbnail': 're:^https?://.*\.jpg$',
379 'timestamp': 1406937606,
380 'upload_date': '20140802',
381 'uploader': 'NBCU-NEWS',
382 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
386 def _real_extract(self, url):
387 video_id = self._match_id(url)
388 webpage = self._download_webpage(url, video_id)
389 embed_url = self._html_search_meta('embedURL', webpage)
390 return self.url_result(embed_url)