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.

72 lines
2.7 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. common_data = page_data.get('episode', {}).get('episode') or page_data.get('clip', {}).get('clip')
  44. video_data = common_data['video']
  45. if video_data.get('drm'):
  46. raise ExtractorError('This video is DRM protected.', expected=True)
  47. brightcove_id = video_data.get('brightcoveId') or 'ref:' + video_data['referenceId']
  48. video_id = compat_str(video_data.get('id') or brightcove_id)
  49. title = common_data['name']
  50. thumbnails = [{
  51. 'id': thumbnail_id,
  52. 'url': thumbnail_url,
  53. 'width': int_or_none(thumbnail_id[1:])
  54. } for thumbnail_id, thumbnail_url in common_data.get('image', {}).get('sizes', {}).items()]
  55. return {
  56. '_type': 'url_transparent',
  57. 'url': self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
  58. 'id': video_id,
  59. 'title': title,
  60. 'description': common_data.get('description'),
  61. 'duration': float_or_none(video_data.get('duration'), 1000),
  62. 'thumbnails': thumbnails,
  63. 'ie_key': 'BrightcoveNew',
  64. }