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