From 4cc3d0742663c92ef5cf89927edee4300666ea69 Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Thu, 13 Dec 2012 21:27:57 +0100 Subject: [PATCH] NBA IE (Closes #590) --- test/tests.json | 6 +++++ youtube_dl/InfoExtractors.py | 46 ++++++++++++++++++++++++++++++++++++ youtube_dl/__init__.py | 1 + 3 files changed, 53 insertions(+) diff --git a/test/tests.json b/test/tests.json index 706149bf8..58e73e7e1 100644 --- a/test/tests.json +++ b/test/tests.json @@ -58,5 +58,11 @@ "file": "XNDgyMDQ2NTQw_part00.flv", "md5": "ffe3f2e435663dc2d1eea34faeff5b5b", "params": { "test": false } + }, + { + "name": "NBA", + "url": "http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html", + "file": "0021200253-okc-bkn-recap.nba.mp4", + "md5": "c0edcfc37607344e2ff8f13c378c88a4" } ] diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index 1b37eb648..b7fedabb2 100644 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -3590,3 +3590,49 @@ class GooglePlusIE(InfoExtractor): 'title': video_title.decode('utf-8'), 'ext': video_extension.decode('utf-8'), }] + +class NBAIE(InfoExtractor): + _VALID_URL = r'^(?:https?://)?(?:watch\.|www\.)?nba\.com/(?:nba/)?video(/[^?]*)(\?.*)?$' + IE_NAME = u'nba' + + def report_extraction(self, video_id): + self._downloader.to_screen(u'[%s] %s: Extracting information' % (self.IE_NAME, video_id)) + + def _real_extract(self, url): + mobj = re.match(self._VALID_URL, url) + if mobj is None: + self._downloader.trouble(u'ERROR: invalid URL: %s' % url) + return + + video_id = mobj.group(1) + if video_id.endswith('/index.html'): + video_id = video_id[:-len('/index.html')] + + self.report_extraction(video_id) + try: + urlh = compat_urllib_request.urlopen(url) + webpage_bytes = urlh.read() + webpage = webpage_bytes.decode('utf-8', 'ignore') + except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err: + self._downloader.trouble(u'ERROR: unable to download video info XML: %s' % compat_str(err)) + return + + video_url = u'http://ht-mobile.cdn.turner.com/nba/big' + video_id + '_nba_1280x720.mp4' + def _findProp(rexp, default=None): + m = re.search(rexp, webpage) + if m: + return unescapeHTML(m.group(1)) + else: + return default + + shortened_video_id = video_id.rpartition('/')[2] + title = _findProp(r'Date: (.*?)'), + 'description': _findProp(r'
(.*?)'), + } + return [info] diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index d7e1a91ad..b6ee2e119 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -398,6 +398,7 @@ def gen_extractors(): XNXXIE(), GooglePlusIE(), ArteTvIE(), + NBAIE(), GenericIE() ] -- 2.22.2