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.

63 lines
2.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. remove_end,
  5. parse_duration,
  6. )
  7. class NBAIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:watch\.|www\.)?nba\.com/(?:nba/)?video(?P<id>/[^?]*?)/?(?:/index\.html)?(?:\?.*)?$'
  9. _TESTS = [{
  10. 'url': 'http://www.nba.com/video/games/nets/2012/12/04/0021200253-okc-bkn-recap.nba/index.html',
  11. 'md5': 'c0edcfc37607344e2ff8f13c378c88a4',
  12. 'info_dict': {
  13. 'id': '0021200253-okc-bkn-recap.nba',
  14. 'ext': 'mp4',
  15. 'title': 'Thunder vs. Nets',
  16. 'description': 'Kevin Durant scores 32 points and dishes out six assists as the Thunder beat the Nets in Brooklyn.',
  17. 'duration': 181,
  18. },
  19. }, {
  20. 'url': 'http://www.nba.com/video/games/hornets/2014/12/05/0021400276-nyk-cha-play5.nba/',
  21. 'only_matching': True,
  22. }, {
  23. 'url': 'http://watch.nba.com/nba/video/channels/playoffs/2015/05/20/0041400301-cle-atl-recap.nba',
  24. 'info_dict': {
  25. 'id': '0041400301-cle-atl-recap.nba',
  26. 'ext': 'mp4',
  27. 'title': 'NBA GAME TIME | Video: Hawks vs. Cavaliers Game 1',
  28. 'description': 'md5:8094c3498d35a9bd6b1a8c396a071b4d',
  29. 'duration': 228,
  30. },
  31. 'params': {
  32. 'skip_download': True,
  33. }
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. webpage = self._download_webpage(url, video_id)
  38. video_url = 'http://ht-mobile.cdn.turner.com/nba/big' + video_id + '_nba_1280x720.mp4'
  39. shortened_video_id = video_id.rpartition('/')[2]
  40. title = remove_end(
  41. self._og_search_title(webpage, default=shortened_video_id), ' : NBA.com')
  42. description = self._og_search_description(webpage)
  43. duration_str = self._html_search_meta(
  44. 'duration', webpage, 'duration', default=None)
  45. if not duration_str:
  46. duration_str = self._html_search_regex(
  47. r'Duration:</b>\s*(\d+:\d+)', webpage, 'duration', fatal=False)
  48. duration = parse_duration(duration_str)
  49. return {
  50. 'id': shortened_video_id,
  51. 'url': video_url,
  52. 'title': title,
  53. 'description': description,
  54. 'duration': duration,
  55. }