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': 'channels/playoffs/2015/05/20/0041400301-cle-atl-recap.nba',
44 'title': 'Hawks vs. Cavaliers Game 1',
45 'description': 'md5:8094c3498d35a9bd6b1a8c396a071b4d',
47 'timestamp': 1432134543,
48 'upload_date': '20150520',
50 'expected_warnings': ['Unable to download f4m manifest'],
52 'url': 'http://www.nba.com/clippers/news/doc-rivers-were-not-trading-blake',
54 'id': 'teams/clippers/2016/02/17/1455672027478-Doc_Feb16_720.mov-297324',
56 'title': 'Practice: Doc Rivers - 2/16/16',
57 'description': 'Head Coach Doc Rivers addresses the media following practice.',
58 'upload_date': '20160216',
59 'timestamp': 1455672000,
63 'skip_download': True,
65 'expected_warnings': ['Unable to download f4m manifest'],
67 'url': 'http://www.nba.com/timberwolves/wiggins-shootaround#',
70 'title': 'Shootaround Access - Dec. 12 | Andrew Wiggins',
74 # Download the whole playlist takes too long time
75 'playlist_items': '1-30',
78 'url': 'http://www.nba.com/timberwolves/wiggins-shootaround#',
80 'id': 'teams/timberwolves/2014/12/12/Wigginsmp4-3462601',
82 'title': 'Shootaround Access - Dec. 12 | Andrew Wiggins',
83 'description': 'Wolves rookie Andrew Wiggins addresses the media after Friday\'s shootaround.',
84 'upload_date': '20141212',
85 'timestamp': 1418418600,
90 'skip_download': True,
92 'expected_warnings': ['Unable to download f4m manifest'],
97 def _fetch_page(self, team, video_id, page):
98 search_url = 'http://searchapp2.nba.com/nba-search/query.jsp?' + compat_urllib_parse_urlencode({
100 'start': page * self._PAGE_SIZE + 1,
101 'npp': (page + 1) * self._PAGE_SIZE + 1,
106 results = self._download_json(
107 search_url, video_id, note='Download page %d of playlist data' % page)['results'][0]
109 yield self.url_result(compat_urlparse.urljoin('http://www.nba.com/', item['url']))
111 def _extract_playlist(self, orig_path, video_id, webpage):
112 team = orig_path.split('/')[0]
114 if self._downloader.params.get('noplaylist'):
115 self.to_screen('Downloading just video because of --no-playlist')
116 video_path = self._search_regex(
117 r'nbaVideoCore\.firstVideo\s*=\s*\'([^\']+)\';', webpage, 'video path')
118 video_url = 'http://www.nba.com/%s/video/%s' % (team, video_path)
119 return self.url_result(video_url)
121 self.to_screen('Downloading playlist - add --no-playlist to just download video')
122 playlist_title = self._og_search_title(webpage, fatal=False)
123 entries = OnDemandPagedList(
124 functools.partial(self._fetch_page, team, video_id),
127 return self.playlist_result(entries, team, playlist_title)
129 def _real_extract(self, url):
130 path, video_id = re.match(self._VALID_URL, url).groups()
132 if path.startswith('nba/'):
135 if 'video/' not in path:
136 webpage = self._download_webpage(url, video_id)
137 path = remove_start(self._search_regex(r'data-videoid="([^"]+)"', webpage, 'video id'), '/')
140 return self._extract_playlist(orig_path, video_id, webpage)
142 # See prepareContentId() of pkgCvp.js
143 if path.startswith('video/teams'):
144 path = 'video/channels/proxy/' + path[6:]
146 return self._extract_cvp_info(
147 'http://www.nba.com/%s.xml' % path, video_id, {
149 'media_src': 'http://nba.cdn.turner.com/nba/big',
152 'media_src': 'http://nbavod-f.akamaihd.net',