]>
Commit | Line | Data |
---|---|---|
26a78d4b JMF |
1 | from __future__ import unicode_literals |
2 | ||
ecf6de5b | 3 | import re |
4 | ||
5b286728 | 5 | from .common import InfoExtractor |
7bbc6428 | 6 | from ..utils import ( |
7bbc6428 | 7 | parse_duration, |
8fc226ef | 8 | int_or_none, |
7bbc6428 | 9 | ) |
5b286728 PH |
10 | |
11 | ||
c233e6bc | 12 | class NBAIE(InfoExtractor): |
13 | _VALID_URL = r'https?://(?:watch\.|www\.)?nba\.com/(?:nba/)?video/(?P<id>[^?]*?)/?(?:/index\.html)?(?:\?.*)?$' | |
6a3e0103 | 14 | _TESTS = [{ |
26a78d4b | 15 | 'url': 'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html', |
8fc226ef | 16 | 'md5': '9d902940d2a127af3f7f9d2f3dc79c96', |
26a78d4b | 17 | 'info_dict': { |
c233e6bc | 18 | 'id': '0021200253-okc-bkn-recap', |
2ff7f897 | 19 | 'ext': 'mp4', |
26a78d4b | 20 | 'title': 'Thunder vs. Nets', |
7bbc6428 S |
21 | 'description': 'Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.', |
22 | 'duration': 181, | |
c233e6bc | 23 | 'timestamp': 1354638466, |
24 | 'upload_date': '20121204', | |
26a78d4b | 25 | }, |
6a3e0103 PH |
26 | }, { |
27 | 'url': 'http://www.nba.com/video/games/hornets/2014/12/05/0021400276-nyk-cha-play5.nba/', | |
28 | 'only_matching': True, | |
c233e6bc | 29 | },{ |
8a278a1d | 30 | 'url': 'http://watch.nba.com/nba/video/channels/playoffs/2015/05/20/0041400301-cle-atl-recap.nba', |
8fc226ef | 31 | 'md5': 'b2b39b81cf28615ae0c3360a3f9668c4', |
8a278a1d | 32 | 'info_dict': { |
c233e6bc | 33 | 'id': '0041400301-cle-atl-recap', |
8a278a1d | 34 | 'ext': 'mp4', |
8fc226ef | 35 | 'title': 'Hawks vs. Cavaliers Game 1', |
8a278a1d YCH |
36 | 'description': 'md5:8094c3498d35a9bd6b1a8c396a071b4d', |
37 | 'duration': 228, | |
c233e6bc | 38 | 'timestamp': 1432134543, |
8fc226ef | 39 | 'upload_date': '20150520', |
8a278a1d | 40 | } |
6a3e0103 | 41 | }] |
5b286728 | 42 | |
c233e6bc | 43 | def _real_extract(self, url): |
44 | video_id = self._match_id(url) | |
45 | video_info = self._download_xml('http://www.nba.com/video/%s.xml' % video_id, video_id) | |
46 | video_id = video_info.find('slug').text | |
47 | title = video_info.find('headline').text | |
48 | description = video_info.find('description').text | |
49 | duration = parse_duration(video_info.find('length').text) | |
50 | timestamp = int_or_none(video_info.find('dateCreated').attrib.get('uts')) | |
51 | ||
52 | thumbnails = [] | |
53 | for image in video_info.find('images'): | |
54 | thumbnails.append({ | |
55 | 'id': image.attrib.get('cut'), | |
56 | 'url': image.text, | |
57 | 'width': int_or_none(image.attrib.get('width')), | |
58 | 'height': int_or_none(image.attrib.get('height')), | |
59 | }) | |
60 | ||
61 | formats = [] | |
62 | for video_file in video_info.find('files').iter('file'): | |
63 | video_url = video_file.text | |
139f2782 | 64 | if video_url.startswith('/'): |
65 | continue | |
c233e6bc | 66 | if video_url.endswith('.m3u8'): |
67 | formats.extend(self._extract_m3u8_formats(video_url, video_id)) | |
68 | elif video_url.endswith('.f4m'): | |
69 | formats.extend(self._extract_f4m_formats(video_url + '?hdcore=3.4.1.1', video_id)) | |
70 | else: | |
71 | key = video_file.attrib.get('bitrate') | |
ecf6de5b | 72 | width, height, bitrate = re.search(r'(\d+)x(\d+)(?:_(\d+))?', key).groups() |
c233e6bc | 73 | formats.append({ |
74 | 'format_id': key, | |
75 | 'url': video_url, | |
ecf6de5b | 76 | 'width': int_or_none(width), |
77 | 'height': int_or_none(height), | |
78 | 'tbr': int_or_none(bitrate), | |
c233e6bc | 79 | }) |
80 | self._sort_formats(formats) | |
81 | ||
26a78d4b | 82 | return { |
c233e6bc | 83 | 'id': video_id, |
84 | 'title': title, | |
85 | 'description': description, | |
86 | 'duration': duration, | |
87 | 'timestamp': timestamp, | |
88 | 'thumbnails': thumbnails, | |
89 | 'formats': formats, | |
5b286728 | 90 | } |