1 from __future__ import unicode_literals
3 from .common import InfoExtractor
11 class NBABaseIE(InfoExtractor):
12 def _get_formats(self, video_id):
13 formats = self._extract_m3u8_formats(
14 'http://nbavod-f.akamaihd.net/i/nba/big%s_,640x360_664m,768x432_996,768x432_1404,960x540_2104,1280x720,.mp4.csmil/master.m3u8' % video_id,
17 formats.extend(self._extract_f4m_formats(
18 'http://nbavod-f.akamaihd.net/z/nba/big%s_,640x360_664m,768x432_996,768x432_1404,960x540_2104,1280x720,.mp4.csmil/manifest.f4m?hdcore=3.4.1.1' % video_id,
21 base_url = 'http://nba.cdn.turner.com/nba/big%s' % video_id
23 'url': base_url + '_nba_ipad.mp4',
29 'url': base_url + '_nba_android_high.mp4',
35 'url': base_url + '_nba_576x324.mp4',
41 'url': base_url + '_640x360_664b.mp4',
47 'url': base_url + '_768x432_1404.mp4',
53 'url': base_url + '_960x540_2104.mp4',
59 'url': base_url + '_1280x720.mp4',
65 self._sort_formats(formats)
68 def _real_extract(self, url):
69 video_id = self._match_id(url)
70 webpage = self._download_webpage(url, video_id)
71 ret = self._extract_metadata(webpage, video_id)
72 ret['id'] = video_id.rpartition('/')[2]
73 ret['formats'] = self._get_formats(video_id)
77 class NBAIE(NBABaseIE):
79 _VALID_URL = r'https?://(?:www\.)?nba\.com/(?:nba/)?video(?P<id>/[^?]*?)/?(?:/index\.html)?(?:\?.*)?$'
81 'url': 'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html',
82 'md5': '9d902940d2a127af3f7f9d2f3dc79c96',
84 'id': '0021200253-okc-bkn-recap.nba',
86 'title': 'Thunder vs. Nets',
87 'description': 'Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.',
89 'timestamp': 1354680189,
90 'upload_date': '20121205',
93 'url': 'http://www.nba.com/video/games/hornets/2014/12/05/0021400276-nyk-cha-play5.nba/',
94 'only_matching': True,
97 def _extract_metadata(self, webpage, video_id):
99 'title': self._html_search_meta('name', webpage),
100 'description': self._html_search_meta('description', webpage),
101 'duration': parse_duration(self._html_search_meta('duration', webpage)),
102 'thumbnail': self._html_search_meta('thumbnailUrl', webpage),
103 'timestamp': parse_iso8601(self._html_search_meta('uploadDate', webpage))
106 class NBAWatchIE(NBABaseIE):
107 IE_NAME = 'nba:watch'
108 _VALID_URL = r'https?://watch.nba\.com/(?:nba/)?video(?P<id>/[^?]*?)/?(?:/index\.html)?(?:\?.*)?$'
110 'url': 'http://watch.nba.com/nba/video/channels/playoffs/2015/05/20/0041400301-cle-atl-recap.nba',
111 'md5': 'b2b39b81cf28615ae0c3360a3f9668c4',
113 'id': '0041400301-cle-atl-recap.nba',
115 'title': 'Hawks vs. Cavaliers Game 1',
116 'description': 'md5:8094c3498d35a9bd6b1a8c396a071b4d',
118 'timestamp': 1432094400,
119 'upload_date': '20150520',
123 def _extract_metadata(self, webpage, video_id):
124 program_id = self._search_regex(r'var\s+programId\s*=\s*(\d+);', webpage, 'program id')
125 metadata = self._download_json(
126 'http://smbsolr.cdnak.neulion.com/solr_nbav6/nba/nba/mlt/?wt=json&fl=name,description,image,runtime,releaseDate&q=sequence%3A' + program_id, video_id)['match']['docs'][0]
128 'title': metadata['name'],
129 'description': metadata.get('description'),
130 'duration': int_or_none(metadata.get('runtime')),
131 'thumbnail': metadata.get('image'),
132 'timestamp': parse_iso8601(metadata.get('releaseDate'))