]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nbc.py
554dec36e62dc246ea314ac07f9cff6b3c1323fe
[youtubedl] / youtube_dl / extractor / nbc.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from .theplatform import ThePlatformIE
7 from .adobepass import AdobePassIE
8 from ..utils import (
9 find_xpath_attr,
10 smuggle_url,
11 unescapeHTML,
12 update_url_query,
13 int_or_none,
14 )
15
16
17 class NBCIE(AdobePassIE):
18 _VALID_URL = r'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>n?\d+))'
19
20 _TESTS = [
21 {
22 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237',
23 'info_dict': {
24 'id': '2848237',
25 'ext': 'mp4',
26 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
27 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
28 'timestamp': 1424246400,
29 'upload_date': '20150218',
30 'uploader': 'NBCU-COM',
31 },
32 'params': {
33 # m3u8 download
34 'skip_download': True,
35 },
36 },
37 {
38 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
39 'info_dict': {
40 'id': '2832821',
41 'ext': 'mp4',
42 'title': 'Star Wars Teaser',
43 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
44 'timestamp': 1417852800,
45 'upload_date': '20141206',
46 'uploader': 'NBCU-COM',
47 },
48 'params': {
49 # m3u8 download
50 'skip_download': True,
51 },
52 'skip': 'Only works from US',
53 },
54 {
55 # HLS streams requires the 'hdnea3' cookie
56 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
57 'info_dict': {
58 'id': '101528f5a9e8127b107e98c5e6ce4638',
59 'ext': 'mp4',
60 'title': 'Goliath',
61 '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.',
62 'timestamp': 1237100400,
63 'upload_date': '20090315',
64 'uploader': 'NBCU-COM',
65 },
66 'params': {
67 'skip_download': True,
68 },
69 'skip': 'Only works from US',
70 },
71 {
72 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310',
73 'only_matching': True,
74 },
75 ]
76
77 def _real_extract(self, url):
78 permalink, video_id = re.match(self._VALID_URL, url).groups()
79 permalink = 'http' + permalink
80 video_data = self._download_json(
81 'https://api.nbc.com/v3/videos', video_id, query={
82 'filter[permalink]': permalink,
83 })['data'][0]['attributes']
84 query = {
85 'mbr': 'true',
86 'manifest': 'm3u',
87 }
88 video_id = video_data['guid']
89 title = video_data['title']
90 if video_data.get('entitlement') == 'auth':
91 resource = self._get_mvpd_resource(
92 'nbcentertainment', title, video_id,
93 video_data.get('vChipRating'))
94 query['auth'] = self._extract_mvpd_auth(
95 url, video_id, 'nbcentertainment', resource)
96 theplatform_url = smuggle_url(update_url_query(
97 'http://link.theplatform.com/s/NnzsPC/media/guid/2410887629/' + video_id,
98 query), {'force_smil_url': True})
99 return {
100 '_type': 'url_transparent',
101 'id': video_id,
102 'title': title,
103 'url': theplatform_url,
104 'description': video_data.get('description'),
105 'keywords': video_data.get('keywords'),
106 'season_number': int_or_none(video_data.get('seasonNumber')),
107 'episode_number': int_or_none(video_data.get('episodeNumber')),
108 'series': video_data.get('showName'),
109 'ie_key': 'ThePlatform',
110 }
111
112
113 class NBCSportsVPlayerIE(InfoExtractor):
114 _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
115
116 _TESTS = [{
117 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI',
118 'info_dict': {
119 'id': '9CsDKds0kvHI',
120 'ext': 'mp4',
121 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
122 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
123 'timestamp': 1426270238,
124 'upload_date': '20150313',
125 'uploader': 'NBCU-SPORTS',
126 }
127 }, {
128 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/_hqLjQ95yx8Z',
129 'only_matching': True,
130 }]
131
132 @staticmethod
133 def _extract_url(webpage):
134 iframe_m = re.search(
135 r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
136 if iframe_m:
137 return iframe_m.group('url')
138
139 def _real_extract(self, url):
140 video_id = self._match_id(url)
141 webpage = self._download_webpage(url, video_id)
142 theplatform_url = self._og_search_video_url(webpage).replace(
143 'vplayer.nbcsports.com', 'player.theplatform.com')
144 return self.url_result(theplatform_url, 'ThePlatform')
145
146
147 class NBCSportsIE(InfoExtractor):
148 # Does not include https because its certificate is invalid
149 _VALID_URL = r'https?://(?:www\.)?nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
150
151 _TEST = {
152 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
153 'info_dict': {
154 'id': 'PHJSaFWbrTY9',
155 'ext': 'flv',
156 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
157 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
158 'uploader': 'NBCU-SPORTS',
159 'upload_date': '20150330',
160 'timestamp': 1427726529,
161 }
162 }
163
164 def _real_extract(self, url):
165 video_id = self._match_id(url)
166 webpage = self._download_webpage(url, video_id)
167 return self.url_result(
168 NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
169
170
171 class CSNNEIE(InfoExtractor):
172 _VALID_URL = r'https?://(?:www\.)?csnne\.com/video/(?P<id>[0-9a-z-]+)'
173
174 _TEST = {
175 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
176 'info_dict': {
177 'id': 'yvBLLUgQ8WU0',
178 'ext': 'mp4',
179 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
180 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
181 'timestamp': 1459369979,
182 'upload_date': '20160330',
183 'uploader': 'NBCU-SPORTS',
184 }
185 }
186
187 def _real_extract(self, url):
188 display_id = self._match_id(url)
189 webpage = self._download_webpage(url, display_id)
190 return {
191 '_type': 'url_transparent',
192 'ie_key': 'ThePlatform',
193 'url': self._html_search_meta('twitter:player:stream', webpage),
194 'display_id': display_id,
195 }
196
197
198 class NBCNewsIE(ThePlatformIE):
199 _VALID_URL = r'''(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/
200 (?:video/.+?/(?P<id>\d+)|
201 ([^/]+/)*(?:.*-)?(?P<mpx_id>[^/?]+))
202 '''
203
204 _TESTS = [
205 {
206 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
207 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
208 'info_dict': {
209 'id': '52753292',
210 'ext': 'flv',
211 'title': 'Crew emerges after four-month Mars food study',
212 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
213 },
214 },
215 {
216 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
217 'md5': 'af1adfa51312291a017720403826bb64',
218 'info_dict': {
219 'id': 'p_tweet_snow_140529',
220 'ext': 'mp4',
221 'title': 'How Twitter Reacted To The Snowden Interview',
222 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
223 'uploader': 'NBCU-NEWS',
224 'timestamp': 1401363060,
225 'upload_date': '20140529',
226 },
227 },
228 {
229 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
230 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
231 'info_dict': {
232 'id': '529953347624',
233 'ext': 'mp4',
234 'title': 'FULL EPISODE: Family Business',
235 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
236 },
237 'skip': 'This page is unavailable.',
238 },
239 {
240 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
241 'md5': '73135a2e0ef819107bbb55a5a9b2a802',
242 'info_dict': {
243 'id': 'nn_netcast_150204',
244 'ext': 'mp4',
245 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
246 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
247 'timestamp': 1423104900,
248 'uploader': 'NBCU-NEWS',
249 'upload_date': '20150205',
250 },
251 },
252 {
253 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
254 'md5': 'a49e173825e5fcd15c13fc297fced39d',
255 'info_dict': {
256 'id': 'x_lon_vwhorn_150922',
257 'ext': 'mp4',
258 'title': 'Volkswagen U.S. Chief:\xa0 We Have Totally Screwed Up',
259 'description': 'md5:c8be487b2d80ff0594c005add88d8351',
260 'upload_date': '20150922',
261 'timestamp': 1442917800,
262 'uploader': 'NBCU-NEWS',
263 },
264 },
265 {
266 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
267 'md5': '118d7ca3f0bea6534f119c68ef539f71',
268 'info_dict': {
269 'id': 'tdy_al_space_160420',
270 'ext': 'mp4',
271 'title': 'See the aurora borealis from space in stunning new NASA video',
272 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
273 'upload_date': '20160420',
274 'timestamp': 1461152093,
275 'uploader': 'NBCU-NEWS',
276 },
277 },
278 {
279 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
280 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
281 'info_dict': {
282 'id': 'n_hayes_Aimm_140801_272214',
283 'ext': 'mp4',
284 'title': 'The chaotic GOP immigration vote',
285 '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.',
286 'thumbnail': r're:^https?://.*\.jpg$',
287 'timestamp': 1406937606,
288 'upload_date': '20140802',
289 'uploader': 'NBCU-NEWS',
290 },
291 },
292 {
293 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
294 'only_matching': True,
295 },
296 {
297 # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
298 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
299 'only_matching': True,
300 },
301 ]
302
303 def _real_extract(self, url):
304 mobj = re.match(self._VALID_URL, url)
305 video_id = mobj.group('id')
306 if video_id is not None:
307 all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
308 info = all_info.find('video')
309
310 return {
311 'id': video_id,
312 'title': info.find('headline').text,
313 'ext': 'flv',
314 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
315 'description': info.find('caption').text,
316 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
317 }
318 else:
319 # "feature" and "nightly-news" pages use theplatform.com
320 video_id = mobj.group('mpx_id')
321 webpage = self._download_webpage(url, video_id)
322
323 filter_param = 'byId'
324 bootstrap_json = self._search_regex(
325 [r'(?m)(?:var\s+(?:bootstrapJson|playlistData)|NEWS\.videoObj)\s*=\s*({.+});?\s*$',
326 r'videoObj\s*:\s*({.+})', r'data-video="([^"]+)"',
327 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);'],
328 webpage, 'bootstrap json', default=None)
329 if bootstrap_json:
330 bootstrap = self._parse_json(
331 bootstrap_json, video_id, transform_source=unescapeHTML)
332
333 info = None
334 if 'results' in bootstrap:
335 info = bootstrap['results'][0]['video']
336 elif 'video' in bootstrap:
337 info = bootstrap['video']
338 elif 'msnbcVideoInfo' in bootstrap:
339 info = bootstrap['msnbcVideoInfo']['meta']
340 elif 'msnbcThePlatform' in bootstrap:
341 info = bootstrap['msnbcThePlatform']['videoPlayer']['video']
342 else:
343 info = bootstrap
344
345 if 'guid' in info:
346 video_id = info['guid']
347 filter_param = 'byGuid'
348 elif 'mpxId' in info:
349 video_id = info['mpxId']
350
351 return {
352 '_type': 'url_transparent',
353 'id': video_id,
354 # http://feed.theplatform.com/f/2E2eJC/nbcnews also works
355 'url': update_url_query('http://feed.theplatform.com/f/2E2eJC/nnd_NBCNews', {filter_param: video_id}),
356 'ie_key': 'ThePlatformFeed',
357 }
358
359
360 class NBCOlympicsIE(InfoExtractor):
361 _VALID_URL = r'https?://www\.nbcolympics\.com/video/(?P<id>[a-z-]+)'
362
363 _TEST = {
364 # Geo-restricted to US
365 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold',
366 'md5': '54fecf846d05429fbaa18af557ee523a',
367 'info_dict': {
368 'id': 'WjTBzDXx5AUq',
369 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold',
370 'ext': 'mp4',
371 'title': 'Rose\'s son Leo was in tears after his dad won gold',
372 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.',
373 'timestamp': 1471274964,
374 'upload_date': '20160815',
375 'uploader': 'NBCU-SPORTS',
376 },
377 }
378
379 def _real_extract(self, url):
380 display_id = self._match_id(url)
381
382 webpage = self._download_webpage(url, display_id)
383
384 drupal_settings = self._parse_json(self._search_regex(
385 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
386 webpage, 'drupal settings'), display_id)
387
388 iframe_url = drupal_settings['vod']['iframe_url']
389 theplatform_url = iframe_url.replace(
390 'vplayer.nbcolympics.com', 'player.theplatform.com')
391
392 return {
393 '_type': 'url_transparent',
394 'url': theplatform_url,
395 'ie_key': ThePlatformIE.ie_key(),
396 'display_id': display_id,
397 }