4 from .turner
import TurnerBaseIE
7 compat_urllib_parse_unquote
,
22 class NBACVPBaseIE(TurnerBaseIE
):
23 def _extract_nba_cvp_info(self
, path
, video_id
, fatal
=False):
24 return self
._extract
_cvp
_info
(
25 'http://secure.nba.com/%s' % path
, video_id
, {
27 'media_src': 'http://nba.cdn.turner.com/nba/big',
30 'media_src': 'http://nbavod-f.akamaihd.net',
35 class NBAWatchBaseIE(NBACVPBaseIE
):
36 _VALID_URL_BASE
= r
'https?://(?:(?:www\.)?nba\.com(?:/watch)?|watch\.nba\.com)/'
38 def _extract_video(self
, filter_key
, filter_value
):
39 video
= self
._download
_json
(
40 'https://neulionscnbav2-a.akamaihd.net/solr/nbad_program/usersearch',
42 'fl': 'description,image,name,pid,releaseDate,runtime,tags,seoName',
43 'q': filter_key
+ ':' + filter_value
,
45 })['response']['docs'][0]
47 video_id
= str(video
['pid'])
51 m3u8_url
= (self
._download
_json
(
52 'https://watch.nba.com/service/publishpoint', video_id
, query
={
57 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0_1 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A402 Safari/604.1',
58 }, fatal
=False) or {}).get('path')
60 m3u8_formats
= self
._extract
_m
3u8_formats
(
61 re
.sub(r
'_(?:pc|iphone)\.', '.', m3u8_url
), video_id
, 'mp4',
62 'm3u8_native', m3u8_id
='hls', fatal
=False)
63 formats
.extend(m3u8_formats
)
64 for f
in m3u8_formats
:
67 'format_id': http_f
['format_id'].replace('hls-', 'http-'),
69 'url': http_f
['url'].replace('.m3u8', ''),
71 formats
.append(http_f
)
76 'thumbnail': urljoin('https://nbadsdmt.akamaized.net/media/nba/nba/thumbs/', video
.get('image')),
77 'description': video
.get('description'),
78 'duration': int_or_none(video
.get('runtime')),
79 'timestamp': parse_iso8601(video
.get('releaseDate')),
80 'tags': video
.get('tags'),
83 seo_name
= video
.get('seoName')
84 if seo_name
and re
.search(r
'\d{4}/\d{2}/\d{2}/', seo_name
):
86 if seo_name
.startswith('teams/'):
87 base_path
+= seo_name
.split('/')[1] + '/'
89 cvp_info
= self
._extract
_nba
_cvp
_info
(
90 base_path
+ seo_name
+ '.xml', video_id
, False)
92 formats
.extend(cvp_info
['formats'])
93 info
= merge_dicts(info
, cvp_info
)
95 self
._sort
_formats
(formats
)
96 info
['formats'] = formats
100 class NBAWatchEmbedIE(NBAWatchBaseIE
):
101 IENAME
= 'nba:watch:embed'
102 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'embed\?.*?\bid=(?P<id>\d+)'
104 'url': 'http://watch.nba.com/embed?id=659395',
105 'md5': 'b7e3f9946595f4ca0a13903ce5edd120',
109 'title': 'Mix clip: More than 7 points of Joe Ingles, Luc Mbah a Moute, Blake Griffin and 6 more in Utah Jazz vs. the Clippers, 4/15/2017',
110 'description': 'Mix clip: More than 7 points of Joe Ingles, Luc Mbah a Moute, Blake Griffin and 6 more in Utah Jazz vs. the Clippers, 4/15/2017',
111 'timestamp': 1492228800,
112 'upload_date': '20170415',
116 def _real_extract(self
, url
):
117 video_id
= self
._match
_id
(url
)
118 return self
._extract
_video
('pid', video_id
)
121 class NBAWatchIE(NBAWatchBaseIE
):
122 IE_NAME
= 'nba:watch'
123 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'(?:nba/)?video/(?P<id>.+?(?=/index\.html)|(?:[^/]+/)*[^/?#&]+)'
125 'url': 'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html',
126 'md5': '9d902940d2a127af3f7f9d2f3dc79c96',
130 'title': 'Thunder vs. Nets',
131 'description': 'Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.',
133 'timestamp': 1354597200,
134 'upload_date': '20121204',
137 'url': 'http://www.nba.com/video/games/hornets/2014/12/05/0021400276-nyk-cha-play5.nba/',
138 'only_matching': True,
140 'url': 'http://watch.nba.com/video/channels/playoffs/2015/05/20/0041400301-cle-atl-recap.nba',
141 'md5': 'b2b39b81cf28615ae0c3360a3f9668c4',
145 'title': 'Hawks vs. Cavaliers Game 1',
146 'description': 'md5:8094c3498d35a9bd6b1a8c396a071b4d',
148 'timestamp': 1432094400,
149 'upload_date': '20150521',
152 'url': 'http://watch.nba.com/nba/video/channels/nba_tv/2015/06/11/YT_go_big_go_home_Game4_061115',
153 'only_matching': True,
155 # only CVP mp4 format available
156 'url': 'https://watch.nba.com/video/teams/cavaliers/2012/10/15/sloan121015mov-2249106',
157 'only_matching': True,
159 'url': 'https://watch.nba.com/video/top-100-dunks-from-the-2019-20-season?plsrc=nba&collection=2019-20-season-highlights',
160 'only_matching': True,
163 def _real_extract(self
, url
):
164 display_id
= self
._match
_id
(url
)
165 collection_id
= parse_qs(url
).get('collection', [None])[0]
166 if self
._yes
_playlist
(collection_id
, display_id
):
167 return self
.url_result(
168 'https://www.nba.com/watch/list/collection/' + collection_id
,
169 NBAWatchCollectionIE
.ie_key(), collection_id
)
170 return self
._extract
_video
('seoName', display_id
)
173 class NBAWatchCollectionIE(NBAWatchBaseIE
):
174 IE_NAME
= 'nba:watch:collection'
175 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'list/collection/(?P<id>[^/?#&]+)'
177 'url': 'https://watch.nba.com/list/collection/season-preview-2020',
179 'id': 'season-preview-2020',
181 'playlist_mincount': 43,
185 def _fetch_page(self
, collection_id
, page
):
187 videos
= self
._download
_json
(
188 'https://content-api-prod.nba.com/public/1/endeavor/video-list/collection/' + collection_id
,
189 collection_id
, 'Downloading page %d JSON metadata' % page
, query
={
190 'count': self
._PAGE
_SIZE
,
192 })['results']['videos']
194 program
= video
.get('program') or {}
195 seo_name
= program
.get('seoName') or program
.get('slug')
200 'id': program
.get('id'),
201 'title': program
.get('title') or video
.get('title'),
202 'url': 'https://www.nba.com/watch/video/' + seo_name
,
203 'thumbnail': video
.get('image'),
204 'description': program
.get('description') or video
.get('description'),
205 'duration': parse_duration(program
.get('runtimeHours')),
206 'timestamp': parse_iso8601(video
.get('releaseDate')),
209 def _real_extract(self
, url
):
210 collection_id
= self
._match
_id
(url
)
211 entries
= OnDemandPagedList(
212 functools
.partial(self
._fetch
_page
, collection_id
),
214 return self
.playlist_result(entries
, collection_id
)
217 class NBABaseIE(NBACVPBaseIE
):
218 _VALID_URL_BASE
= r
'''(?x)
219 https?://(?:www\.)?nba\.com/
253 _CHANNEL_PATH_REGEX
= r
'video/channel|series'
255 def _embed_url_result(self
, team
, content_id
):
256 return self
.url_result(update_url_query(
257 'https://secure.nba.com/assets/amp/include/video/iframe.html', {
258 'contentId': content_id
,
260 }), NBAEmbedIE
.ie_key())
262 def _call_api(self
, team
, content_id
, query
, resource
):
263 return self
._download
_json
(
264 'https://api.nba.net/2/%s/video,imported_video,wsc/' % team
,
265 content_id
, 'Download %s JSON metadata' % resource
,
266 query
=query
, headers
={
267 'accessToken': 'internal|bb88df6b4c2244e78822812cecf1ee1b',
268 })['response']['result']
270 def _extract_video(self
, video
, team
, extract_all
=True):
271 video_id
= compat_str(video
['nid'])
272 team
= video
['brand']
276 'title': video
.get('title') or video
.get('headline') or video
['shortHeadline'],
277 'description': video
.get('description'),
278 'timestamp': parse_iso8601(video
.get('published')),
282 captions
= try_get(video
, lambda x
: x
['videoCaptions']['sidecars'], dict) or {}
283 for caption_url
in captions
.values():
284 subtitles
.setdefault('en', []).append({'url': caption_url}
)
287 mp4_url
= video
.get('mp4')
294 source_url
= video
.get('videoSource')
295 if source_url
and not source_url
.startswith('s3://') and self
._is
_valid
_url
(source_url
, video_id
, 'source'):
297 'format_id': 'source',
302 m3u8_url
= video
.get('m3u8')
304 if '.akamaihd.net/i/' in m3u8_url
:
305 formats
.extend(self
._extract
_akamai
_formats
(
306 m3u8_url
, video_id
, {'http': 'pmd.cdn.turner.com'}
))
308 formats
.extend(self
._extract
_m
3u8_formats
(
309 m3u8_url
, video_id
, 'mp4',
310 'm3u8_native', m3u8_id
='hls', fatal
=False))
312 content_xml
= video
.get('contentXml')
313 if team
and content_xml
:
314 cvp_info
= self
._extract
_nba
_cvp
_info
(
315 team
+ content_xml
, video_id
, fatal
=False)
317 formats
.extend(cvp_info
['formats'])
318 subtitles
= self
._merge
_subtitles
(subtitles
, cvp_info
['subtitles'])
319 info
= merge_dicts(info
, cvp_info
)
321 self
._sort
_formats
(formats
)
323 info
.update(self
._embed
_url
_result
(team
, video
['videoId']))
327 'subtitles': subtitles
,
332 def _real_extract(self
, url
):
333 team
, display_id
= self
._match
_valid
_url
(url
).groups()
335 display_id
= compat_urllib_parse_unquote(display_id
)
337 webpage
= self
._download
_webpage
(url
, display_id
)
338 display_id
= self
._search
_regex
(
339 self
._CONTENT
_ID
_REGEX
+ r
'\s*:\s*"([^"]+)"', webpage
, 'video id')
340 return self
._extract
_url
_results
(team
, display_id
)
343 class NBAEmbedIE(NBABaseIE
):
345 _VALID_URL
= r
'https?://secure\.nba\.com/assets/amp/include/video/(?:topI|i)frame\.html\?.*?\bcontentId=(?P<id>[^?#&]+)'
347 'url': 'https://secure.nba.com/assets/amp/include/video/topIframe.html?contentId=teams/bulls/2020/12/04/3478774/1607105587854-20201204_SCHEDULE_RELEASE_FINAL_DRUPAL-3478774&team=bulls&adFree=false&profile=71&videoPlayerName=TAMPCVP&baseUrl=&videoAdsection=nba.com_mobile_web_teamsites_chicagobulls&Env=',
348 'only_matching': True,
350 'url': 'https://secure.nba.com/assets/amp/include/video/iframe.html?contentId=2016/10/29/0021600027boschaplay7&adFree=false&profile=71&team=&videoPlayerName=LAMPCVP',
351 'only_matching': True,
354 def _real_extract(self
, url
):
356 content_id
= qs
['contentId'][0]
357 team
= qs
.get('team', [None])[0]
359 return self
.url_result(
360 'https://watch.nba.com/video/' + content_id
, NBAWatchIE
.ie_key())
361 video
= self
._call
_api
(team
, content_id
, {'videoid': content_id}
, 'video')[0]
362 return self
._extract
_video
(video
, team
)
365 class NBAIE(NBABaseIE
):
367 _VALID_URL
= NBABaseIE
._VALID
_URL
_BASE
+ '(?!%s)video/(?P<id>(?:[^/]+/)*[^/?#&]+)' % NBABaseIE
._CHANNEL
_PATH
_REGEX
369 'url': 'https://www.nba.com/bulls/video/teams/bulls/2020/12/04/3478774/1607105587854-20201204schedulereleasefinaldrupal-3478774',
373 'title': 'AND WE BACK.',
374 'description': 'Part 1 of our 2020-21 schedule is here! Watch our games on NBC Sports Chicago.',
376 'timestamp': 1607112000,
377 'upload_date': '20201218',
380 'url': 'https://www.nba.com/bucks/play#/video/teams%2Fbucks%2F2020%2F12%2F17%2F64860%2F1608252863446-Op_Dream_16x9-64860',
381 'only_matching': True,
383 'url': 'https://www.nba.com/bucks/play#/video/wsc%2Fteams%2F2787C911AA1ACD154B5377F7577CCC7134B2A4B0',
384 'only_matching': True,
386 _CONTENT_ID_REGEX
= r
'videoID'
388 def _extract_url_results(self
, team
, content_id
):
389 return self
._embed
_url
_result
(team
, content_id
)
392 class NBAChannelIE(NBABaseIE
):
393 IENAME
= 'nba:channel'
394 _VALID_URL
= NBABaseIE
._VALID
_URL
_BASE
+ '(?:%s)/(?P<id>[^/?#&]+)' % NBABaseIE
._CHANNEL
_PATH
_REGEX
396 'url': 'https://www.nba.com/blazers/video/channel/summer_league',
398 'title': 'Summer League',
400 'playlist_mincount': 138,
402 'url': 'https://www.nba.com/bucks/play#/series/On%20This%20Date',
403 'only_matching': True,
405 _CONTENT_ID_REGEX
= r
'videoSubCategory'
408 def _fetch_page(self
, team
, channel
, page
):
409 results
= self
._call
_api
(team
, channel
, {
411 'count': self
._PAGE
_SIZE
,
412 'offset': page
* self
._PAGE
_SIZE
,
413 }, 'page %d' % (page
+ 1))
414 for video
in results
:
415 yield self
._extract
_video
(video
, team
, False)
417 def _extract_url_results(self
, team
, content_id
):
418 entries
= OnDemandPagedList(
419 functools
.partial(self
._fetch
_page
, team
, content_id
),
421 return self
.playlist_result(entries
, playlist_title
=content_id
)