1 from __future__ import unicode_literals
5 from .common import InfoExtractor
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',
25 # md5 checksum is not stable
29 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
30 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
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': 'Only works from US',
44 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
48 'title': 'Star Wars Teaser',
49 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
51 'skip': 'Only works from US',
54 # This video has expired but with an escaped embedURL
55 'url': 'http://www.nbc.com/parenthood/episode-guide/season-5/just-like-at-home/515',
60 def _real_extract(self, url):
61 video_id = self._match_id(url)
62 webpage = self._download_webpage(url, video_id)
63 theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
65 r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
66 r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
67 r'"embedURL"\s*:\s*"([^"]+)"'
69 webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
70 if theplatform_url.startswith('//'):
71 theplatform_url = 'http:' + theplatform_url
72 return self.url_result(smuggle_url(theplatform_url, {'source_url': url}))
75 class NBCSportsVPlayerIE(InfoExtractor):
76 _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
79 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
83 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
84 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
87 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
88 'only_matching': True,
92 def _extract_url(webpage):
94 r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
96 return iframe_m.group('url')
98 def _real_extract(self, url):
99 video_id = self._match_id(url)
100 webpage = self._download_webpage(url, video_id)
101 theplatform_url = self._og_search_video_url(webpage)
102 return self.url_result(theplatform_url, 'ThePlatform')
105 class NBCSportsIE(InfoExtractor):
106 # Does not include https becuase its certificate is invalid
107 _VALID_URL = r'http://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
110 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
112 'id': 'PHJSaFWbrTY9',
114 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
115 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
119 def _real_extract(self, url):
120 video_id = self._match_id(url)
121 webpage = self._download_webpage(url, video_id)
122 return self.url_result(
123 NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
126 class NBCNewsIE(InfoExtractor):
127 _VALID_URL = r'''(?x)https?://(?:www\.)?nbcnews\.com/
128 (?:video/.+?/(?P<id>\d+)|
129 (?:watch|feature|nightly-news)/[^/]+/(?P<title>.+))
134 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
135 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
139 'title': 'Crew emerges after four-month Mars food study',
140 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
144 'url': 'http://www.nbcnews.com/feature/edward-snowden-interview/how-twitter-reacted-snowden-interview-n117236',
145 'md5': 'b2421750c9f260783721d898f4c42063',
147 'id': 'I1wpAI_zmhsQ',
149 'title': 'How Twitter Reacted To The Snowden Interview',
150 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
152 'add_ie': ['ThePlatform'],
155 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
156 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
158 'id': 'Wjf9EDR3A_60',
160 'title': 'FULL EPISODE: Family Business',
161 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
165 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
166 'md5': 'b5dda8cddd8650baa0dcb616dd2cf60d',
168 'id': 'sekXqyTVnmN3',
170 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
171 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
175 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
176 'only_matching': True,
180 def _real_extract(self, url):
181 mobj = re.match(self._VALID_URL, url)
182 video_id = mobj.group('id')
183 if video_id is not None:
184 all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
185 info = all_info.find('video')
189 'title': info.find('headline').text,
191 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
192 'description': compat_str(info.find('caption').text),
193 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
196 # "feature" and "nightly-news" pages use theplatform.com
197 title = mobj.group('title')
198 webpage = self._download_webpage(url, title)
199 bootstrap_json = self._search_regex(
200 r'var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
201 webpage, 'bootstrap json', flags=re.MULTILINE)
202 bootstrap = self._parse_json(bootstrap_json, video_id)
203 info = bootstrap['results'][0]['video']
204 mpxid = info['mpxId']
207 info['fallbackPlaylistUrl'],
208 info['associatedPlaylistUrl'],
211 for base_url in base_urls:
214 playlist_url = base_url + '?form=MPXNBCNewsAPI'
217 all_videos = self._download_json(playlist_url, title)
218 except ExtractorError as ee:
219 if isinstance(ee.cause, compat_HTTPError):
223 if not all_videos or 'videos' not in all_videos:
227 info = next(v for v in all_videos['videos'] if v['mpxId'] == mpxid)
229 except StopIteration:
233 raise ExtractorError('Could not find video in playlists')
237 # We get the best quality video
238 'url': info['videoAssets'][-1]['publicUrl'],
239 'ie_key': 'ThePlatform',
243 class MSNBCIE(InfoExtractor):
244 # https URLs redirect to corresponding http ones
245 _VALID_URL = r'http://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
247 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
248 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
250 'id': 'n_hayes_Aimm_140801_272214',
252 'title': 'The chaotic GOP immigration vote',
253 '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.',
254 'thumbnail': 're:^https?://.*\.jpg$',
255 'timestamp': 1406937606,
256 'upload_date': '20140802',
257 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
261 def _real_extract(self, url):
262 video_id = self._match_id(url)
263 webpage = self._download_webpage(url, video_id)
264 embed_url = self._html_search_meta('embedURL', webpage)
265 return self.url_result(embed_url)