You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

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