]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/nba.py
Move NBA IE into its own file
[yt-dlp.git] / youtube_dl / extractor / nba.py
CommitLineData
5b286728
PH
1import re
2
3from .common import InfoExtractor
4from ..utils import (
5 ExtractorError,
6)
7
8
9class NBAIE(InfoExtractor):
10 _VALID_URL = r'^(?:https?://)?(?:watch\.|www\.)?nba\.com/(?:nba/)?video(/[^?]*?)(?:/index\.html)?(?:\?.*)?$'
11
12 def _real_extract(self, url):
13 mobj = re.match(self._VALID_URL, url)
14 if mobj is None:
15 raise ExtractorError(u'Invalid URL: %s' % url)
16
17 video_id = mobj.group(1)
18
19 webpage = self._download_webpage(url, video_id)
20
21 video_url = u'http://ht-mobile.cdn.turner.com/nba/big' + video_id + '_nba_1280x720.mp4'
22
23 shortened_video_id = video_id.rpartition('/')[2]
24 title = self._html_search_regex(r'<meta property="og:title" content="(.*?)"',
25 webpage, 'title', default=shortened_video_id).replace('NBA.com: ', '')
26
27 # It isn't there in the HTML it returns to us
28 # uploader_date = self._html_search_regex(r'<b>Date:</b> (.*?)</div>', webpage, 'upload_date', fatal=False)
29
30 description = self._html_search_regex(r'<meta name="description" (?:content|value)="(.*?)" />', webpage, 'description', fatal=False)
31
32 info = {
33 'id': shortened_video_id,
34 'url': video_url,
35 'ext': 'mp4',
36 'title': title,
37 # 'uploader_date': uploader_date,
38 'description': description,
39 }
40 return [info]