1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_HTTPError
16 class NBCIE(InfoExtractor):
17 _VALID_URL = r'https?://www\.nbc\.com/(?:[^/]+/)+(?P<id>n?\d+)'
21 'url': 'http://www.nbc.com/the-tonight-show/segments/112966',
25 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
26 '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 'skip_download': True,
34 'url': 'http://www.nbc.com/the-tonight-show/episodes/176',
38 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen',
39 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.',
41 'skip': '404 Not Found',
44 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
48 'title': 'Star Wars Teaser',
49 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
53 'skip_download': True,
55 'skip': 'Only works from US',
58 # This video has expired but with an escaped embedURL
59 'url': 'http://www.nbc.com/parenthood/episode-guide/season-5/just-like-at-home/515',
60 'only_matching': True,
64 def _real_extract(self, url):
65 video_id = self._match_id(url)
66 webpage = self._download_webpage(url, video_id)
67 theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
69 r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
70 r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
71 r'"embedURL"\s*:\s*"([^"]+)"'
73 webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
74 if theplatform_url.startswith('//'):
75 theplatform_url = 'http:' + theplatform_url
77 '_type': 'url_transparent',
78 'url': smuggle_url(theplatform_url, {'source_url': url}),
83 class NBCSportsVPlayerIE(InfoExtractor):
84 _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
87 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
91 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
92 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
95 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
96 'only_matching': True,
100 def _extract_url(webpage):
101 iframe_m = re.search(
102 r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
104 return iframe_m.group('url')
106 def _real_extract(self, url):
107 video_id = self._match_id(url)
108 webpage = self._download_webpage(url, video_id)
109 theplatform_url = self._og_search_video_url(webpage)
110 return self.url_result(theplatform_url, 'ThePlatform')
113 class NBCSportsIE(InfoExtractor):
114 # Does not include https because its certificate is invalid
115 _VALID_URL = r'http://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
118 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
120 'id': 'PHJSaFWbrTY9',
122 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
123 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
127 def _real_extract(self, url):
128 video_id = self._match_id(url)
129 webpage = self._download_webpage(url, video_id)
130 return self.url_result(
131 NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
134 class NBCNewsIE(InfoExtractor):
135 _VALID_URL = r'''(?x)https?://(?:www\.)?nbcnews\.com/
136 (?:video/.+?/(?P<id>\d+)|
137 (?:watch|feature|nightly-news)/[^/]+/(?P<title>.+))
142 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
143 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
147 'title': 'Crew emerges after four-month Mars food study',
148 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
152 'url': 'http://www.nbcnews.com/feature/edward-snowden-interview/how-twitter-reacted-snowden-interview-n117236',
153 'md5': 'b2421750c9f260783721d898f4c42063',
155 'id': 'I1wpAI_zmhsQ',
157 'title': 'How Twitter Reacted To The Snowden Interview',
158 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
160 'add_ie': ['ThePlatform'],
163 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
164 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
166 'id': 'Wjf9EDR3A_60',
168 'title': 'FULL EPISODE: Family Business',
169 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
173 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
174 'md5': 'b5dda8cddd8650baa0dcb616dd2cf60d',
176 'id': 'sekXqyTVnmN3',
178 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
179 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
183 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
184 'only_matching': True,
188 def _real_extract(self, url):
189 mobj = re.match(self._VALID_URL, url)
190 video_id = mobj.group('id')
191 if video_id is not None:
192 all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
193 info = all_info.find('video')
197 'title': info.find('headline').text,
199 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
200 'description': info.find('caption').text,
201 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
204 # "feature" and "nightly-news" pages use theplatform.com
205 title = mobj.group('title')
206 webpage = self._download_webpage(url, title)
207 bootstrap_json = self._search_regex(
208 r'var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
209 webpage, 'bootstrap json', flags=re.MULTILINE)
210 bootstrap = self._parse_json(bootstrap_json, video_id)
211 info = bootstrap['results'][0]['video']
212 mpxid = info['mpxId']
215 info['fallbackPlaylistUrl'],
216 info['associatedPlaylistUrl'],
219 for base_url in base_urls:
222 playlist_url = base_url + '?form=MPXNBCNewsAPI'
225 all_videos = self._download_json(playlist_url, title)
226 except ExtractorError as ee:
227 if isinstance(ee.cause, compat_HTTPError):
231 if not all_videos or 'videos' not in all_videos:
235 info = next(v for v in all_videos['videos'] if v['mpxId'] == mpxid)
237 except StopIteration:
241 raise ExtractorError('Could not find video in playlists')
245 # We get the best quality video
246 'url': info['videoAssets'][-1]['publicUrl'],
247 'ie_key': 'ThePlatform',
251 class MSNBCIE(InfoExtractor):
252 # https URLs redirect to corresponding http ones
253 _VALID_URL = r'http://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
255 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
256 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
258 'id': 'n_hayes_Aimm_140801_272214',
260 'title': 'The chaotic GOP immigration vote',
261 '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.',
262 'thumbnail': 're:^https?://.*\.jpg$',
263 'timestamp': 1406937606,
264 'upload_date': '20140802',
265 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
269 def _real_extract(self, url):
270 video_id = self._match_id(url)
271 webpage = self._download_webpage(url, video_id)
272 embed_url = self._html_search_meta('embedURL', webpage)
273 return self.url_result(embed_url)