ninenow.py 5.1 KB

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