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.

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