]>
Commit | Line | Data |
---|---|---|
cd7ee7aa JMF |
1 | from __future__ import unicode_literals |
2 | ||
58284890 | 3 | import base64 |
1139935d RA |
4 | import json |
5 | import re | |
0bc56fa6 JMF |
6 | |
7 | from .common import InfoExtractor | |
574b2a73 | 8 | from .theplatform import ThePlatformIE |
fdf9b959 | 9 | from .adobepass import AdobePassIE |
d0c5fabc | 10 | from ..compat import compat_urllib_parse_unquote |
1cc79574 | 11 | from ..utils import ( |
895e5c03 | 12 | int_or_none, |
9160a0c6 | 13 | parse_age_limit, |
895e5c03 | 14 | parse_duration, |
3e376d18 | 15 | RegexNotFoundError, |
b46b65ed | 16 | smuggle_url, |
895e5c03 RA |
17 | try_get, |
18 | unified_timestamp, | |
6e416b21 | 19 | update_url_query, |
37e64add | 20 | ) |
0bc56fa6 JMF |
21 | |
22 | ||
9160a0c6 | 23 | class NBCIE(ThePlatformIE): |
d673ab65 | 24 | _VALID_URL = r'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>n?\d+))' |
58c1f6f0 S |
25 | |
26 | _TESTS = [ | |
27 | { | |
fdf9b959 | 28 | 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237', |
58c1f6f0 | 29 | 'info_dict': { |
fdf9b959 | 30 | 'id': '2848237', |
e881c4bc | 31 | 'ext': 'mp4', |
5c8a3f86 JMF |
32 | 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s', |
33 | '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 | 34 | 'timestamp': 1424246400, |
35 | 'upload_date': '20150218', | |
36 | 'uploader': 'NBCU-COM', | |
58c1f6f0 | 37 | }, |
e881c4bc YCH |
38 | 'params': { |
39 | # m3u8 download | |
40 | 'skip_download': True, | |
41 | }, | |
020cf5eb | 42 | }, |
b9b3ab45 YCH |
43 | { |
44 | 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821', | |
45 | 'info_dict': { | |
e881c4bc YCH |
46 | 'id': '2832821', |
47 | 'ext': 'mp4', | |
b9b3ab45 YCH |
48 | 'title': 'Star Wars Teaser', |
49 | 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442', | |
79ba9140 | 50 | 'timestamp': 1417852800, |
51 | 'upload_date': '20141206', | |
52 | 'uploader': 'NBCU-COM', | |
b9b3ab45 | 53 | }, |
e881c4bc YCH |
54 | 'params': { |
55 | # m3u8 download | |
56 | 'skip_download': True, | |
57 | }, | |
b9b3ab45 | 58 | 'skip': 'Only works from US', |
0fe2ff78 | 59 | }, |
e6e90515 YCH |
60 | { |
61 | # HLS streams requires the 'hdnea3' cookie | |
62 | 'url': 'http://www.nbc.com/Kings/video/goliath/n1806', | |
63 | 'info_dict': { | |
fdf9b959 | 64 | 'id': '101528f5a9e8127b107e98c5e6ce4638', |
e6e90515 YCH |
65 | 'ext': 'mp4', |
66 | 'title': 'Goliath', | |
67 | '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.', | |
68 | 'timestamp': 1237100400, | |
69 | 'upload_date': '20090315', | |
70 | 'uploader': 'NBCU-COM', | |
71 | }, | |
72 | 'params': { | |
73 | 'skip_download': True, | |
74 | }, | |
75 | 'skip': 'Only works from US', | |
d673ab65 L |
76 | }, |
77 | { | |
78 | 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310', | |
79 | 'only_matching': True, | |
80 | }, | |
d0c5fabc T |
81 | { |
82 | # Percent escaped url | |
83 | 'url': 'https://www.nbc.com/up-all-night/video/day-after-valentine%27s-day/n2189', | |
84 | 'only_matching': True, | |
85 | } | |
58c1f6f0 | 86 | ] |
020cf5eb JMF |
87 | |
88 | def _real_extract(self, url): | |
5ad28e7f | 89 | permalink, video_id = self._match_valid_url(url).groups() |
d0c5fabc | 90 | permalink = 'http' + compat_urllib_parse_unquote(permalink) |
48ff5590 | 91 | video_data = self._download_json( |
311ee457 | 92 | 'https://friendship.nbc.co/v2/graphql', video_id, query={ |
48ff5590 RA |
93 | 'query': '''query bonanzaPage( |
94 | $app: NBCUBrands! = nbc | |
95 | $name: String! | |
96 | $oneApp: Boolean | |
97 | $platform: SupportedPlatforms! = web | |
98 | $type: EntityPageType! = VIDEO | |
99 | $userId: String! | |
100 | ) { | |
101 | bonanzaPage( | |
102 | app: $app | |
103 | name: $name | |
104 | oneApp: $oneApp | |
105 | platform: $platform | |
106 | type: $type | |
107 | userId: $userId | |
108 | ) { | |
109 | metadata { | |
311ee457 RA |
110 | ... on VideoPageData { |
111 | description | |
112 | episodeNumber | |
113 | keywords | |
114 | locked | |
115 | mpxAccountId | |
116 | mpxGuid | |
117 | rating | |
48ff5590 | 118 | resourceId |
311ee457 RA |
119 | seasonNumber |
120 | secondaryTitle | |
121 | seriesShortTitle | |
122 | } | |
123 | } | |
124 | } | |
48ff5590 RA |
125 | }''', |
126 | 'variables': json.dumps({ | |
127 | 'name': permalink, | |
128 | 'oneApp': True, | |
129 | 'userId': '0', | |
130 | }), | |
131 | })['data']['bonanzaPage']['metadata'] | |
2eeb588e RA |
132 | query = { |
133 | 'mbr': 'true', | |
134 | 'manifest': 'm3u', | |
135 | } | |
311ee457 | 136 | video_id = video_data['mpxGuid'] |
9160a0c6 TSJ |
137 | tp_path = 'NnzsPC/media/guid/%s/%s' % (video_data.get('mpxAccountId') or '2410887629', video_id) |
138 | tpm = self._download_theplatform_metadata(tp_path, video_id) | |
139 | title = tpm.get('title') or video_data.get('secondaryTitle') | |
311ee457 | 140 | if video_data.get('locked'): |
2eeb588e | 141 | resource = self._get_mvpd_resource( |
48ff5590 RA |
142 | video_data.get('resourceId') or 'nbcentertainment', |
143 | title, video_id, video_data.get('rating')) | |
2eeb588e RA |
144 | query['auth'] = self._extract_mvpd_auth( |
145 | url, video_id, 'nbcentertainment', resource) | |
146 | theplatform_url = smuggle_url(update_url_query( | |
311ee457 | 147 | 'http://link.theplatform.com/s/NnzsPC/media/guid/%s/%s' % (video_data.get('mpxAccountId') or '2410887629', video_id), |
2eeb588e | 148 | query), {'force_smil_url': True}) |
9160a0c6 TSJ |
149 | |
150 | # Empty string or 0 can be valid values for these. So the check must be `is None` | |
151 | description = video_data.get('description') | |
152 | if description is None: | |
153 | description = tpm.get('description') | |
154 | episode_number = int_or_none(video_data.get('episodeNumber')) | |
155 | if episode_number is None: | |
156 | episode_number = int_or_none(tpm.get('nbcu$airOrder')) | |
157 | rating = video_data.get('rating') | |
158 | if rating is None: | |
159 | try_get(tpm, lambda x: x['ratings'][0]['rating']) | |
160 | season_number = int_or_none(video_data.get('seasonNumber')) | |
161 | if season_number is None: | |
162 | season_number = int_or_none(tpm.get('nbcu$seasonNumber')) | |
163 | series = video_data.get('seriesShortTitle') | |
164 | if series is None: | |
165 | series = tpm.get('nbcu$seriesShortTitle') | |
166 | tags = video_data.get('keywords') | |
167 | if tags is None or len(tags) == 0: | |
168 | tags = tpm.get('keywords') | |
169 | ||
2eeb588e | 170 | return { |
e881c4bc | 171 | '_type': 'url_transparent', |
9160a0c6 TSJ |
172 | 'age_limit': parse_age_limit(rating), |
173 | 'description': description, | |
174 | 'episode': title, | |
175 | 'episode_number': episode_number, | |
e881c4bc | 176 | 'id': video_id, |
9160a0c6 TSJ |
177 | 'ie_key': 'ThePlatform', |
178 | 'season_number': season_number, | |
179 | 'series': series, | |
180 | 'tags': tags, | |
2eeb588e RA |
181 | 'title': title, |
182 | 'url': theplatform_url, | |
e881c4bc | 183 | } |
020cf5eb JMF |
184 | |
185 | ||
a2a4d5fa | 186 | class NBCSportsVPlayerIE(InfoExtractor): |
29f7c58a | 187 | _VALID_URL_BASE = r'https?://(?:vplayer\.nbcsports\.com|(?:www\.)?nbcsports\.com/vplayer)/' |
188 | _VALID_URL = _VALID_URL_BASE + r'(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)' | |
a28ccbab | 189 | |
5cbb2699 | 190 | _TESTS = [{ |
12ea5c79 | 191 | 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI', |
a28ccbab YCH |
192 | 'info_dict': { |
193 | 'id': '9CsDKds0kvHI', | |
12ea5c79 | 194 | 'ext': 'mp4', |
a28ccbab YCH |
195 | 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d', |
196 | 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson', | |
79ba9140 | 197 | 'timestamp': 1426270238, |
198 | 'upload_date': '20150313', | |
199 | 'uploader': 'NBCU-SPORTS', | |
a28ccbab | 200 | } |
5cbb2699 | 201 | }, { |
12ea5c79 | 202 | 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/_hqLjQ95yx8Z', |
5cbb2699 | 203 | 'only_matching': True, |
29f7c58a | 204 | }, { |
205 | 'url': 'https://www.nbcsports.com/vplayer/p/BxmELC/nbcsports/select/PHJSaFWbrTY9?form=html&autoPlay=true', | |
206 | 'only_matching': True, | |
5cbb2699 | 207 | }] |
a28ccbab | 208 | |
a2a4d5fa YCH |
209 | @staticmethod |
210 | def _extract_url(webpage): | |
211 | iframe_m = re.search( | |
29f7c58a | 212 | r'<(?:iframe[^>]+|div[^>]+data-(?:mpx-)?)src="(?P<url>%s[^"]+)"' % NBCSportsVPlayerIE._VALID_URL_BASE, webpage) |
a2a4d5fa YCH |
213 | if iframe_m: |
214 | return iframe_m.group('url') | |
215 | ||
a28ccbab YCH |
216 | def _real_extract(self, url): |
217 | video_id = self._match_id(url) | |
218 | webpage = self._download_webpage(url, video_id) | |
12ea5c79 PV |
219 | theplatform_url = self._og_search_video_url(webpage).replace( |
220 | 'vplayer.nbcsports.com', 'player.theplatform.com') | |
a28ccbab YCH |
221 | return self.url_result(theplatform_url, 'ThePlatform') |
222 | ||
223 | ||
a2a4d5fa | 224 | class NBCSportsIE(InfoExtractor): |
29f7c58a | 225 | _VALID_URL = r'https?://(?:www\.)?nbcsports\.com//?(?!vplayer/)(?:[^/]+/)+(?P<id>[0-9a-z-]+)' |
a2a4d5fa | 226 | |
29f7c58a | 227 | _TESTS = [{ |
228 | # iframe src | |
a2a4d5fa | 229 | 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke', |
a2a4d5fa YCH |
230 | 'info_dict': { |
231 | 'id': 'PHJSaFWbrTY9', | |
29f7c58a | 232 | 'ext': 'mp4', |
a2a4d5fa YCH |
233 | 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke', |
234 | 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113', | |
0738187f YCH |
235 | 'uploader': 'NBCU-SPORTS', |
236 | 'upload_date': '20150330', | |
237 | 'timestamp': 1427726529, | |
a2a4d5fa | 238 | } |
29f7c58a | 239 | }, { |
240 | # data-mpx-src | |
241 | 'url': 'https://www.nbcsports.com/philadelphia/philadelphia-phillies/bruce-bochy-hector-neris-hes-idiot', | |
242 | 'only_matching': True, | |
243 | }, { | |
244 | # data-src | |
245 | 'url': 'https://www.nbcsports.com/boston/video/report-card-pats-secondary-no-match-josh-allen', | |
246 | 'only_matching': True, | |
247 | }] | |
a2a4d5fa YCH |
248 | |
249 | def _real_extract(self, url): | |
250 | video_id = self._match_id(url) | |
251 | webpage = self._download_webpage(url, video_id) | |
252 | return self.url_result( | |
253 | NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer') | |
254 | ||
255 | ||
1139935d RA |
256 | class NBCSportsStreamIE(AdobePassIE): |
257 | _VALID_URL = r'https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)' | |
258 | _TEST = { | |
259 | 'url': 'http://stream.nbcsports.com/nbcsn/generic?pid=206559', | |
260 | 'info_dict': { | |
261 | 'id': '206559', | |
262 | 'ext': 'mp4', | |
263 | 'title': 'Amgen Tour of California Women\'s Recap', | |
264 | 'description': 'md5:66520066b3b5281ada7698d0ea2aa894', | |
265 | }, | |
266 | 'params': { | |
267 | # m3u8 download | |
268 | 'skip_download': True, | |
269 | }, | |
270 | 'skip': 'Requires Adobe Pass Authentication', | |
271 | } | |
272 | ||
273 | def _real_extract(self, url): | |
274 | video_id = self._match_id(url) | |
275 | live_source = self._download_json( | |
276 | 'http://stream.nbcsports.com/data/live_sources_%s.json' % video_id, | |
277 | video_id) | |
278 | video_source = live_source['videoSources'][0] | |
279 | title = video_source['title'] | |
280 | source_url = None | |
281 | for k in ('source', 'msl4source', 'iossource', 'hlsv4'): | |
282 | sk = k + 'Url' | |
283 | source_url = video_source.get(sk) or video_source.get(sk + 'Alt') | |
284 | if source_url: | |
285 | break | |
286 | else: | |
287 | source_url = video_source['ottStreamUrl'] | |
288 | is_live = video_source.get('type') == 'live' or video_source.get('status') == 'Live' | |
289 | resource = self._get_mvpd_resource('nbcsports', title, video_id, '') | |
290 | token = self._extract_mvpd_auth(url, video_id, 'nbcsports', resource) | |
291 | tokenized_url = self._download_json( | |
292 | 'https://token.playmakerservices.com/cdn', | |
293 | video_id, data=json.dumps({ | |
294 | 'requestorId': 'nbcsports', | |
295 | 'pid': video_id, | |
296 | 'application': 'NBCSports', | |
297 | 'version': 'v1', | |
298 | 'platform': 'desktop', | |
299 | 'cdn': 'akamai', | |
300 | 'url': video_source['sourceUrl'], | |
301 | 'token': base64.b64encode(token.encode()).decode(), | |
302 | 'resourceId': base64.b64encode(resource.encode()).decode(), | |
303 | }).encode())['tokenizedUrl'] | |
304 | formats = self._extract_m3u8_formats(tokenized_url, video_id, 'mp4') | |
305 | self._sort_formats(formats) | |
306 | return { | |
307 | 'id': video_id, | |
308 | 'title': self._live_title(title) if is_live else title, | |
309 | 'description': live_source.get('description'), | |
310 | 'formats': formats, | |
311 | 'is_live': is_live, | |
312 | } | |
313 | ||
314 | ||
574b2a73 | 315 | class NBCNewsIE(ThePlatformIE): |
a843464a | 316 | _VALID_URL = r'(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)' |
0bc56fa6 | 317 | |
87fe568c | 318 | _TESTS = [ |
87fe568c | 319 | { |
574b2a73 | 320 | 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880', |
895e5c03 | 321 | 'md5': 'cf4bc9e6ce0130f00f545d80ecedd4bf', |
87fe568c | 322 | 'info_dict': { |
a843464a | 323 | 'id': '269389891880', |
10e3d734 | 324 | 'ext': 'mp4', |
87fe568c JMF |
325 | 'title': 'How Twitter Reacted To The Snowden Interview', |
326 | 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64', | |
0437307a RA |
327 | 'timestamp': 1401363060, |
328 | 'upload_date': '20140529', | |
87fe568c | 329 | }, |
87fe568c | 330 | }, |
2df54b4b S |
331 | { |
332 | 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156', | |
333 | 'md5': 'fdbf39ab73a72df5896b6234ff98518a', | |
334 | 'info_dict': { | |
0437307a | 335 | 'id': '529953347624', |
2df54b4b S |
336 | 'ext': 'mp4', |
337 | 'title': 'FULL EPISODE: Family Business', | |
338 | 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04', | |
339 | }, | |
574b2a73 | 340 | 'skip': 'This page is unavailable.', |
2df54b4b | 341 | }, |
d9aa2b78 RS |
342 | { |
343 | 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844', | |
895e5c03 | 344 | 'md5': '8eb831eca25bfa7d25ddd83e85946548', |
d9aa2b78 | 345 | 'info_dict': { |
a843464a | 346 | 'id': '394064451844', |
d9aa2b78 RS |
347 | 'ext': 'mp4', |
348 | 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)', | |
349 | 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5', | |
0437307a | 350 | 'timestamp': 1423104900, |
0437307a | 351 | 'upload_date': '20150205', |
d9aa2b78 RS |
352 | }, |
353 | }, | |
574b2a73 | 354 | { |
355 | 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456', | |
895e5c03 | 356 | 'md5': '4a8c4cec9e1ded51060bdda36ff0a5c0', |
574b2a73 | 357 | 'info_dict': { |
895e5c03 | 358 | 'id': 'n431456', |
574b2a73 | 359 | 'ext': 'mp4', |
895e5c03 RA |
360 | 'title': "Volkswagen U.S. Chief: We 'Totally Screwed Up'", |
361 | 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301', | |
0437307a RA |
362 | 'upload_date': '20150922', |
363 | 'timestamp': 1442917800, | |
574b2a73 | 364 | }, |
574b2a73 | 365 | }, |
cb7d4d0e | 366 | { |
367 | 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788', | |
368 | 'md5': '118d7ca3f0bea6534f119c68ef539f71', | |
369 | 'info_dict': { | |
a843464a | 370 | 'id': '669831235788', |
cb7d4d0e | 371 | 'ext': 'mp4', |
372 | 'title': 'See the aurora borealis from space in stunning new NASA video', | |
373 | 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1', | |
374 | 'upload_date': '20160420', | |
375 | 'timestamp': 1461152093, | |
0437307a RA |
376 | }, |
377 | }, | |
378 | { | |
379 | 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924', | |
380 | 'md5': '6d236bf4f3dddc226633ce6e2c3f814d', | |
381 | 'info_dict': { | |
a843464a | 382 | 'id': '314487875924', |
0437307a RA |
383 | 'ext': 'mp4', |
384 | 'title': 'The chaotic GOP immigration vote', | |
385 | '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 | 386 | 'thumbnail': r're:^https?://.*\.jpg$', |
0437307a RA |
387 | 'timestamp': 1406937606, |
388 | 'upload_date': '20140802', | |
cb7d4d0e | 389 | }, |
390 | }, | |
3f125c8c S |
391 | { |
392 | 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952', | |
393 | 'only_matching': True, | |
394 | }, | |
5de008e8 YCH |
395 | { |
396 | # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html | |
397 | 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682', | |
398 | 'only_matching': True, | |
399 | }, | |
87fe568c | 400 | ] |
0bc56fa6 JMF |
401 | |
402 | def _real_extract(self, url): | |
a843464a | 403 | video_id = self._match_id(url) |
895e5c03 RA |
404 | webpage = self._download_webpage(url, video_id) |
405 | ||
406 | data = self._parse_json(self._search_regex( | |
8bdd16b4 | 407 | r'<script[^>]+id="__NEXT_DATA__"[^>]*>({.+?})</script>', |
408 | webpage, 'bootstrap json'), video_id)['props']['initialState'] | |
895e5c03 RA |
409 | video_data = try_get(data, lambda x: x['video']['current'], dict) |
410 | if not video_data: | |
411 | video_data = data['article']['content'][0]['primaryMedia']['video'] | |
412 | title = video_data['headline']['primary'] | |
413 | ||
414 | formats = [] | |
415 | for va in video_data.get('videoAssets', []): | |
416 | public_url = va.get('publicUrl') | |
417 | if not public_url: | |
418 | continue | |
419 | if '://link.theplatform.com/' in public_url: | |
420 | public_url = update_url_query(public_url, {'format': 'redirect'}) | |
421 | format_id = va.get('format') | |
422 | if format_id == 'M3U': | |
423 | formats.extend(self._extract_m3u8_formats( | |
424 | public_url, video_id, 'mp4', 'm3u8_native', | |
425 | m3u8_id=format_id, fatal=False)) | |
426 | continue | |
427 | tbr = int_or_none(va.get('bitrate'), 1000) | |
428 | if tbr: | |
429 | format_id += '-%d' % tbr | |
430 | formats.append({ | |
431 | 'format_id': format_id, | |
432 | 'url': public_url, | |
433 | 'width': int_or_none(va.get('width')), | |
434 | 'height': int_or_none(va.get('height')), | |
435 | 'tbr': tbr, | |
436 | 'ext': 'mp4', | |
437 | }) | |
438 | self._sort_formats(formats) | |
6e416b21 | 439 | |
895e5c03 RA |
440 | subtitles = {} |
441 | closed_captioning = video_data.get('closedCaptioning') | |
442 | if closed_captioning: | |
443 | for cc_url in closed_captioning.values(): | |
444 | if not cc_url: | |
445 | continue | |
446 | subtitles.setdefault('en', []).append({ | |
447 | 'url': cc_url, | |
448 | }) | |
6e416b21 | 449 | |
a843464a | 450 | return { |
a843464a | 451 | 'id': video_id, |
895e5c03 RA |
452 | 'title': title, |
453 | 'description': try_get(video_data, lambda x: x['description']['primary']), | |
454 | 'thumbnail': try_get(video_data, lambda x: x['primaryImage']['url']['primary']), | |
455 | 'duration': parse_duration(video_data.get('duration')), | |
456 | 'timestamp': unified_timestamp(video_data.get('datePublished')), | |
457 | 'formats': formats, | |
458 | 'subtitles': subtitles, | |
a843464a | 459 | } |
be457302 YCH |
460 | |
461 | ||
462 | class NBCOlympicsIE(InfoExtractor): | |
58284890 | 463 | IE_NAME = 'nbcolympics' |
3e376d18 | 464 | _VALID_URL = r'https?://www\.nbcolympics\.com/videos?/(?P<id>[0-9a-z-]+)' |
be457302 YCH |
465 | |
466 | _TEST = { | |
467 | # Geo-restricted to US | |
468 | 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold', | |
469 | 'md5': '54fecf846d05429fbaa18af557ee523a', | |
470 | 'info_dict': { | |
471 | 'id': 'WjTBzDXx5AUq', | |
472 | 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold', | |
473 | 'ext': 'mp4', | |
474 | 'title': 'Rose\'s son Leo was in tears after his dad won gold', | |
475 | 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.', | |
476 | 'timestamp': 1471274964, | |
477 | 'upload_date': '20160815', | |
478 | 'uploader': 'NBCU-SPORTS', | |
479 | }, | |
480 | } | |
481 | ||
482 | def _real_extract(self, url): | |
483 | display_id = self._match_id(url) | |
484 | ||
485 | webpage = self._download_webpage(url, display_id) | |
486 | ||
3e376d18 W |
487 | try: |
488 | drupal_settings = self._parse_json(self._search_regex( | |
489 | r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);', | |
490 | webpage, 'drupal settings'), display_id) | |
491 | ||
492 | iframe_url = drupal_settings['vod']['iframe_url'] | |
493 | theplatform_url = iframe_url.replace( | |
494 | 'vplayer.nbcolympics.com', 'player.theplatform.com') | |
495 | except RegexNotFoundError: | |
496 | theplatform_url = self._search_regex( | |
497 | r"([\"'])embedUrl\1: *([\"'])(?P<embedUrl>.+)\2", | |
498 | webpage, 'embedding URL', group="embedUrl") | |
be457302 YCH |
499 | |
500 | return { | |
501 | '_type': 'url_transparent', | |
502 | 'url': theplatform_url, | |
503 | 'ie_key': ThePlatformIE.ie_key(), | |
504 | 'display_id': display_id, | |
505 | } | |
58284890 RA |
506 | |
507 | ||
508 | class NBCOlympicsStreamIE(AdobePassIE): | |
509 | IE_NAME = 'nbcolympics:stream' | |
510 | _VALID_URL = r'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)' | |
bb36a55c | 511 | _TESTS = [ |
512 | { | |
513 | 'note': 'Tokenized m3u8 source URL', | |
514 | 'url': 'https://stream.nbcolympics.com/womens-soccer-group-round-11', | |
515 | 'info_dict': { | |
516 | 'id': '2019740', | |
517 | 'ext': 'mp4', | |
518 | '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}$", | |
519 | }, | |
520 | 'params': { | |
521 | 'skip_download': 'm3u8', | |
522 | }, | |
523 | }, { | |
524 | 'note': 'Plain m3u8 source URL', | |
525 | 'url': 'https://stream.nbcolympics.com/gymnastics-event-finals-mens-floor-pommel-horse-womens-vault-bars', | |
526 | 'info_dict': { | |
527 | 'id': '2021729', | |
528 | 'ext': 'mp4', | |
529 | '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}$', | |
530 | }, | |
531 | 'params': { | |
532 | 'skip_download': 'm3u8', | |
533 | }, | |
58284890 | 534 | }, |
bb36a55c | 535 | ] |
58284890 RA |
536 | |
537 | def _real_extract(self, url): | |
538 | display_id = self._match_id(url) | |
539 | webpage = self._download_webpage(url, display_id) | |
540 | pid = self._search_regex(r'pid\s*=\s*(\d+);', webpage, 'pid') | |
bb36a55c | 541 | |
58284890 | 542 | event_config = self._download_json( |
bb36a55c | 543 | f'http://stream.nbcolympics.com/data/event_config_{pid}.json', |
544 | pid, 'Downloading event config')['eventConfig'] | |
545 | ||
546 | title = event_config['eventTitle'] | |
547 | is_live = {'live': True, 'replay': False}.get(event_config.get('eventStatus')) | |
548 | if is_live: | |
549 | title = self._live_title(title) | |
550 | ||
58284890 | 551 | source_url = self._download_json( |
bb36a55c | 552 | f'https://api-leap.nbcsports.com/feeds/assets/{pid}?application=NBCOlympics&platform=desktop&format=nbc-player&env=staging', |
553 | pid, 'Downloading leap config' | |
554 | )['videoSources'][0]['cdnSources']['primary'][0]['sourceUrl'] | |
555 | ||
556 | if event_config.get('cdnToken'): | |
557 | ap_resource = self._get_mvpd_resource( | |
558 | event_config.get('resourceId', 'NBCOlympics'), | |
559 | re.sub(r'[^\w\d ]+', '', event_config['eventTitle']), pid, | |
560 | event_config.get('ratingId', 'NO VALUE')) | |
561 | media_token = self._extract_mvpd_auth(url, pid, event_config.get('requestorId', 'NBCOlympics'), ap_resource) | |
562 | ||
563 | source_url = self._download_json( | |
564 | 'https://tokens.playmakerservices.com/', pid, 'Retrieving tokenized URL', | |
565 | data=json.dumps({ | |
566 | 'application': 'NBCSports', | |
567 | 'authentication-type': 'adobe-pass', | |
568 | 'cdn': 'akamai', | |
569 | 'pid': pid, | |
570 | 'platform': 'desktop', | |
571 | 'requestorId': 'NBCOlympics', | |
572 | 'resourceId': base64.b64encode(ap_resource.encode()).decode(), | |
573 | 'token': base64.b64encode(media_token.encode()).decode(), | |
574 | 'url': source_url, | |
575 | 'version': 'v1', | |
576 | }).encode(), | |
577 | )['akamai'][0]['tokenizedUrl'] | |
578 | ||
579 | formats = self._extract_m3u8_formats(source_url, pid, 'mp4', live=is_live) | |
580 | for f in formats: | |
581 | # -http_seekable requires ffmpeg 4.3+ but it doesnt seem possible to | |
582 | # download with ffmpeg without this option | |
583 | f['_ffmpeg_args'] = ['-seekable', '0', '-http_seekable', '0', '-icy', '0'] | |
58284890 RA |
584 | self._sort_formats(formats) |
585 | ||
586 | return { | |
587 | 'id': pid, | |
588 | 'display_id': display_id, | |
589 | 'title': title, | |
590 | 'formats': formats, | |
bb36a55c | 591 | 'is_live': is_live, |
58284890 | 592 | } |