ninenow.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. float_or_none,
  7. smuggle_url,
  8. str_or_none,
  9. try_get,
  10. unified_strdate,
  11. unified_timestamp,
  12. )
  13. class NineNowIE(InfoExtractor):
  14. IE_NAME = '9now.com.au'
  15. _VALID_URL = r'https?://(?:www\.)?9now\.com\.au/(?:[^/]+/){2}(?P<id>[^/?#]+)'
  16. _GEO_COUNTRIES = ['AU']
  17. _TESTS = [{
  18. # clip
  19. 'url': 'https://www.9now.com.au/afl-footy-show/2016/clip-ciql02091000g0hp5oktrnytc',
  20. 'md5': '17cf47d63ec9323e562c9957a968b565',
  21. 'info_dict': {
  22. 'id': '16801',
  23. 'ext': 'mp4',
  24. 'title': 'St. Kilda\'s Joey Montagna on the potential for a player\'s strike',
  25. 'description': 'Is a boycott of the NAB Cup "on the table"?',
  26. 'uploader_id': '4460760524001',
  27. 'upload_date': '20160713',
  28. 'timestamp': 1468421266,
  29. },
  30. 'skip': 'Only available in Australia',
  31. }, {
  32. # episode
  33. 'url': 'https://www.9now.com.au/afl-footy-show/2016/episode-19',
  34. 'only_matching': True,
  35. }, {
  36. # DRM protected
  37. 'url': 'https://www.9now.com.au/andrew-marrs-history-of-the-world/season-1/episode-1',
  38. 'only_matching': True,
  39. }, {
  40. # episode of series
  41. 'url': 'https://www.9now.com.au/lego-masters/season-3/episode-3',
  42. 'info_dict': {
  43. 'id': '6249614030001',
  44. 'title': 'Episode 3',
  45. 'ext': 'mp4',
  46. 'season_number': 3,
  47. 'episode_number': 3,
  48. 'description': 'In the first elimination of the competition, teams will have 10 hours to build a world inside a snow globe.',
  49. 'uploader_id': '4460760524001',
  50. 'timestamp': 1619002200,
  51. 'upload_date': '20210421',
  52. },
  53. 'expected_warnings': ['Ignoring subtitle tracks'],
  54. 'params':{
  55. 'skip_download': True,
  56. }
  57. }]
  58. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/4460760524001/default_default/index.html?videoId=%s'
  59. def _real_extract(self, url):
  60. display_id = self._match_id(url)
  61. webpage = self._download_webpage(url, display_id)
  62. page_data = self._parse_json(self._search_regex(
  63. r'window\.__data\s*=\s*({.*?});', webpage,
  64. 'page data', default='{}'), display_id, fatal=False)
  65. if not page_data:
  66. page_data = self._parse_json(self._parse_json(self._search_regex(
  67. r'window\.__data\s*=\s*JSON\.parse\s*\(\s*(".+?")\s*\)\s*;',
  68. webpage, 'page data'), display_id), display_id)
  69. for kind in ('episode', 'clip'):
  70. current_key = page_data.get(kind, {}).get(
  71. 'current%sKey' % kind.capitalize())
  72. if not current_key:
  73. continue
  74. cache = page_data.get(kind, {}).get('%sCache' % kind, {})
  75. if not cache:
  76. continue
  77. common_data = {
  78. 'episode': (cache.get(current_key) or list(cache.values())[0])[kind],
  79. 'season': (cache.get(current_key) or list(cache.values())[0]).get('season', None)
  80. }
  81. break
  82. else:
  83. raise ExtractorError('Unable to find video data')
  84. if not self.get_param('allow_unplayable_formats') and try_get(common_data, lambda x: x['episode']['video']['drm'], bool):
  85. self.report_drm(display_id)
  86. brightcove_id = try_get(
  87. common_data, lambda x: x['episode']['video']['brightcoveId'], compat_str) or 'ref:%s' % common_data['episode']['video']['referenceId']
  88. video_id = str_or_none(try_get(common_data, lambda x: x['episode']['video']['id'])) or brightcove_id
  89. title = try_get(common_data, lambda x: x['episode']['name'], compat_str)
  90. season_number = try_get(common_data, lambda x: x['season']['seasonNumber'], int)
  91. episode_number = try_get(common_data, lambda x: x['episode']['episodeNumber'], int)
  92. timestamp = unified_timestamp(try_get(common_data, lambda x: x['episode']['airDate'], compat_str))
  93. release_date = unified_strdate(try_get(common_data, lambda x: x['episode']['availability'], compat_str))
  94. thumbnails_data = try_get(common_data, lambda x: x['episode']['image']['sizes'], dict) or {}
  95. thumbnails = [{
  96. 'id': thumbnail_id,
  97. 'url': thumbnail_url,
  98. 'width': int_or_none(thumbnail_id[1:]),
  99. } for thumbnail_id, thumbnail_url in thumbnails_data.items()]
  100. return {
  101. '_type': 'url_transparent',
  102. 'url': smuggle_url(
  103. self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
  104. {'geo_countries': self._GEO_COUNTRIES}),
  105. 'id': video_id,
  106. 'title': title,
  107. 'description': try_get(common_data, lambda x: x['episode']['description'], compat_str),
  108. 'duration': float_or_none(try_get(common_data, lambda x: x['episode']['video']['duration'], float), 1000),
  109. 'thumbnails': thumbnails,
  110. 'ie_key': 'BrightcoveNew',
  111. 'season_number': season_number,
  112. 'episode_number': episode_number,
  113. 'timestamp': timestamp,
  114. 'release_date': release_date,
  115. }