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.

49 lines
1.8 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. _TEST = {
  9. u'url': u'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html',
  10. u'file': u'0021200253-okc-bkn-recap.nba.mp4',
  11. u'md5': u'c0edcfc37607344e2ff8f13c378c88a4',
  12. u'info_dict': {
  13. u"description": u"Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.",
  14. u"title": u"Thunder vs. Nets"
  15. }
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. if mobj is None:
  20. raise ExtractorError(u'Invalid URL: %s' % url)
  21. video_id = mobj.group(1)
  22. webpage = self._download_webpage(url, video_id)
  23. video_url = u'http://ht-mobile.cdn.turner.com/nba/big' + video_id + '_nba_1280x720.mp4'
  24. shortened_video_id = video_id.rpartition('/')[2]
  25. title = self._html_search_regex(r'<meta property="og:title" content="(.*?)"',
  26. webpage, 'title', default=shortened_video_id).replace('NBA.com: ', '')
  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. description = self._html_search_regex(r'<meta name="description" (?:content|value)="(.*?)" />', webpage, 'description', fatal=False)
  30. info = {
  31. 'id': shortened_video_id,
  32. 'url': video_url,
  33. 'ext': 'mp4',
  34. 'title': title,
  35. # 'uploader_date': uploader_date,
  36. 'description': description,
  37. }
  38. return [info]