]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nba.py
Imported Upstream version 2014.12.01
[youtubedl] / 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 mobj = re.match(self._VALID_URL, url)
28 video_id = mobj.group('id')
29
30 webpage = self._download_webpage(url, video_id)
31
32 video_url = 'http://ht-mobile.cdn.turner.com/nba/big' + video_id + '_nba_1280x720.mp4'
33
34 shortened_video_id = video_id.rpartition('/')[2]
35 title = remove_end(
36 self._og_search_title(webpage, default=shortened_video_id), ' : NBA.com')
37
38 description = self._og_search_description(webpage)
39 duration = parse_duration(
40 self._html_search_meta('duration', webpage, 'duration', fatal=False))
41
42 return {
43 'id': shortened_video_id,
44 'url': video_url,
45 'title': title,
46 'description': description,
47 'duration': duration,
48 }