[nba] Modernize
[youtube-dl] / youtube_dl / extractor / nba.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     remove_end,
8     parse_duration,
9 )
10
11
12 class NBAIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:watch\.|www\.)?nba\.com/(?:nba/)?video(?P<id>/[^?]*?)/?(?:/index\.html)?(?:\?.*)?$'
14     _TEST = {
15         'url': 'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html',
16         'md5': 'c0edcfc37607344e2ff8f13c378c88a4',
17         'info_dict': {
18             'id': '0021200253-okc-bkn-recap.nba',
19             'ext': 'mp4',
20             'title': 'Thunder vs. Nets',
21             'description': 'Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.',
22             'duration': 181,
23         },
24     }
25
26     def _real_extract(self, url):
27         video_id = self._match_id(url)
28         webpage = self._download_webpage(url, video_id)
29
30         video_url = 'http://ht-mobile.cdn.turner.com/nba/big' + video_id + '_nba_1280x720.mp4'
31
32         shortened_video_id = video_id.rpartition('/')[2]
33         title = remove_end(
34             self._og_search_title(webpage, default=shortened_video_id), ' : NBA.com')
35
36         description = self._og_search_description(webpage)
37         duration = parse_duration(
38             self._html_search_meta('duration', webpage, 'duration'))
39
40         return {
41             'id': shortened_video_id,
42             'url': video_url,
43             'title': title,
44             'description': description,
45             'duration': duration,
46         }