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.',
33 'skip_download': True,
37 'url': 'http://www.nbc.com/the-tonight-show/episodes/176',
41 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen',
42 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.',
44 'skip': '404 Not Found',
47 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
51 'title': 'Star Wars Teaser',
52 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
56 'skip_download': True,
58 'skip': 'Only works from US',
61 # This video has expired but with an escaped embedURL
62 'url': 'http://www.nbc.com/parenthood/episode-guide/season-5/just-like-at-home/515',
63 'only_matching': True,
67 def _real_extract(self, url):
68 video_id = self._match_id(url)
69 webpage = self._download_webpage(url, video_id)
70 theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
72 r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
73 r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
74 r'"embedURL"\s*:\s*"([^"]+)"'
76 webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
77 if theplatform_url.startswith('//'):
78 theplatform_url = 'http:' + theplatform_url
80 '_type': 'url_transparent',
81 'url': smuggle_url(theplatform_url, {'source_url': url}),
86 class NBCSportsVPlayerIE(InfoExtractor):
87 _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
90 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
94 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
95 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
98 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
99 'only_matching': True,
103 def _extract_url(webpage):
104 iframe_m = re.search(
105 r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
107 return iframe_m.group('url')
109 def _real_extract(self, url):
110 video_id = self._match_id(url)
111 webpage = self._download_webpage(url, video_id)
112 theplatform_url = self._og_search_video_url(webpage)
113 return self.url_result(theplatform_url, 'ThePlatform')
116 class NBCSportsIE(InfoExtractor):
117 # Does not include https because its certificate is invalid
118 _VALID_URL = r'https?://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
121 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
123 'id': 'PHJSaFWbrTY9',
125 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
126 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
130 def _real_extract(self, url):
131 video_id = self._match_id(url)
132 webpage = self._download_webpage(url, video_id)
133 return self.url_result(
134 NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
137 class CSNNEIE(InfoExtractor):
138 _VALID_URL = r'https?://www\.csnne\.com/video/(?P<id>[0-9a-z-]+)'
141 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
143 'id': 'yvBLLUgQ8WU0',
145 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
146 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
150 def _real_extract(self, url):
151 display_id = self._match_id(url)
152 webpage = self._download_webpage(url, display_id)
154 '_type': 'url_transparent',
155 'ie_key': 'ThePlatform',
156 'url': self._html_search_meta('twitter:player:stream', webpage),
157 'display_id': display_id,
161 class NBCNewsIE(ThePlatformIE):
162 _VALID_URL = r'''(?x)https?://(?:www\.)?nbcnews\.com/
163 (?:video/.+?/(?P<id>\d+)|
164 ([^/]+/)*(?P<display_id>[^/?]+))
169 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
170 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
174 'title': 'Crew emerges after four-month Mars food study',
175 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
179 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
180 'md5': 'af1adfa51312291a017720403826bb64',
182 'id': '269389891880',
184 'title': 'How Twitter Reacted To The Snowden Interview',
185 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
189 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
190 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
192 'id': 'Wjf9EDR3A_60',
194 'title': 'FULL EPISODE: Family Business',
195 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
197 'skip': 'This page is unavailable.',
200 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
201 'md5': '73135a2e0ef819107bbb55a5a9b2a802',
203 'id': '394064451844',
205 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
206 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
210 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
211 'md5': 'a49e173825e5fcd15c13fc297fced39d',
213 'id': '529953347624',
215 'title': 'Volkswagen U.S. Chief: We \'Totally Screwed Up\'',
216 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
218 'expected_warnings': ['http-6000 is not available']
221 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
222 'only_matching': True,
226 def _real_extract(self, url):
227 mobj = re.match(self._VALID_URL, url)
228 video_id = mobj.group('id')
229 if video_id is not None:
230 all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
231 info = all_info.find('video')
235 'title': info.find('headline').text,
237 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
238 'description': info.find('caption').text,
239 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
242 # "feature" and "nightly-news" pages use theplatform.com
243 display_id = mobj.group('display_id')
244 webpage = self._download_webpage(url, display_id)
246 bootstrap_json = self._search_regex(
247 r'(?m)var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
248 webpage, 'bootstrap json', default=None)
250 bootstrap = self._parse_json(bootstrap_json, display_id)
251 info = bootstrap['results'][0]['video']
253 player_instance_json = self._search_regex(
254 r'videoObj\s*:\s*({.+})', webpage, 'player instance')
255 info = self._parse_json(player_instance_json, display_id)
256 video_id = info['mpxId']
257 title = info['title']
260 caption_links = info.get('captionLinks')
262 for (sub_key, sub_ext) in (('smpte-tt', 'ttml'), ('web-vtt', 'vtt'), ('srt', 'srt')):
263 sub_url = caption_links.get(sub_key)
265 subtitles.setdefault('en', []).append({
271 for video_asset in info['videoAssets']:
272 video_url = video_asset.get('publicUrl')
275 container = video_asset.get('format')
276 asset_type = video_asset.get('assetType') or ''
277 if container == 'ISM' or asset_type == 'FireTV-Once':
279 elif asset_type == 'OnceURL':
280 tp_formats, tp_subtitles = self._extract_theplatform_smil(
282 formats.extend(tp_formats)
283 subtitles = self._merge_subtitles(subtitles, tp_subtitles)
285 tbr = int_or_none(video_asset.get('bitRate'), 1000)
286 format_id = 'http%s' % ('-%d' % tbr if tbr else '')
287 video_url = update_url_query(
288 video_url, {'format': 'redirect'})
289 # resolve the url so that we can check availability and detect the correct extension
290 head = self._request_webpage(
291 HEADRequest(video_url), video_id,
292 'Checking %s url' % format_id,
293 '%s is not available' % format_id,
296 video_url = head.geturl()
298 'format_id': format_id,
300 'width': int_or_none(video_asset.get('width')),
301 'height': int_or_none(video_asset.get('height')),
303 'container': video_asset.get('format'),
305 self._sort_formats(formats)
310 'description': info.get('description'),
311 'thumbnail': info.get('description'),
312 'thumbnail': info.get('thumbnail'),
313 'duration': int_or_none(info.get('duration')),
314 'timestamp': parse_iso8601(info.get('pubDate')),
316 'subtitles': subtitles,
320 class MSNBCIE(InfoExtractor):
321 # https URLs redirect to corresponding http ones
322 _VALID_URL = r'https?://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
324 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
325 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
327 'id': 'n_hayes_Aimm_140801_272214',
329 'title': 'The chaotic GOP immigration vote',
330 '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.',
331 'thumbnail': 're:^https?://.*\.jpg$',
332 'timestamp': 1406937606,
333 'upload_date': '20140802',
334 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
338 def _real_extract(self, url):
339 video_id = self._match_id(url)
340 webpage = self._download_webpage(url, video_id)
341 embed_url = self._html_search_meta('embedURL', webpage)
342 return self.url_result(embed_url)