]>
Commit | Line | Data |
---|---|---|
1 | import base64 | |
2 | import json | |
3 | import re | |
4 | import xml.etree.ElementTree | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from .theplatform import ThePlatformIE, default_ns | |
8 | from .adobepass import AdobePassIE | |
9 | from ..compat import compat_urllib_parse_unquote | |
10 | from ..networking import HEADRequest | |
11 | from ..utils import ( | |
12 | ExtractorError, | |
13 | RegexNotFoundError, | |
14 | UserNotLive, | |
15 | clean_html, | |
16 | determine_ext, | |
17 | float_or_none, | |
18 | int_or_none, | |
19 | mimetype2ext, | |
20 | parse_age_limit, | |
21 | parse_duration, | |
22 | remove_end, | |
23 | smuggle_url, | |
24 | traverse_obj, | |
25 | try_get, | |
26 | unescapeHTML, | |
27 | unified_timestamp, | |
28 | update_url_query, | |
29 | url_basename, | |
30 | ) | |
31 | ||
32 | ||
33 | class NBCIE(ThePlatformIE): # XXX: Do not subclass from concrete IE | |
34 | _VALID_URL = r'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>(?:NBCE|n)?\d+))' | |
35 | ||
36 | _TESTS = [ | |
37 | { | |
38 | 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237', | |
39 | 'info_dict': { | |
40 | 'id': '2848237', | |
41 | 'ext': 'mp4', | |
42 | 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s', | |
43 | 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.', | |
44 | 'timestamp': 1424246400, | |
45 | 'upload_date': '20150218', | |
46 | 'uploader': 'NBCU-COM', | |
47 | 'episode': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s', | |
48 | 'episode_number': 86, | |
49 | 'season': 'Season 2', | |
50 | 'season_number': 2, | |
51 | 'series': 'Tonight Show: Jimmy Fallon', | |
52 | 'duration': 237.0, | |
53 | 'chapters': 'count:1', | |
54 | 'tags': 'count:4', | |
55 | 'thumbnail': r're:https?://.+\.jpg', | |
56 | 'categories': ['Series/The Tonight Show Starring Jimmy Fallon'], | |
57 | 'media_type': 'Full Episode', | |
58 | }, | |
59 | 'params': { | |
60 | 'skip_download': 'm3u8', | |
61 | }, | |
62 | }, | |
63 | { | |
64 | 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821', | |
65 | 'info_dict': { | |
66 | 'id': '2832821', | |
67 | 'ext': 'mp4', | |
68 | 'title': 'Star Wars Teaser', | |
69 | 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442', | |
70 | 'timestamp': 1417852800, | |
71 | 'upload_date': '20141206', | |
72 | 'uploader': 'NBCU-COM', | |
73 | }, | |
74 | 'skip': 'page not found', | |
75 | }, | |
76 | { | |
77 | # HLS streams requires the 'hdnea3' cookie | |
78 | 'url': 'http://www.nbc.com/Kings/video/goliath/n1806', | |
79 | 'info_dict': { | |
80 | 'id': '101528f5a9e8127b107e98c5e6ce4638', | |
81 | 'ext': 'mp4', | |
82 | 'title': 'Goliath', | |
83 | '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.', | |
84 | 'timestamp': 1237100400, | |
85 | 'upload_date': '20090315', | |
86 | 'uploader': 'NBCU-COM', | |
87 | }, | |
88 | 'skip': 'page not found', | |
89 | }, | |
90 | { | |
91 | # manifest url does not have extension | |
92 | 'url': 'https://www.nbc.com/the-golden-globe-awards/video/oprah-winfrey-receives-cecil-b-de-mille-award-at-the-2018-golden-globes/3646439', | |
93 | 'info_dict': { | |
94 | 'id': '3646439', | |
95 | 'ext': 'mp4', | |
96 | 'title': 'Oprah Winfrey Receives Cecil B. de Mille Award at the 2018 Golden Globes', | |
97 | 'episode': 'Oprah Winfrey Receives Cecil B. de Mille Award at the 2018 Golden Globes', | |
98 | 'episode_number': 1, | |
99 | 'season': 'Season 75', | |
100 | 'season_number': 75, | |
101 | 'series': 'The Golden Globe Awards', | |
102 | 'description': 'Oprah Winfrey receives the Cecil B. de Mille Award at the 75th Annual Golden Globe Awards.', | |
103 | 'uploader': 'NBCU-COM', | |
104 | 'upload_date': '20180107', | |
105 | 'timestamp': 1515312000, | |
106 | 'duration': 570.0, | |
107 | 'tags': 'count:8', | |
108 | 'thumbnail': r're:https?://.+\.jpg', | |
109 | 'chapters': 'count:1', | |
110 | }, | |
111 | 'params': { | |
112 | 'skip_download': 'm3u8', | |
113 | }, | |
114 | }, | |
115 | { | |
116 | # new video_id format | |
117 | 'url': 'https://www.nbc.com/quantum-leap/video/bens-first-leap-nbcs-quantum-leap/NBCE125189978', | |
118 | 'info_dict': { | |
119 | 'id': 'NBCE125189978', | |
120 | 'ext': 'mp4', | |
121 | 'title': 'Ben\'s First Leap | NBC\'s Quantum Leap', | |
122 | 'description': 'md5:a82762449b7ec4bb83291a7b355ebf8e', | |
123 | 'uploader': 'NBCU-COM', | |
124 | 'series': 'Quantum Leap', | |
125 | 'season': 'Season 1', | |
126 | 'season_number': 1, | |
127 | 'episode': 'Ben\'s First Leap | NBC\'s Quantum Leap', | |
128 | 'episode_number': 1, | |
129 | 'duration': 170.171, | |
130 | 'chapters': [], | |
131 | 'timestamp': 1663956155, | |
132 | 'upload_date': '20220923', | |
133 | 'tags': 'count:10', | |
134 | 'age_limit': 0, | |
135 | 'thumbnail': r're:https?://.+\.jpg', | |
136 | 'categories': ['Series/Quantum Leap 2022'], | |
137 | 'media_type': 'Highlight', | |
138 | }, | |
139 | 'params': { | |
140 | 'skip_download': 'm3u8', | |
141 | }, | |
142 | }, | |
143 | { | |
144 | 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310', | |
145 | 'only_matching': True, | |
146 | }, | |
147 | { | |
148 | # Percent escaped url | |
149 | 'url': 'https://www.nbc.com/up-all-night/video/day-after-valentine%27s-day/n2189', | |
150 | 'only_matching': True, | |
151 | } | |
152 | ] | |
153 | ||
154 | def _real_extract(self, url): | |
155 | permalink, video_id = self._match_valid_url(url).groups() | |
156 | permalink = 'http' + compat_urllib_parse_unquote(permalink) | |
157 | video_data = self._download_json( | |
158 | 'https://friendship.nbc.co/v2/graphql', video_id, query={ | |
159 | 'query': '''query bonanzaPage( | |
160 | $app: NBCUBrands! = nbc | |
161 | $name: String! | |
162 | $oneApp: Boolean | |
163 | $platform: SupportedPlatforms! = web | |
164 | $type: EntityPageType! = VIDEO | |
165 | $userId: String! | |
166 | ) { | |
167 | bonanzaPage( | |
168 | app: $app | |
169 | name: $name | |
170 | oneApp: $oneApp | |
171 | platform: $platform | |
172 | type: $type | |
173 | userId: $userId | |
174 | ) { | |
175 | metadata { | |
176 | ... on VideoPageData { | |
177 | description | |
178 | episodeNumber | |
179 | keywords | |
180 | locked | |
181 | mpxAccountId | |
182 | mpxGuid | |
183 | rating | |
184 | resourceId | |
185 | seasonNumber | |
186 | secondaryTitle | |
187 | seriesShortTitle | |
188 | } | |
189 | } | |
190 | } | |
191 | }''', | |
192 | 'variables': json.dumps({ | |
193 | 'name': permalink, | |
194 | 'oneApp': True, | |
195 | 'userId': '0', | |
196 | }), | |
197 | })['data']['bonanzaPage']['metadata'] | |
198 | query = { | |
199 | 'mbr': 'true', | |
200 | 'manifest': 'm3u', | |
201 | 'switch': 'HLSServiceSecure', | |
202 | } | |
203 | video_id = video_data['mpxGuid'] | |
204 | tp_path = 'NnzsPC/media/guid/%s/%s' % (video_data.get('mpxAccountId') or '2410887629', video_id) | |
205 | tpm = self._download_theplatform_metadata(tp_path, video_id) | |
206 | title = tpm.get('title') or video_data.get('secondaryTitle') | |
207 | if video_data.get('locked'): | |
208 | resource = self._get_mvpd_resource( | |
209 | video_data.get('resourceId') or 'nbcentertainment', | |
210 | title, video_id, video_data.get('rating')) | |
211 | query['auth'] = self._extract_mvpd_auth( | |
212 | url, video_id, 'nbcentertainment', resource) | |
213 | theplatform_url = smuggle_url(update_url_query( | |
214 | 'http://link.theplatform.com/s/NnzsPC/media/guid/%s/%s' % (video_data.get('mpxAccountId') or '2410887629', video_id), | |
215 | query), {'force_smil_url': True}) | |
216 | ||
217 | # Empty string or 0 can be valid values for these. So the check must be `is None` | |
218 | description = video_data.get('description') | |
219 | if description is None: | |
220 | description = tpm.get('description') | |
221 | episode_number = int_or_none(video_data.get('episodeNumber')) | |
222 | if episode_number is None: | |
223 | episode_number = int_or_none(tpm.get('nbcu$airOrder')) | |
224 | rating = video_data.get('rating') | |
225 | if rating is None: | |
226 | try_get(tpm, lambda x: x['ratings'][0]['rating']) | |
227 | season_number = int_or_none(video_data.get('seasonNumber')) | |
228 | if season_number is None: | |
229 | season_number = int_or_none(tpm.get('nbcu$seasonNumber')) | |
230 | series = video_data.get('seriesShortTitle') | |
231 | if series is None: | |
232 | series = tpm.get('nbcu$seriesShortTitle') | |
233 | tags = video_data.get('keywords') | |
234 | if tags is None or len(tags) == 0: | |
235 | tags = tpm.get('keywords') | |
236 | ||
237 | return { | |
238 | '_type': 'url_transparent', | |
239 | 'age_limit': parse_age_limit(rating), | |
240 | 'description': description, | |
241 | 'episode': title, | |
242 | 'episode_number': episode_number, | |
243 | 'id': video_id, | |
244 | 'ie_key': 'ThePlatform', | |
245 | 'season_number': season_number, | |
246 | 'series': series, | |
247 | 'tags': tags, | |
248 | 'title': title, | |
249 | 'url': theplatform_url, | |
250 | } | |
251 | ||
252 | ||
253 | class NBCSportsVPlayerIE(InfoExtractor): | |
254 | _VALID_URL_BASE = r'https?://(?:vplayer\.nbcsports\.com|(?:www\.)?nbcsports\.com/vplayer)/' | |
255 | _VALID_URL = _VALID_URL_BASE + r'(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)' | |
256 | _EMBED_REGEX = [r'(?:iframe[^>]+|var video|div[^>]+data-(?:mpx-)?)[sS]rc\s?=\s?"(?P<url>%s[^\"]+)' % _VALID_URL_BASE] | |
257 | ||
258 | _TESTS = [{ | |
259 | 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI', | |
260 | 'info_dict': { | |
261 | 'id': '9CsDKds0kvHI', | |
262 | 'ext': 'mp4', | |
263 | 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d', | |
264 | 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson', | |
265 | 'timestamp': 1426270238, | |
266 | 'upload_date': '20150313', | |
267 | 'uploader': 'NBCU-SPORTS', | |
268 | 'duration': 72.818, | |
269 | 'chapters': [], | |
270 | 'thumbnail': r're:^https?://.*\.jpg$' | |
271 | } | |
272 | }, { | |
273 | 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/PEgOtlNcC_y2', | |
274 | 'only_matching': True, | |
275 | }, { | |
276 | 'url': 'https://www.nbcsports.com/vplayer/p/BxmELC/nbcsports/select/PHJSaFWbrTY9?form=html&autoPlay=true', | |
277 | 'only_matching': True, | |
278 | }] | |
279 | ||
280 | def _real_extract(self, url): | |
281 | video_id = self._match_id(url) | |
282 | webpage = self._download_webpage(url, video_id) | |
283 | theplatform_url = self._html_search_regex(r'tp:releaseUrl="(.+?)"', webpage, 'url') | |
284 | return self.url_result(theplatform_url, 'ThePlatform') | |
285 | ||
286 | ||
287 | class NBCSportsIE(InfoExtractor): | |
288 | _VALID_URL = r'https?://(?:www\.)?nbcsports\.com//?(?!vplayer/)(?:[^/]+/)+(?P<id>[0-9a-z-]+)' | |
289 | ||
290 | _TESTS = [{ | |
291 | # iframe src | |
292 | 'url': 'https://www.nbcsports.com/watch/nfl/profootballtalk/pft-pm/unpacking-addisons-reckless-driving-citation', | |
293 | 'info_dict': { | |
294 | 'id': 'PHJSaFWbrTY9', | |
295 | 'ext': 'mp4', | |
296 | 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke', | |
297 | 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113', | |
298 | 'uploader': 'NBCU-SPORTS', | |
299 | 'upload_date': '20150330', | |
300 | 'timestamp': 1427726529, | |
301 | 'chapters': [], | |
302 | 'thumbnail': 'https://hdliveextra-a.akamaihd.net/HD/image_sports/NBCU_Sports_Group_-_nbcsports/253/303/izzodps.jpg', | |
303 | 'duration': 528.395, | |
304 | } | |
305 | }, { | |
306 | # data-mpx-src | |
307 | 'url': 'https://www.nbcsports.com/philadelphia/philadelphia-phillies/bruce-bochy-hector-neris-hes-idiot', | |
308 | 'only_matching': True, | |
309 | }, { | |
310 | # data-src | |
311 | 'url': 'https://www.nbcsports.com/boston/video/report-card-pats-secondary-no-match-josh-allen', | |
312 | 'only_matching': True, | |
313 | }] | |
314 | ||
315 | def _real_extract(self, url): | |
316 | video_id = self._match_id(url) | |
317 | webpage = self._download_webpage(url, video_id) | |
318 | return self.url_result( | |
319 | NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer') | |
320 | ||
321 | ||
322 | class NBCSportsStreamIE(AdobePassIE): | |
323 | _VALID_URL = r'https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)' | |
324 | _TEST = { | |
325 | 'url': 'http://stream.nbcsports.com/nbcsn/generic?pid=206559', | |
326 | 'info_dict': { | |
327 | 'id': '206559', | |
328 | 'ext': 'mp4', | |
329 | 'title': 'Amgen Tour of California Women\'s Recap', | |
330 | 'description': 'md5:66520066b3b5281ada7698d0ea2aa894', | |
331 | }, | |
332 | 'params': { | |
333 | # m3u8 download | |
334 | 'skip_download': True, | |
335 | }, | |
336 | 'skip': 'Requires Adobe Pass Authentication', | |
337 | } | |
338 | ||
339 | def _real_extract(self, url): | |
340 | video_id = self._match_id(url) | |
341 | live_source = self._download_json( | |
342 | 'http://stream.nbcsports.com/data/live_sources_%s.json' % video_id, | |
343 | video_id) | |
344 | video_source = live_source['videoSources'][0] | |
345 | title = video_source['title'] | |
346 | source_url = None | |
347 | for k in ('source', 'msl4source', 'iossource', 'hlsv4'): | |
348 | sk = k + 'Url' | |
349 | source_url = video_source.get(sk) or video_source.get(sk + 'Alt') | |
350 | if source_url: | |
351 | break | |
352 | else: | |
353 | source_url = video_source['ottStreamUrl'] | |
354 | is_live = video_source.get('type') == 'live' or video_source.get('status') == 'Live' | |
355 | resource = self._get_mvpd_resource('nbcsports', title, video_id, '') | |
356 | token = self._extract_mvpd_auth(url, video_id, 'nbcsports', resource) | |
357 | tokenized_url = self._download_json( | |
358 | 'https://token.playmakerservices.com/cdn', | |
359 | video_id, data=json.dumps({ | |
360 | 'requestorId': 'nbcsports', | |
361 | 'pid': video_id, | |
362 | 'application': 'NBCSports', | |
363 | 'version': 'v1', | |
364 | 'platform': 'desktop', | |
365 | 'cdn': 'akamai', | |
366 | 'url': video_source['sourceUrl'], | |
367 | 'token': base64.b64encode(token.encode()).decode(), | |
368 | 'resourceId': base64.b64encode(resource.encode()).decode(), | |
369 | }).encode())['tokenizedUrl'] | |
370 | formats = self._extract_m3u8_formats(tokenized_url, video_id, 'mp4') | |
371 | return { | |
372 | 'id': video_id, | |
373 | 'title': title, | |
374 | 'description': live_source.get('description'), | |
375 | 'formats': formats, | |
376 | 'is_live': is_live, | |
377 | } | |
378 | ||
379 | ||
380 | class NBCNewsIE(ThePlatformIE): # XXX: Do not subclass from concrete IE | |
381 | _VALID_URL = r'(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)' | |
382 | _EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//www\.nbcnews\.com/widget/video-embed/[^"\']+)\1'] | |
383 | ||
384 | _TESTS = [ | |
385 | { | |
386 | 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880', | |
387 | 'md5': 'fb3dcd2d7b1dd9804305fa2fc95ab610', # md5 tends to fluctuate | |
388 | 'info_dict': { | |
389 | 'id': '269389891880', | |
390 | 'ext': 'mp4', | |
391 | 'title': 'How Twitter Reacted To The Snowden Interview', | |
392 | 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64', | |
393 | 'timestamp': 1401363060, | |
394 | 'upload_date': '20140529', | |
395 | 'duration': 46.0, | |
396 | 'thumbnail': 'https://media-cldnry.s-nbcnews.com/image/upload/MSNBC/Components/Video/140529/p_tweet_snow_140529.jpg', | |
397 | }, | |
398 | }, | |
399 | { | |
400 | 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156', | |
401 | 'md5': 'fdbf39ab73a72df5896b6234ff98518a', | |
402 | 'info_dict': { | |
403 | 'id': '529953347624', | |
404 | 'ext': 'mp4', | |
405 | 'title': 'FULL EPISODE: Family Business', | |
406 | 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04', | |
407 | }, | |
408 | 'skip': 'This page is unavailable.', | |
409 | }, | |
410 | { | |
411 | 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844', | |
412 | 'md5': '40d0e48c68896359c80372306ece0fc3', | |
413 | 'info_dict': { | |
414 | 'id': '394064451844', | |
415 | 'ext': 'mp4', | |
416 | 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)', | |
417 | 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5', | |
418 | 'timestamp': 1423104900, | |
419 | 'upload_date': '20150205', | |
420 | 'duration': 1236.0, | |
421 | 'thumbnail': 'https://media-cldnry.s-nbcnews.com/image/upload/MSNBC/Components/Video/__NEW/nn_netcast_150204.jpg', | |
422 | }, | |
423 | }, | |
424 | { | |
425 | 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456', | |
426 | 'md5': 'ffb59bcf0733dc3c7f0ace907f5e3939', | |
427 | 'info_dict': { | |
428 | 'id': 'n431456', | |
429 | 'ext': 'mp4', | |
430 | 'title': "Volkswagen U.S. Chief: We 'Totally Screwed Up'", | |
431 | 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301', | |
432 | 'upload_date': '20150922', | |
433 | 'timestamp': 1442917800, | |
434 | 'duration': 37.0, | |
435 | 'thumbnail': 'https://media-cldnry.s-nbcnews.com/image/upload/MSNBC/Components/Video/__NEW/x_lon_vwhorn_150922.jpg', | |
436 | }, | |
437 | }, | |
438 | { | |
439 | 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788', | |
440 | 'md5': '693d1fa21d23afcc9b04c66b227ed9ff', | |
441 | 'info_dict': { | |
442 | 'id': '669831235788', | |
443 | 'ext': 'mp4', | |
444 | 'title': 'See the aurora borealis from space in stunning new NASA video', | |
445 | 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1', | |
446 | 'upload_date': '20160420', | |
447 | 'timestamp': 1461152093, | |
448 | 'duration': 69.0, | |
449 | 'thumbnail': 'https://media-cldnry.s-nbcnews.com/image/upload/MSNBC/Components/Video/201604/2016-04-20T11-35-09-133Z--1280x720.jpg', | |
450 | }, | |
451 | }, | |
452 | { | |
453 | 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924', | |
454 | 'md5': '6d236bf4f3dddc226633ce6e2c3f814d', | |
455 | 'info_dict': { | |
456 | 'id': '314487875924', | |
457 | 'ext': 'mp4', | |
458 | 'title': 'The chaotic GOP immigration vote', | |
459 | '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.', | |
460 | 'thumbnail': r're:^https?://.*\.jpg$', | |
461 | 'timestamp': 1406937606, | |
462 | 'upload_date': '20140802', | |
463 | 'duration': 940.0, | |
464 | }, | |
465 | }, | |
466 | { | |
467 | 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952', | |
468 | 'only_matching': True, | |
469 | }, | |
470 | { | |
471 | # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html | |
472 | 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682', | |
473 | 'only_matching': True, | |
474 | }, | |
475 | ] | |
476 | ||
477 | def _real_extract(self, url): | |
478 | video_id = self._match_id(url) | |
479 | webpage = self._download_webpage(url, video_id) | |
480 | ||
481 | data = self._search_nextjs_data(webpage, video_id)['props']['initialState'] | |
482 | video_data = try_get(data, lambda x: x['video']['current'], dict) | |
483 | if not video_data: | |
484 | video_data = data['article']['content'][0]['primaryMedia']['video'] | |
485 | title = video_data['headline']['primary'] | |
486 | ||
487 | formats = [] | |
488 | for va in video_data.get('videoAssets', []): | |
489 | public_url = va.get('publicUrl') | |
490 | if not public_url: | |
491 | continue | |
492 | if '://link.theplatform.com/' in public_url: | |
493 | public_url = update_url_query(public_url, {'format': 'redirect'}) | |
494 | format_id = va.get('format') | |
495 | if format_id == 'M3U': | |
496 | formats.extend(self._extract_m3u8_formats( | |
497 | public_url, video_id, 'mp4', 'm3u8_native', | |
498 | m3u8_id=format_id, fatal=False)) | |
499 | continue | |
500 | tbr = int_or_none(va.get('bitrate'), 1000) | |
501 | if tbr: | |
502 | format_id += '-%d' % tbr | |
503 | formats.append({ | |
504 | 'format_id': format_id, | |
505 | 'url': public_url, | |
506 | 'width': int_or_none(va.get('width')), | |
507 | 'height': int_or_none(va.get('height')), | |
508 | 'tbr': tbr, | |
509 | 'ext': 'mp4', | |
510 | }) | |
511 | ||
512 | subtitles = {} | |
513 | closed_captioning = video_data.get('closedCaptioning') | |
514 | if closed_captioning: | |
515 | for cc_url in closed_captioning.values(): | |
516 | if not cc_url: | |
517 | continue | |
518 | subtitles.setdefault('en', []).append({ | |
519 | 'url': cc_url, | |
520 | }) | |
521 | ||
522 | return { | |
523 | 'id': video_id, | |
524 | 'title': title, | |
525 | 'description': try_get(video_data, lambda x: x['description']['primary']), | |
526 | 'thumbnail': try_get(video_data, lambda x: x['primaryImage']['url']['primary']), | |
527 | 'duration': parse_duration(video_data.get('duration')), | |
528 | 'timestamp': unified_timestamp(video_data.get('datePublished')), | |
529 | 'formats': formats, | |
530 | 'subtitles': subtitles, | |
531 | } | |
532 | ||
533 | ||
534 | class NBCOlympicsIE(InfoExtractor): | |
535 | IE_NAME = 'nbcolympics' | |
536 | _VALID_URL = r'https?://www\.nbcolympics\.com/videos?/(?P<id>[0-9a-z-]+)' | |
537 | ||
538 | _TEST = { | |
539 | # Geo-restricted to US | |
540 | 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold', | |
541 | 'md5': '54fecf846d05429fbaa18af557ee523a', | |
542 | 'info_dict': { | |
543 | 'id': 'WjTBzDXx5AUq', | |
544 | 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold', | |
545 | 'ext': 'mp4', | |
546 | 'title': 'Rose\'s son Leo was in tears after his dad won gold', | |
547 | 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.', | |
548 | 'timestamp': 1471274964, | |
549 | 'upload_date': '20160815', | |
550 | 'uploader': 'NBCU-SPORTS', | |
551 | }, | |
552 | 'skip': '404 Not Found', | |
553 | } | |
554 | ||
555 | def _real_extract(self, url): | |
556 | display_id = self._match_id(url) | |
557 | ||
558 | webpage = self._download_webpage(url, display_id) | |
559 | ||
560 | try: | |
561 | drupal_settings = self._parse_json(self._search_regex( | |
562 | r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);', | |
563 | webpage, 'drupal settings'), display_id) | |
564 | ||
565 | iframe_url = drupal_settings['vod']['iframe_url'] | |
566 | theplatform_url = iframe_url.replace( | |
567 | 'vplayer.nbcolympics.com', 'player.theplatform.com') | |
568 | except RegexNotFoundError: | |
569 | theplatform_url = self._search_regex( | |
570 | r"([\"'])embedUrl\1: *([\"'])(?P<embedUrl>.+)\2", | |
571 | webpage, 'embedding URL', group="embedUrl") | |
572 | ||
573 | return { | |
574 | '_type': 'url_transparent', | |
575 | 'url': theplatform_url, | |
576 | 'ie_key': ThePlatformIE.ie_key(), | |
577 | 'display_id': display_id, | |
578 | } | |
579 | ||
580 | ||
581 | class NBCOlympicsStreamIE(AdobePassIE): | |
582 | IE_NAME = 'nbcolympics:stream' | |
583 | _VALID_URL = r'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)' | |
584 | _TESTS = [ | |
585 | { | |
586 | 'note': 'Tokenized m3u8 source URL', | |
587 | 'url': 'https://stream.nbcolympics.com/womens-soccer-group-round-11', | |
588 | 'info_dict': { | |
589 | 'id': '2019740', | |
590 | 'ext': 'mp4', | |
591 | 'title': r"re:Women's Group Stage - Netherlands vs\. Brazil [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$", | |
592 | }, | |
593 | 'params': { | |
594 | 'skip_download': 'm3u8', | |
595 | }, | |
596 | 'skip': 'Livestream', | |
597 | }, { | |
598 | 'note': 'Plain m3u8 source URL', | |
599 | 'url': 'https://stream.nbcolympics.com/gymnastics-event-finals-mens-floor-pommel-horse-womens-vault-bars', | |
600 | 'info_dict': { | |
601 | 'id': '2021729', | |
602 | 'ext': 'mp4', | |
603 | 'title': r're:Event Finals: M Floor, W Vault, M Pommel, W Uneven Bars [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', | |
604 | }, | |
605 | 'params': { | |
606 | 'skip_download': 'm3u8', | |
607 | }, | |
608 | 'skip': 'Livestream', | |
609 | }, | |
610 | ] | |
611 | ||
612 | def _real_extract(self, url): | |
613 | display_id = self._match_id(url) | |
614 | webpage = self._download_webpage(url, display_id) | |
615 | pid = self._search_regex(r'pid\s*=\s*(\d+);', webpage, 'pid') | |
616 | ||
617 | event_config = self._download_json( | |
618 | f'http://stream.nbcolympics.com/data/event_config_{pid}.json', | |
619 | pid, 'Downloading event config')['eventConfig'] | |
620 | ||
621 | title = event_config['eventTitle'] | |
622 | is_live = {'live': True, 'replay': False}.get(event_config.get('eventStatus')) | |
623 | ||
624 | source_url = self._download_json( | |
625 | f'https://api-leap.nbcsports.com/feeds/assets/{pid}?application=NBCOlympics&platform=desktop&format=nbc-player&env=staging', | |
626 | pid, 'Downloading leap config' | |
627 | )['videoSources'][0]['cdnSources']['primary'][0]['sourceUrl'] | |
628 | ||
629 | if event_config.get('cdnToken'): | |
630 | ap_resource = self._get_mvpd_resource( | |
631 | event_config.get('resourceId', 'NBCOlympics'), | |
632 | re.sub(r'[^\w\d ]+', '', event_config['eventTitle']), pid, | |
633 | event_config.get('ratingId', 'NO VALUE')) | |
634 | media_token = self._extract_mvpd_auth(url, pid, event_config.get('requestorId', 'NBCOlympics'), ap_resource) | |
635 | ||
636 | source_url = self._download_json( | |
637 | 'https://tokens.playmakerservices.com/', pid, 'Retrieving tokenized URL', | |
638 | data=json.dumps({ | |
639 | 'application': 'NBCSports', | |
640 | 'authentication-type': 'adobe-pass', | |
641 | 'cdn': 'akamai', | |
642 | 'pid': pid, | |
643 | 'platform': 'desktop', | |
644 | 'requestorId': 'NBCOlympics', | |
645 | 'resourceId': base64.b64encode(ap_resource.encode()).decode(), | |
646 | 'token': base64.b64encode(media_token.encode()).decode(), | |
647 | 'url': source_url, | |
648 | 'version': 'v1', | |
649 | }).encode(), | |
650 | )['akamai'][0]['tokenizedUrl'] | |
651 | ||
652 | formats = self._extract_m3u8_formats(source_url, pid, 'mp4', live=is_live) | |
653 | for f in formats: | |
654 | # -http_seekable requires ffmpeg 4.3+ but it doesnt seem possible to | |
655 | # download with ffmpeg without this option | |
656 | f['downloader_options'] = {'ffmpeg_args': ['-seekable', '0', '-http_seekable', '0', '-icy', '0']} | |
657 | ||
658 | return { | |
659 | 'id': pid, | |
660 | 'display_id': display_id, | |
661 | 'title': title, | |
662 | 'formats': formats, | |
663 | 'is_live': is_live, | |
664 | } | |
665 | ||
666 | ||
667 | class NBCStationsIE(InfoExtractor): | |
668 | _DOMAIN_RE = '|'.join(map(re.escape, ( | |
669 | 'nbcbayarea', 'nbcboston', 'nbcchicago', 'nbcconnecticut', 'nbcdfw', 'nbclosangeles', | |
670 | 'nbcmiami', 'nbcnewyork', 'nbcphiladelphia', 'nbcsandiego', 'nbcwashington', | |
671 | 'necn', 'telemundo52', 'telemundoarizona', 'telemundochicago', 'telemundonuevainglaterra', | |
672 | ))) | |
673 | _VALID_URL = rf'https?://(?:www\.)?(?P<site>{_DOMAIN_RE})\.com/(?:[^/?#]+/)*(?P<id>[^/?#]+)/?(?:$|[#?])' | |
674 | ||
675 | _TESTS = [{ | |
676 | 'url': 'https://www.nbclosangeles.com/news/local/large-structure-fire-in-downtown-la-prompts-smoke-odor-advisory/2968618/', | |
677 | 'info_dict': { | |
678 | 'id': '2968618', | |
679 | 'ext': 'mp4', | |
680 | 'title': 'Large Structure Fire in Downtown LA Prompts Smoke Odor Advisory', | |
681 | 'description': 'md5:417ed3c2d91fe9d301e6db7b0942f182', | |
682 | 'duration': 112.513, | |
683 | 'timestamp': 1661135892, | |
684 | 'upload_date': '20220822', | |
685 | 'uploader': 'NBC 4', | |
686 | 'channel_id': 'KNBC', | |
687 | 'channel': 'nbclosangeles', | |
688 | }, | |
689 | 'params': { | |
690 | 'skip_download': 'm3u8', | |
691 | }, | |
692 | }, { | |
693 | 'url': 'https://www.telemundoarizona.com/responde/huracan-complica-reembolso-para-televidente-de-tucson/2247002/', | |
694 | 'info_dict': { | |
695 | 'id': '2247002', | |
696 | 'ext': 'mp4', | |
697 | 'title': 'Huracán complica que televidente de Tucson reciba reembolso', | |
698 | 'description': 'md5:af298dc73aab74d4fca6abfb12acb6cf', | |
699 | 'duration': 172.406, | |
700 | 'timestamp': 1660886507, | |
701 | 'upload_date': '20220819', | |
702 | 'uploader': 'Telemundo Arizona', | |
703 | 'channel_id': 'KTAZ', | |
704 | 'channel': 'telemundoarizona', | |
705 | }, | |
706 | 'params': { | |
707 | 'skip_download': 'm3u8', | |
708 | }, | |
709 | }, { | |
710 | # direct mp4 link | |
711 | 'url': 'https://www.nbcboston.com/weather/video-weather/highs-near-freezing-in-boston-on-wednesday/2961135/', | |
712 | 'md5': '9bf8c41dc7abbb75b1a44f1491a4cc85', | |
713 | 'info_dict': { | |
714 | 'id': '2961135', | |
715 | 'ext': 'mp4', | |
716 | 'title': 'Highs Near Freezing in Boston on Wednesday', | |
717 | 'description': 'md5:3ec486609a926c99f00a3512e6c0e85b', | |
718 | 'duration': 235.669, | |
719 | 'timestamp': 1675268656, | |
720 | 'upload_date': '20230201', | |
721 | 'uploader': '', | |
722 | 'channel_id': 'WBTS', | |
723 | 'channel': 'nbcboston', | |
724 | }, | |
725 | }] | |
726 | ||
727 | _RESOLUTIONS = { | |
728 | '1080': '1920', | |
729 | '720': '1280', | |
730 | '540': '960', | |
731 | '360': '640', | |
732 | '234': '416', | |
733 | } | |
734 | ||
735 | def _real_extract(self, url): | |
736 | channel, video_id = self._match_valid_url(url).group('site', 'id') | |
737 | webpage = self._download_webpage(url, video_id) | |
738 | ||
739 | nbc_data = self._search_json( | |
740 | r'<script>\s*var\s+nbc\s*=', webpage, 'NBC JSON data', video_id) | |
741 | pdk_acct = nbc_data.get('pdkAcct') or 'Yh1nAC' | |
742 | fw_ssid = traverse_obj(nbc_data, ('video', 'fwSSID')) | |
743 | ||
744 | video_data = self._search_json( | |
745 | r'data-videos="\[', webpage, 'video data', video_id, default={}, transform_source=unescapeHTML) | |
746 | video_data.update(self._search_json( | |
747 | r'data-meta="', webpage, 'metadata', video_id, default={}, transform_source=unescapeHTML)) | |
748 | if not video_data: | |
749 | raise ExtractorError('No video metadata found in webpage', expected=True) | |
750 | ||
751 | info, formats = {}, [] | |
752 | is_live = int_or_none(video_data.get('mpx_is_livestream')) == 1 | |
753 | query = { | |
754 | 'formats': 'MPEG-DASH none,M3U none,MPEG-DASH none,MPEG4,MP3', | |
755 | 'format': 'SMIL', | |
756 | 'fwsitesection': fw_ssid, | |
757 | 'fwNetworkID': traverse_obj(nbc_data, ('video', 'fwNetworkID'), default='382114'), | |
758 | 'pprofile': 'ots_desktop_html', | |
759 | 'sensitive': 'false', | |
760 | 'w': '1920', | |
761 | 'h': '1080', | |
762 | 'mode': 'LIVE' if is_live else 'on-demand', | |
763 | 'vpaid': 'script', | |
764 | 'schema': '2.0', | |
765 | 'sdk': 'PDK 6.1.3', | |
766 | } | |
767 | ||
768 | if is_live: | |
769 | player_id = traverse_obj(video_data, ((None, ('video', 'meta')), ( | |
770 | 'mpx_m3upid', 'mpx_pid', 'pid_streaming_web_medium')), get_all=False) | |
771 | info['title'] = f'{channel} livestream' | |
772 | ||
773 | else: | |
774 | player_id = traverse_obj(video_data, ( | |
775 | (None, ('video', 'meta')), ('pid_streaming_web_high', 'mpx_pid')), get_all=False) | |
776 | ||
777 | date_string = traverse_obj(video_data, 'date_string', 'date_gmt') | |
778 | if date_string: | |
779 | date_string = self._search_regex( | |
780 | r'datetime="([^"]+)"', date_string, 'date string', fatal=False) | |
781 | else: | |
782 | date_string = traverse_obj( | |
783 | nbc_data, ('dataLayer', 'adobe', ('prop70', 'eVar70', 'eVar59')), get_all=False) | |
784 | ||
785 | video_url = traverse_obj(video_data, ((None, ('video', 'meta')), 'mp4_url'), get_all=False) | |
786 | if video_url: | |
787 | ext = determine_ext(video_url) | |
788 | height = self._search_regex(r'\d+-(\d+)p', url_basename(video_url), 'height', default=None) | |
789 | formats.append({ | |
790 | 'url': video_url, | |
791 | 'ext': ext, | |
792 | 'width': int_or_none(self._RESOLUTIONS.get(height)), | |
793 | 'height': int_or_none(height), | |
794 | 'format_id': f'http-{ext}', | |
795 | }) | |
796 | ||
797 | info.update({ | |
798 | 'title': video_data.get('title') or traverse_obj(nbc_data, ( | |
799 | 'dataLayer', (None, 'adobe'), ('contenttitle', 'title', 'prop22')), get_all=False), | |
800 | 'description': | |
801 | traverse_obj(video_data, 'summary', 'excerpt', 'video_hero_text') | |
802 | or clean_html(traverse_obj(nbc_data, ('dataLayer', 'summary'))), | |
803 | 'timestamp': unified_timestamp(date_string), | |
804 | }) | |
805 | ||
806 | smil = None | |
807 | if player_id and fw_ssid: | |
808 | smil = self._download_xml( | |
809 | f'https://link.theplatform.com/s/{pdk_acct}/{player_id}', video_id, | |
810 | note='Downloading SMIL data', query=query, fatal=is_live) | |
811 | if not isinstance(smil, xml.etree.ElementTree.Element): | |
812 | smil = None | |
813 | subtitles = self._parse_smil_subtitles(smil, default_ns) if smil is not None else {} | |
814 | for video in smil.findall(self._xpath_ns('.//video', default_ns)) if smil is not None else []: | |
815 | info['duration'] = float_or_none(remove_end(video.get('dur'), 'ms'), 1000) | |
816 | video_src_url = video.get('src') | |
817 | ext = mimetype2ext(video.get('type'), default=determine_ext(video_src_url)) | |
818 | if ext == 'm3u8': | |
819 | fmts, subs = self._extract_m3u8_formats_and_subtitles( | |
820 | video_src_url, video_id, 'mp4', m3u8_id='hls', fatal=is_live, | |
821 | live=is_live, errnote='No HLS formats found') | |
822 | formats.extend(fmts) | |
823 | self._merge_subtitles(subs, target=subtitles) | |
824 | elif video_src_url: | |
825 | formats.append({ | |
826 | 'url': video_src_url, | |
827 | 'format_id': f'https-{ext}', | |
828 | 'ext': ext, | |
829 | 'width': int_or_none(video.get('width')), | |
830 | 'height': int_or_none(video.get('height')), | |
831 | }) | |
832 | ||
833 | if not formats: | |
834 | self.raise_no_formats('No video content found in webpage', expected=True) | |
835 | elif is_live: | |
836 | try: | |
837 | self._request_webpage( | |
838 | HEADRequest(formats[0]['url']), video_id, note='Checking live status') | |
839 | except ExtractorError: | |
840 | raise UserNotLive(video_id=channel) | |
841 | ||
842 | return { | |
843 | 'id': video_id, | |
844 | 'channel': channel, | |
845 | 'channel_id': nbc_data.get('callLetters'), | |
846 | 'uploader': nbc_data.get('on_air_name'), | |
847 | 'formats': formats, | |
848 | 'subtitles': subtitles, | |
849 | 'is_live': is_live, | |
850 | **info, | |
851 | } |