5 from .turner
import TurnerBaseIE
19 class NBACVPBaseIE(TurnerBaseIE
):
20 def _extract_nba_cvp_info(self
, path
, video_id
, fatal
=False):
21 return self
._extract
_cvp
_info
(
22 f
'http://secure.nba.com/{path}', video_id
, {
24 'media_src': 'http://nba.cdn.turner.com/nba/big',
27 'media_src': 'http://nbavod-f.akamaihd.net',
32 class NBAWatchBaseIE(NBACVPBaseIE
):
33 _VALID_URL_BASE
= r
'https?://(?:(?:www\.)?nba\.com(?:/watch)?|watch\.nba\.com)/'
35 def _extract_video(self
, filter_key
, filter_value
):
36 video
= self
._download
_json
(
37 'https://neulionscnbav2-a.akamaihd.net/solr/nbad_program/usersearch',
39 'fl': 'description,image,name,pid,releaseDate,runtime,tags,seoName',
40 'q': filter_key
+ ':' + filter_value
,
42 })['response']['docs'][0]
44 video_id
= str(video
['pid'])
48 m3u8_url
= (self
._download
_json
(
49 'https://watch.nba.com/service/publishpoint', video_id
, query
={
54 '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',
55 }, fatal
=False) or {}).get('path')
57 m3u8_formats
= self
._extract
_m
3u8_formats
(
58 re
.sub(r
'_(?:pc|iphone)\.', '.', m3u8_url
), video_id
, 'mp4',
59 'm3u8_native', m3u8_id
='hls', fatal
=False)
60 formats
.extend(m3u8_formats
)
61 for f
in m3u8_formats
:
64 'format_id': http_f
['format_id'].replace('hls-', 'http-'),
66 'url': http_f
['url'].replace('.m3u8', ''),
68 formats
.append(http_f
)
73 'thumbnail': urljoin('https://nbadsdmt.akamaized.net/media/nba/nba/thumbs/', video
.get('image')),
74 'description': video
.get('description'),
75 'duration': int_or_none(video
.get('runtime')),
76 'timestamp': parse_iso8601(video
.get('releaseDate')),
77 'tags': video
.get('tags'),
80 seo_name
= video
.get('seoName')
81 if seo_name
and re
.search(r
'\d{4}/\d{2}/\d{2}/', seo_name
):
83 if seo_name
.startswith('teams/'):
84 base_path
+= seo_name
.split('/')[1] + '/'
86 cvp_info
= self
._extract
_nba
_cvp
_info
(
87 base_path
+ seo_name
+ '.xml', video_id
, False)
89 formats
.extend(cvp_info
['formats'])
90 info
= merge_dicts(info
, cvp_info
)
92 info
['formats'] = formats
96 class NBAWatchEmbedIE(NBAWatchBaseIE
):
97 IE_NAME
= 'nba:watch:embed'
98 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'embed\?.*?\bid=(?P<id>\d+)'
100 'url': 'http://watch.nba.com/embed?id=659395',
101 'md5': 'b7e3f9946595f4ca0a13903ce5edd120',
105 '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',
106 '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',
107 'timestamp': 1492228800,
108 'upload_date': '20170415',
112 def _real_extract(self
, url
):
113 video_id
= self
._match
_id
(url
)
114 return self
._extract
_video
('pid', video_id
)
117 class NBAWatchIE(NBAWatchBaseIE
):
118 IE_NAME
= 'nba:watch'
119 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'(?:nba/)?video/(?P<id>.+?(?=/index\.html)|(?:[^/]+/)*[^/?#&]+)'
121 'url': 'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html',
122 'md5': '9d902940d2a127af3f7f9d2f3dc79c96',
126 'title': 'Thunder vs. Nets',
127 'description': 'Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.',
129 'timestamp': 1354597200,
130 'upload_date': '20121204',
133 'url': 'http://www.nba.com/video/games/hornets/2014/12/05/0021400276-nyk-cha-play5.nba/',
134 'only_matching': True,
136 'url': 'http://watch.nba.com/video/channels/playoffs/2015/05/20/0041400301-cle-atl-recap.nba',
137 'md5': 'b2b39b81cf28615ae0c3360a3f9668c4',
141 'title': 'Hawks vs. Cavaliers Game 1',
142 'description': 'md5:8094c3498d35a9bd6b1a8c396a071b4d',
144 'timestamp': 1432094400,
145 'upload_date': '20150521',
148 'url': 'http://watch.nba.com/nba/video/channels/nba_tv/2015/06/11/YT_go_big_go_home_Game4_061115',
149 'only_matching': True,
151 # only CVP mp4 format available
152 'url': 'https://watch.nba.com/video/teams/cavaliers/2012/10/15/sloan121015mov-2249106',
153 'only_matching': True,
155 'url': 'https://watch.nba.com/video/top-100-dunks-from-the-2019-20-season?plsrc=nba&collection=2019-20-season-highlights',
156 'only_matching': True,
159 def _real_extract(self
, url
):
160 display_id
= self
._match
_id
(url
)
161 collection_id
= parse_qs(url
).get('collection', [None])[0]
162 if self
._yes
_playlist
(collection_id
, display_id
):
163 return self
.url_result(
164 'https://www.nba.com/watch/list/collection/' + collection_id
,
165 NBAWatchCollectionIE
.ie_key(), collection_id
)
166 return self
._extract
_video
('seoName', display_id
)
169 class NBAWatchCollectionIE(NBAWatchBaseIE
):
170 IE_NAME
= 'nba:watch:collection'
171 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'list/collection/(?P<id>[^/?#&]+)'
173 'url': 'https://watch.nba.com/list/collection/season-preview-2020',
175 'id': 'season-preview-2020',
177 'playlist_mincount': 43,
181 def _fetch_page(self
, collection_id
, page
):
183 videos
= self
._download
_json
(
184 'https://content-api-prod.nba.com/public/1/endeavor/video-list/collection/' + collection_id
,
185 collection_id
, f
'Downloading page {page} JSON metadata', query
={
186 'count': self
._PAGE
_SIZE
,
188 })['results']['videos']
190 program
= video
.get('program') or {}
191 seo_name
= program
.get('seoName') or program
.get('slug')
196 'id': program
.get('id'),
197 'title': program
.get('title') or video
.get('title'),
198 'url': 'https://www.nba.com/watch/video/' + seo_name
,
199 'thumbnail': video
.get('image'),
200 'description': program
.get('description') or video
.get('description'),
201 'duration': parse_duration(program
.get('runtimeHours')),
202 'timestamp': parse_iso8601(video
.get('releaseDate')),
205 def _real_extract(self
, url
):
206 collection_id
= self
._match
_id
(url
)
207 entries
= OnDemandPagedList(
208 functools
.partial(self
._fetch
_page
, collection_id
),
210 return self
.playlist_result(entries
, collection_id
)
213 class NBABaseIE(NBACVPBaseIE
):
214 _VALID_URL_BASE
= r
'''(?x)
215 https?://(?:www\.)?nba\.com/
249 _CHANNEL_PATH_REGEX
= r
'video/channel|series'
251 def _embed_url_result(self
, team
, content_id
):
252 return self
.url_result(update_url_query(
253 'https://secure.nba.com/assets/amp/include/video/iframe.html', {
254 'contentId': content_id
,
256 }), NBAEmbedIE
.ie_key())
258 def _call_api(self
, team
, content_id
, query
, resource
):
259 return self
._download
_json
(
260 f
'https://api.nba.net/2/{team}/video,imported_video,wsc/',
261 content_id
, f
'Download {resource} JSON metadata',
262 query
=query
, headers
={
263 'accessToken': 'internal|bb88df6b4c2244e78822812cecf1ee1b',
264 })['response']['result']
266 def _extract_video(self
, video
, team
, extract_all
=True):
267 video_id
= str(video
['nid'])
268 team
= video
['brand']
272 'title': video
.get('title') or video
.get('headline') or video
['shortHeadline'],
273 'description': video
.get('description'),
274 'timestamp': parse_iso8601(video
.get('published')),
278 captions
= try_get(video
, lambda x
: x
['videoCaptions']['sidecars'], dict) or {}
279 for caption_url
in captions
.values():
280 subtitles
.setdefault('en', []).append({'url': caption_url
})
283 mp4_url
= video
.get('mp4')
290 source_url
= video
.get('videoSource')
291 if source_url
and not source_url
.startswith('s3://') and self
._is
_valid
_url
(source_url
, video_id
, 'source'):
293 'format_id': 'source',
298 m3u8_url
= video
.get('m3u8')
300 if '.akamaihd.net/i/' in m3u8_url
:
301 formats
.extend(self
._extract
_akamai
_formats
(
302 m3u8_url
, video_id
, {'http': 'pmd.cdn.turner.com'}))
304 formats
.extend(self
._extract
_m
3u8_formats
(
305 m3u8_url
, video_id
, 'mp4',
306 'm3u8_native', m3u8_id
='hls', fatal
=False))
308 content_xml
= video
.get('contentXml')
309 if team
and content_xml
:
310 cvp_info
= self
._extract
_nba
_cvp
_info
(
311 team
+ content_xml
, video_id
, fatal
=False)
313 formats
.extend(cvp_info
['formats'])
314 subtitles
= self
._merge
_subtitles
(subtitles
, cvp_info
['subtitles'])
315 info
= merge_dicts(info
, cvp_info
)
318 info
.update(self
._embed
_url
_result
(team
, video
['videoId']))
322 'subtitles': subtitles
,
327 def _real_extract(self
, url
):
328 team
, display_id
= self
._match
_valid
_url
(url
).groups()
330 display_id
= urllib
.parse
.unquote(display_id
)
332 webpage
= self
._download
_webpage
(url
, display_id
)
333 display_id
= self
._search
_regex
(
334 self
._CONTENT
_ID
_REGEX
+ r
'\s*:\s*"([^"]+)"', webpage
, 'video id')
335 return self
._extract
_url
_results
(team
, display_id
)
338 class NBAEmbedIE(NBABaseIE
):
339 IE_NAME
= 'nba:embed'
340 _VALID_URL
= r
'https?://secure\.nba\.com/assets/amp/include/video/(?:topI|i)frame\.html\?.*?\bcontentId=(?P<id>[^?#&]+)'
342 '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=',
343 'only_matching': True,
345 'url': 'https://secure.nba.com/assets/amp/include/video/iframe.html?contentId=2016/10/29/0021600027boschaplay7&adFree=false&profile=71&team=&videoPlayerName=LAMPCVP',
346 'only_matching': True,
349 def _real_extract(self
, url
):
351 content_id
= qs
['contentId'][0]
352 team
= qs
.get('team', [None])[0]
354 return self
.url_result(
355 'https://watch.nba.com/video/' + content_id
, NBAWatchIE
.ie_key())
356 video
= self
._call
_api
(team
, content_id
, {'videoid': content_id
}, 'video')[0]
357 return self
._extract
_video
(video
, team
)
360 class NBAIE(NBABaseIE
):
362 _VALID_URL
= NBABaseIE
._VALID
_URL
_BASE
+ f
'(?!{NBABaseIE._CHANNEL_PATH_REGEX})video/(?P<id>(?:[^/]+/)*[^/?#&]+)'
364 'url': 'https://www.nba.com/bulls/video/teams/bulls/2020/12/04/3478774/1607105587854-20201204schedulereleasefinaldrupal-3478774',
368 'title': 'AND WE BACK.',
369 'description': 'Part 1 of our 2020-21 schedule is here! Watch our games on NBC Sports Chicago.',
371 'timestamp': 1607112000,
372 'upload_date': '20201218',
375 'url': 'https://www.nba.com/bucks/play#/video/teams%2Fbucks%2F2020%2F12%2F17%2F64860%2F1608252863446-Op_Dream_16x9-64860',
376 'only_matching': True,
378 'url': 'https://www.nba.com/bucks/play#/video/wsc%2Fteams%2F2787C911AA1ACD154B5377F7577CCC7134B2A4B0',
379 'only_matching': True,
381 _CONTENT_ID_REGEX
= r
'videoID'
383 def _extract_url_results(self
, team
, content_id
):
384 return self
._embed
_url
_result
(team
, content_id
)
387 class NBAChannelIE(NBABaseIE
):
388 IE_NAME
= 'nba:channel'
389 _VALID_URL
= NBABaseIE
._VALID
_URL
_BASE
+ f
'(?:{NBABaseIE._CHANNEL_PATH_REGEX})/(?P<id>[^/?#&]+)'
391 'url': 'https://www.nba.com/blazers/video/channel/summer_league',
393 'title': 'Summer League',
395 'playlist_mincount': 138,
397 'url': 'https://www.nba.com/bucks/play#/series/On%20This%20Date',
398 'only_matching': True,
400 _CONTENT_ID_REGEX
= r
'videoSubCategory'
403 def _fetch_page(self
, team
, channel
, page
):
404 results
= self
._call
_api
(team
, channel
, {
406 'count': self
._PAGE
_SIZE
,
407 'offset': page
* self
._PAGE
_SIZE
,
408 }, f
'page {page + 1}')
409 for video
in results
:
410 yield self
._extract
_video
(video
, team
, False)
412 def _extract_url_results(self
, team
, content_id
):
413 entries
= OnDemandPagedList(
414 functools
.partial(self
._fetch
_page
, team
, content_id
),
416 return self
.playlist_result(entries
, playlist_title
=content_id
)