1 from __future__
import unicode_literals
6 from .turner
import TurnerBaseIE
9 compat_urllib_parse_unquote
,
24 class NBACVPBaseIE(TurnerBaseIE
):
25 def _extract_nba_cvp_info(self
, path
, video_id
, fatal
=False):
26 return self
._extract
_cvp
_info
(
27 'http://secure.nba.com/%s' % path
, video_id
, {
29 'media_src': 'http://nba.cdn.turner.com/nba/big',
32 'media_src': 'http://nbavod-f.akamaihd.net',
37 class NBAWatchBaseIE(NBACVPBaseIE
):
38 _VALID_URL_BASE
= r
'https?://(?:(?:www\.)?nba\.com(?:/watch)?|watch\.nba\.com)/'
40 def _extract_video(self
, filter_key
, filter_value
):
41 video
= self
._download
_json
(
42 'https://neulionscnbav2-a.akamaihd.net/solr/nbad_program/usersearch',
44 'fl': 'description,image,name,pid,releaseDate,runtime,tags,seoName',
45 'q': filter_key
+ ':' + filter_value
,
47 })['response']['docs'][0]
49 video_id
= str(video
['pid'])
53 m3u8_url
= (self
._download
_json
(
54 'https://watch.nba.com/service/publishpoint', video_id
, query
={
59 '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',
60 }, fatal
=False) or {}).get('path')
62 m3u8_formats
= self
._extract
_m
3u8_formats
(
63 re
.sub(r
'_(?:pc|iphone)\.', '.', m3u8_url
), video_id
, 'mp4',
64 'm3u8_native', m3u8_id
='hls', fatal
=False)
65 formats
.extend(m3u8_formats
)
66 for f
in m3u8_formats
:
69 'format_id': http_f
['format_id'].replace('hls-', 'http-'),
71 'url': http_f
['url'].replace('.m3u8', ''),
73 formats
.append(http_f
)
78 'thumbnail': urljoin('https://nbadsdmt.akamaized.net/media/nba/nba/thumbs/', video
.get('image')),
79 'description': video
.get('description'),
80 'duration': int_or_none(video
.get('runtime')),
81 'timestamp': parse_iso8601(video
.get('releaseDate')),
82 'tags': video
.get('tags'),
85 seo_name
= video
.get('seoName')
86 if seo_name
and re
.search(r
'\d{4}/\d{2}/\d{2}/', seo_name
):
88 if seo_name
.startswith('teams/'):
89 base_path
+= seo_name
.split('/')[1] + '/'
91 cvp_info
= self
._extract
_nba
_cvp
_info
(
92 base_path
+ seo_name
+ '.xml', video_id
, False)
94 formats
.extend(cvp_info
['formats'])
95 info
= merge_dicts(info
, cvp_info
)
97 self
._sort
_formats
(formats
)
98 info
['formats'] = formats
102 class NBAWatchEmbedIE(NBAWatchBaseIE
):
103 IENAME
= 'nba:watch:embed'
104 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'embed\?.*?\bid=(?P<id>\d+)'
106 'url': 'http://watch.nba.com/embed?id=659395',
107 'md5': 'b7e3f9946595f4ca0a13903ce5edd120',
111 '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',
112 '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',
113 'timestamp': 1492228800,
114 'upload_date': '20170415',
118 def _real_extract(self
, url
):
119 video_id
= self
._match
_id
(url
)
120 return self
._extract
_video
('pid', video_id
)
123 class NBAWatchIE(NBAWatchBaseIE
):
124 IE_NAME
= 'nba:watch'
125 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'(?:nba/)?video/(?P<id>.+?(?=/index\.html)|(?:[^/]+/)*[^/?#&]+)'
127 'url': 'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html',
128 'md5': '9d902940d2a127af3f7f9d2f3dc79c96',
132 'title': 'Thunder vs. Nets',
133 'description': 'Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.',
135 'timestamp': 1354597200,
136 'upload_date': '20121204',
139 'url': 'http://www.nba.com/video/games/hornets/2014/12/05/0021400276-nyk-cha-play5.nba/',
140 'only_matching': True,
142 'url': 'http://watch.nba.com/video/channels/playoffs/2015/05/20/0041400301-cle-atl-recap.nba',
143 'md5': 'b2b39b81cf28615ae0c3360a3f9668c4',
147 'title': 'Hawks vs. Cavaliers Game 1',
148 'description': 'md5:8094c3498d35a9bd6b1a8c396a071b4d',
150 'timestamp': 1432094400,
151 'upload_date': '20150521',
154 'url': 'http://watch.nba.com/nba/video/channels/nba_tv/2015/06/11/YT_go_big_go_home_Game4_061115',
155 'only_matching': True,
157 # only CVP mp4 format available
158 'url': 'https://watch.nba.com/video/teams/cavaliers/2012/10/15/sloan121015mov-2249106',
159 'only_matching': True,
161 'url': 'https://watch.nba.com/video/top-100-dunks-from-the-2019-20-season?plsrc=nba&collection=2019-20-season-highlights',
162 'only_matching': True,
165 def _real_extract(self
, url
):
166 display_id
= self
._match
_id
(url
)
167 collection_id
= parse_qs(url
).get('collection', [None])[0]
169 if self
.get_param('noplaylist'):
170 self
.to_screen('Downloading just video %s because of --no-playlist' % display_id
)
172 self
.to_screen('Downloading playlist %s - add --no-playlist to just download video' % collection_id
)
173 return self
.url_result(
174 'https://www.nba.com/watch/list/collection/' + collection_id
,
175 NBAWatchCollectionIE
.ie_key(), collection_id
)
176 return self
._extract
_video
('seoName', display_id
)
179 class NBAWatchCollectionIE(NBAWatchBaseIE
):
180 IE_NAME
= 'nba:watch:collection'
181 _VALID_URL
= NBAWatchBaseIE
._VALID
_URL
_BASE
+ r
'list/collection/(?P<id>[^/?#&]+)'
183 'url': 'https://watch.nba.com/list/collection/season-preview-2020',
185 'id': 'season-preview-2020',
187 'playlist_mincount': 43,
191 def _fetch_page(self
, collection_id
, page
):
193 videos
= self
._download
_json
(
194 'https://content-api-prod.nba.com/public/1/endeavor/video-list/collection/' + collection_id
,
195 collection_id
, 'Downloading page %d JSON metadata' % page
, query
={
196 'count': self
._PAGE
_SIZE
,
198 })['results']['videos']
200 program
= video
.get('program') or {}
201 seo_name
= program
.get('seoName') or program
.get('slug')
206 'id': program
.get('id'),
207 'title': program
.get('title') or video
.get('title'),
208 'url': 'https://www.nba.com/watch/video/' + seo_name
,
209 'thumbnail': video
.get('image'),
210 'description': program
.get('description') or video
.get('description'),
211 'duration': parse_duration(program
.get('runtimeHours')),
212 'timestamp': parse_iso8601(video
.get('releaseDate')),
215 def _real_extract(self
, url
):
216 collection_id
= self
._match
_id
(url
)
217 entries
= OnDemandPagedList(
218 functools
.partial(self
._fetch
_page
, collection_id
),
220 return self
.playlist_result(entries
, collection_id
)
223 class NBABaseIE(NBACVPBaseIE
):
224 _VALID_URL_BASE
= r
'''(?x)
225 https?://(?:www\.)?nba\.com/
259 _CHANNEL_PATH_REGEX
= r
'video/channel|series'
261 def _embed_url_result(self
, team
, content_id
):
262 return self
.url_result(update_url_query(
263 'https://secure.nba.com/assets/amp/include/video/iframe.html', {
264 'contentId': content_id
,
266 }), NBAEmbedIE
.ie_key())
268 def _call_api(self
, team
, content_id
, query
, resource
):
269 return self
._download
_json
(
270 'https://api.nba.net/2/%s/video,imported_video,wsc/' % team
,
271 content_id
, 'Download %s JSON metadata' % resource
,
272 query
=query
, headers
={
273 'accessToken': 'internal|bb88df6b4c2244e78822812cecf1ee1b',
274 })['response']['result']
276 def _extract_video(self
, video
, team
, extract_all
=True):
277 video_id
= compat_str(video
['nid'])
278 team
= video
['brand']
282 'title': video
.get('title') or video
.get('headline') or video
['shortHeadline'],
283 'description': video
.get('description'),
284 'timestamp': parse_iso8601(video
.get('published')),
288 captions
= try_get(video
, lambda x
: x
['videoCaptions']['sidecars'], dict) or {}
289 for caption_url
in captions
.values():
290 subtitles
.setdefault('en', []).append({'url': caption_url}
)
293 mp4_url
= video
.get('mp4')
300 source_url
= video
.get('videoSource')
301 if source_url
and not source_url
.startswith('s3://') and self
._is
_valid
_url
(source_url
, video_id
, 'source'):
303 'format_id': 'source',
308 m3u8_url
= video
.get('m3u8')
310 if '.akamaihd.net/i/' in m3u8_url
:
311 formats
.extend(self
._extract
_akamai
_formats
(
312 m3u8_url
, video_id
, {'http': 'pmd.cdn.turner.com'}
))
314 formats
.extend(self
._extract
_m
3u8_formats
(
315 m3u8_url
, video_id
, 'mp4',
316 'm3u8_native', m3u8_id
='hls', fatal
=False))
318 content_xml
= video
.get('contentXml')
319 if team
and content_xml
:
320 cvp_info
= self
._extract
_nba
_cvp
_info
(
321 team
+ content_xml
, video_id
, fatal
=False)
323 formats
.extend(cvp_info
['formats'])
324 subtitles
= self
._merge
_subtitles
(subtitles
, cvp_info
['subtitles'])
325 info
= merge_dicts(info
, cvp_info
)
327 self
._sort
_formats
(formats
)
329 info
.update(self
._embed
_url
_result
(team
, video
['videoId']))
333 'subtitles': subtitles
,
338 def _real_extract(self
, url
):
339 team
, display_id
= self
._match
_valid
_url
(url
).groups()
341 display_id
= compat_urllib_parse_unquote(display_id
)
343 webpage
= self
._download
_webpage
(url
, display_id
)
344 display_id
= self
._search
_regex
(
345 self
._CONTENT
_ID
_REGEX
+ r
'\s*:\s*"([^"]+)"', webpage
, 'video id')
346 return self
._extract
_url
_results
(team
, display_id
)
349 class NBAEmbedIE(NBABaseIE
):
351 _VALID_URL
= r
'https?://secure\.nba\.com/assets/amp/include/video/(?:topI|i)frame\.html\?.*?\bcontentId=(?P<id>[^?#&]+)'
353 '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=',
354 'only_matching': True,
356 'url': 'https://secure.nba.com/assets/amp/include/video/iframe.html?contentId=2016/10/29/0021600027boschaplay7&adFree=false&profile=71&team=&videoPlayerName=LAMPCVP',
357 'only_matching': True,
360 def _real_extract(self
, url
):
362 content_id
= qs
['contentId'][0]
363 team
= qs
.get('team', [None])[0]
365 return self
.url_result(
366 'https://watch.nba.com/video/' + content_id
, NBAWatchIE
.ie_key())
367 video
= self
._call
_api
(team
, content_id
, {'videoid': content_id}
, 'video')[0]
368 return self
._extract
_video
(video
, team
)
371 class NBAIE(NBABaseIE
):
373 _VALID_URL
= NBABaseIE
._VALID
_URL
_BASE
+ '(?!%s)video/(?P<id>(?:[^/]+/)*[^/?#&]+)' % NBABaseIE
._CHANNEL
_PATH
_REGEX
375 'url': 'https://www.nba.com/bulls/video/teams/bulls/2020/12/04/3478774/1607105587854-20201204schedulereleasefinaldrupal-3478774',
379 'title': 'AND WE BACK.',
380 'description': 'Part 1 of our 2020-21 schedule is here! Watch our games on NBC Sports Chicago.',
382 'timestamp': 1607112000,
383 'upload_date': '20201218',
386 'url': 'https://www.nba.com/bucks/play#/video/teams%2Fbucks%2F2020%2F12%2F17%2F64860%2F1608252863446-Op_Dream_16x9-64860',
387 'only_matching': True,
389 'url': 'https://www.nba.com/bucks/play#/video/wsc%2Fteams%2F2787C911AA1ACD154B5377F7577CCC7134B2A4B0',
390 'only_matching': True,
392 _CONTENT_ID_REGEX
= r
'videoID'
394 def _extract_url_results(self
, team
, content_id
):
395 return self
._embed
_url
_result
(team
, content_id
)
398 class NBAChannelIE(NBABaseIE
):
399 IENAME
= 'nba:channel'
400 _VALID_URL
= NBABaseIE
._VALID
_URL
_BASE
+ '(?:%s)/(?P<id>[^/?#&]+)' % NBABaseIE
._CHANNEL
_PATH
_REGEX
402 'url': 'https://www.nba.com/blazers/video/channel/summer_league',
404 'title': 'Summer League',
406 'playlist_mincount': 138,
408 'url': 'https://www.nba.com/bucks/play#/series/On%20This%20Date',
409 'only_matching': True,
411 _CONTENT_ID_REGEX
= r
'videoSubCategory'
414 def _fetch_page(self
, team
, channel
, page
):
415 results
= self
._call
_api
(team
, channel
, {
417 'count': self
._PAGE
_SIZE
,
418 'offset': page
* self
._PAGE
_SIZE
,
419 }, 'page %d' % (page
+ 1))
420 for video
in results
:
421 yield self
._extract
_video
(video
, team
, False)
423 def _extract_url_results(self
, team
, content_id
):
424 entries
= OnDemandPagedList(
425 functools
.partial(self
._fetch
_page
, team
, content_id
),
427 return self
.playlist_result(entries
, playlist_title
=content_id
)