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,
73 def _real_extract(self, url):
74 video_id = self._match_id(url)
75 webpage = self._download_webpage(url, video_id)
76 theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
78 r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
79 r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
80 r'"embedURL"\s*:\s*"([^"]+)"'
82 webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
83 if theplatform_url.startswith('//'):
84 theplatform_url = 'http:' + theplatform_url
86 '_type': 'url_transparent',
87 'ie_key': 'ThePlatform',
88 'url': smuggle_url(theplatform_url, {'source_url': url}),
93 class NBCSportsVPlayerIE(InfoExtractor):
94 _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
97 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
101 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
102 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
103 'timestamp': 1426270238,
104 'upload_date': '20150313',
105 'uploader': 'NBCU-SPORTS',
108 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
109 'only_matching': True,
113 def _extract_url(webpage):
114 iframe_m = re.search(
115 r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
117 return iframe_m.group('url')
119 def _real_extract(self, url):
120 video_id = self._match_id(url)
121 webpage = self._download_webpage(url, video_id)
122 theplatform_url = self._og_search_video_url(webpage)
123 return self.url_result(theplatform_url, 'ThePlatform')
126 class NBCSportsIE(InfoExtractor):
127 # Does not include https because its certificate is invalid
128 _VALID_URL = r'https?://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
131 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
133 'id': 'PHJSaFWbrTY9',
135 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
136 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
140 def _real_extract(self, url):
141 video_id = self._match_id(url)
142 webpage = self._download_webpage(url, video_id)
143 return self.url_result(
144 NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
147 class CSNNEIE(InfoExtractor):
148 _VALID_URL = r'https?://www\.csnne\.com/video/(?P<id>[0-9a-z-]+)'
151 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
153 'id': 'yvBLLUgQ8WU0',
155 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
156 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
157 'timestamp': 1459369979,
158 'upload_date': '20160330',
159 'uploader': 'NBCU-SPORTS',
163 def _real_extract(self, url):
164 display_id = self._match_id(url)
165 webpage = self._download_webpage(url, display_id)
167 '_type': 'url_transparent',
168 'ie_key': 'ThePlatform',
169 'url': self._html_search_meta('twitter:player:stream', webpage),
170 'display_id': display_id,
174 class NBCNewsIE(ThePlatformIE):
175 _VALID_URL = r'''(?x)https?://(?:www\.)?nbcnews\.com/
176 (?:video/.+?/(?P<id>\d+)|
177 ([^/]+/)*(?P<display_id>[^/?]+))
182 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
183 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
187 'title': 'Crew emerges after four-month Mars food study',
188 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
192 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
193 'md5': 'af1adfa51312291a017720403826bb64',
195 'id': '269389891880',
197 'title': 'How Twitter Reacted To The Snowden Interview',
198 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
202 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
203 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
205 'id': 'Wjf9EDR3A_60',
207 'title': 'FULL EPISODE: Family Business',
208 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
210 'skip': 'This page is unavailable.',
213 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
214 'md5': '73135a2e0ef819107bbb55a5a9b2a802',
216 'id': '394064451844',
218 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
219 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
223 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
224 'md5': 'a49e173825e5fcd15c13fc297fced39d',
226 'id': '529953347624',
228 'title': 'Volkswagen U.S. Chief: We \'Totally Screwed Up\'',
229 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
231 'expected_warnings': ['http-6000 is not available']
234 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
235 'only_matching': True,
239 def _real_extract(self, url):
240 mobj = re.match(self._VALID_URL, url)
241 video_id = mobj.group('id')
242 if video_id is not None:
243 all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
244 info = all_info.find('video')
248 'title': info.find('headline').text,
250 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
251 'description': info.find('caption').text,
252 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
255 # "feature" and "nightly-news" pages use theplatform.com
256 display_id = mobj.group('display_id')
257 webpage = self._download_webpage(url, display_id)
259 bootstrap_json = self._search_regex(
260 r'(?m)var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
261 webpage, 'bootstrap json', default=None)
263 bootstrap = self._parse_json(bootstrap_json, display_id)
264 info = bootstrap['results'][0]['video']
266 player_instance_json = self._search_regex(
267 r'videoObj\s*:\s*({.+})', webpage, 'player instance')
268 info = self._parse_json(player_instance_json, display_id)
269 video_id = info['mpxId']
270 title = info['title']
273 caption_links = info.get('captionLinks')
275 for (sub_key, sub_ext) in (('smpte-tt', 'ttml'), ('web-vtt', 'vtt'), ('srt', 'srt')):
276 sub_url = caption_links.get(sub_key)
278 subtitles.setdefault('en', []).append({
284 for video_asset in info['videoAssets']:
285 video_url = video_asset.get('publicUrl')
288 container = video_asset.get('format')
289 asset_type = video_asset.get('assetType') or ''
290 if container == 'ISM' or asset_type == 'FireTV-Once':
292 elif asset_type == 'OnceURL':
293 tp_formats, tp_subtitles = self._extract_theplatform_smil(
295 formats.extend(tp_formats)
296 subtitles = self._merge_subtitles(subtitles, tp_subtitles)
298 tbr = int_or_none(video_asset.get('bitRate'), 1000)
299 format_id = 'http%s' % ('-%d' % tbr if tbr else '')
300 video_url = update_url_query(
301 video_url, {'format': 'redirect'})
302 # resolve the url so that we can check availability and detect the correct extension
303 head = self._request_webpage(
304 HEADRequest(video_url), video_id,
305 'Checking %s url' % format_id,
306 '%s is not available' % format_id,
309 video_url = head.geturl()
311 'format_id': format_id,
313 'width': int_or_none(video_asset.get('width')),
314 'height': int_or_none(video_asset.get('height')),
316 'container': video_asset.get('format'),
318 self._sort_formats(formats)
323 'description': info.get('description'),
324 'thumbnail': info.get('description'),
325 'thumbnail': info.get('thumbnail'),
326 'duration': int_or_none(info.get('duration')),
327 'timestamp': parse_iso8601(info.get('pubDate')),
329 'subtitles': subtitles,
333 class MSNBCIE(InfoExtractor):
334 # https URLs redirect to corresponding http ones
335 _VALID_URL = r'https?://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
337 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
338 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
340 'id': 'n_hayes_Aimm_140801_272214',
342 'title': 'The chaotic GOP immigration vote',
343 '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.',
344 'thumbnail': 're:^https?://.*\.jpg$',
345 'timestamp': 1406937606,
346 'upload_date': '20140802',
347 'uploader': 'NBCU-NEWS',
348 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
352 def _real_extract(self, url):
353 video_id = self._match_id(url)
354 webpage = self._download_webpage(url, video_id)
355 embed_url = self._html_search_meta('embedURL', webpage)
356 return self.url_result(embed_url)