1 from __future__ import unicode_literals
6 from .turner import TurnerBaseIE
8 compat_urllib_parse_urlencode,
17 class NBAIE(TurnerBaseIE):
18 _VALID_URL = r'https?://(?:watch\.|www\.)?nba\.com/(?P<path>(?:[^/]+/)+(?P<id>[^?]*?))/?(?:/index\.html)?(?:\?.*)?$'
20 'url': 'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html',
21 'md5': '9e7729d3010a9c71506fd1248f74e4f4',
23 'id': '0021200253-okc-bkn-recap',
25 'title': 'Thunder vs. Nets',
26 'description': 'Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.',
28 'timestamp': 1354638466,
29 'upload_date': '20121204',
33 'skip_download': True,
36 'url': 'http://www.nba.com/video/games/hornets/2014/12/05/0021400276-nyk-cha-play5.nba/',
37 'only_matching': True,
39 'url': 'http://watch.nba.com/video/channels/playoffs/2015/05/20/0041400301-cle-atl-recap.nba',
40 'md5': 'b2b39b81cf28615ae0c3360a3f9668c4',
42 'id': '0041400301-cle-atl-recap',
44 'title': 'Hawks vs. Cavaliers Game 1',
45 'description': 'md5:8094c3498d35a9bd6b1a8c396a071b4d',
47 'timestamp': 1432134543,
48 'upload_date': '20150520',
51 'url': 'http://www.nba.com/clippers/news/doc-rivers-were-not-trading-blake',
53 'id': '1455672027478-Doc_Feb16_720',
55 'title': 'Practice: Doc Rivers - 2/16/16',
56 'description': 'Head Coach Doc Rivers addresses the media following practice.',
57 'upload_date': '20160216',
58 'timestamp': 1455672000,
62 'skip_download': True,
65 'url': 'http://www.nba.com/timberwolves/wiggins-shootaround#',
68 'title': 'Shootaround Access - Dec. 12 | Andrew Wiggins',
72 # Download the whole playlist takes too long time
73 'playlist_items': '1-30',
76 'url': 'http://www.nba.com/timberwolves/wiggins-shootaround#',
78 'id': 'Wigginsmp4-3462601',
80 'title': 'Shootaround Access - Dec. 12 | Andrew Wiggins',
81 'description': 'Wolves rookie Andrew Wiggins addresses the media after Friday\'s shootaround.',
82 'upload_date': '20141212',
83 'timestamp': 1418418600,
88 'skip_download': True,
94 def _fetch_page(self, team, video_id, page):
95 search_url = 'http://searchapp2.nba.com/nba-search/query.jsp?' + compat_urllib_parse_urlencode({
97 'start': page * self._PAGE_SIZE + 1,
98 'npp': (page + 1) * self._PAGE_SIZE + 1,
103 results = self._download_json(
104 search_url, video_id, note='Download page %d of playlist data' % page)['results'][0]
106 yield self.url_result(compat_urlparse.urljoin('http://www.nba.com/', item['url']))
108 def _extract_playlist(self, orig_path, video_id, webpage):
109 team = orig_path.split('/')[0]
111 if self._downloader.params.get('noplaylist'):
112 self.to_screen('Downloading just video because of --no-playlist')
113 video_path = self._search_regex(
114 r'nbaVideoCore\.firstVideo\s*=\s*\'([^\']+)\';', webpage, 'video path')
115 video_url = 'http://www.nba.com/%s/video/%s' % (team, video_path)
116 return self.url_result(video_url)
118 self.to_screen('Downloading playlist - add --no-playlist to just download video')
119 playlist_title = self._og_search_title(webpage, fatal=False)
120 entries = OnDemandPagedList(
121 functools.partial(self._fetch_page, team, video_id),
122 self._PAGE_SIZE, use_cache=True)
124 return self.playlist_result(entries, team, playlist_title)
126 def _real_extract(self, url):
127 path, video_id = re.match(self._VALID_URL, url).groups()
129 if path.startswith('nba/'):
132 if 'video/' not in path:
133 webpage = self._download_webpage(url, video_id)
134 path = remove_start(self._search_regex(r'data-videoid="([^"]+)"', webpage, 'video id'), '/')
137 return self._extract_playlist(orig_path, video_id, webpage)
139 # See prepareContentId() of pkgCvp.js
140 if path.startswith('video/teams'):
141 path = 'video/channels/proxy/' + path[6:]
143 return self._extract_cvp_info(
144 'http://www.nba.com/%s.xml' % path, video_id, {
146 'media_src': 'http://nba.cdn.turner.com/nba/big',
149 'media_src': 'http://nbavod-f.akamaihd.net',