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.

85 lines
3.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. int_or_none,
  7. float_or_none,
  8. ExtractorError,
  9. )
  10. class NineNowIE(InfoExtractor):
  11. IE_NAME = '9now.com.au'
  12. _VALID_URL = r'https?://(?:www\.)?9now\.com\.au/(?:[^/]+/){2}(?P<id>[^/?#]+)'
  13. _TESTS = [{
  14. # clip
  15. 'url': 'https://www.9now.com.au/afl-footy-show/2016/clip-ciql02091000g0hp5oktrnytc',
  16. 'md5': '17cf47d63ec9323e562c9957a968b565',
  17. 'info_dict': {
  18. 'id': '16801',
  19. 'ext': 'mp4',
  20. 'title': 'St. Kilda\'s Joey Montagna on the potential for a player\'s strike',
  21. 'description': 'Is a boycott of the NAB Cup "on the table"?',
  22. 'uploader_id': '4460760524001',
  23. 'upload_date': '20160713',
  24. 'timestamp': 1468421266,
  25. },
  26. 'skip': 'Only available in Australia',
  27. }, {
  28. # episode
  29. 'url': 'https://www.9now.com.au/afl-footy-show/2016/episode-19',
  30. 'only_matching': True,
  31. }, {
  32. # DRM protected
  33. 'url': 'https://www.9now.com.au/andrew-marrs-history-of-the-world/season-1/episode-1',
  34. 'only_matching': True,
  35. }]
  36. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/4460760524001/default_default/index.html?videoId=%s'
  37. def _real_extract(self, url):
  38. display_id = self._match_id(url)
  39. webpage = self._download_webpage(url, display_id)
  40. page_data = self._parse_json(self._search_regex(
  41. r'window\.__data\s*=\s*({.*?});', webpage,
  42. 'page data'), display_id)
  43. for kind in ('episode', 'clip'):
  44. current_key = page_data.get(kind, {}).get(
  45. 'current%sKey' % kind.capitalize())
  46. if not current_key:
  47. continue
  48. cache = page_data.get(kind, {}).get('%sCache' % kind, {})
  49. if not cache:
  50. continue
  51. common_data = (cache.get(current_key) or list(cache.values())[0])[kind]
  52. break
  53. else:
  54. raise ExtractorError('Unable to find video data')
  55. video_data = common_data['video']
  56. if video_data.get('drm'):
  57. raise ExtractorError('This video is DRM protected.', expected=True)
  58. brightcove_id = video_data.get('brightcoveId') or 'ref:' + video_data['referenceId']
  59. video_id = compat_str(video_data.get('id') or brightcove_id)
  60. title = common_data['name']
  61. thumbnails = [{
  62. 'id': thumbnail_id,
  63. 'url': thumbnail_url,
  64. 'width': int_or_none(thumbnail_id[1:])
  65. } for thumbnail_id, thumbnail_url in common_data.get('image', {}).get('sizes', {}).items()]
  66. return {
  67. '_type': 'url_transparent',
  68. 'url': self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
  69. 'id': video_id,
  70. 'title': title,
  71. 'description': common_data.get('description'),
  72. 'duration': float_or_none(video_data.get('duration'), 1000),
  73. 'thumbnails': thumbnails,
  74. 'ie_key': 'BrightcoveNew',
  75. }