logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

ninenow.py (3541B)


  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', default='{}'), display_id, fatal=False)
  45. if not page_data:
  46. page_data = self._parse_json(self._parse_json(self._search_regex(
  47. r'window\.__data\s*=\s*JSON\.parse\s*\(\s*(".+?")\s*\)\s*;',
  48. webpage, 'page data'), display_id), display_id)
  49. for kind in ('episode', 'clip'):
  50. current_key = page_data.get(kind, {}).get(
  51. 'current%sKey' % kind.capitalize())
  52. if not current_key:
  53. continue
  54. cache = page_data.get(kind, {}).get('%sCache' % kind, {})
  55. if not cache:
  56. continue
  57. common_data = (cache.get(current_key) or list(cache.values())[0])[kind]
  58. break
  59. else:
  60. raise ExtractorError('Unable to find video data')
  61. video_data = common_data['video']
  62. if video_data.get('drm'):
  63. raise ExtractorError('This video is DRM protected.', expected=True)
  64. brightcove_id = video_data.get('brightcoveId') or 'ref:' + video_data['referenceId']
  65. video_id = compat_str(video_data.get('id') or brightcove_id)
  66. title = common_data['name']
  67. thumbnails = [{
  68. 'id': thumbnail_id,
  69. 'url': thumbnail_url,
  70. 'width': int_or_none(thumbnail_id[1:])
  71. } for thumbnail_id, thumbnail_url in common_data.get('image', {}).get('sizes', {}).items()]
  72. return {
  73. '_type': 'url_transparent',
  74. 'url': smuggle_url(
  75. self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
  76. {'geo_countries': self._GEO_COUNTRIES}),
  77. 'id': video_id,
  78. 'title': title,
  79. 'description': common_data.get('description'),
  80. 'duration': float_or_none(video_data.get('duration'), 1000),
  81. 'thumbnails': thumbnails,
  82. 'ie_key': 'BrightcoveNew',
  83. }