ninecninemedia.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. float_or_none,
  4. int_or_none,
  5. parse_iso8601,
  6. str_or_none,
  7. try_get,
  8. )
  9. class NineCNineMediaIE(InfoExtractor):
  10. IE_NAME = '9c9media'
  11. _GEO_COUNTRIES = ['CA']
  12. _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
  13. _API_BASE_TEMPLATE = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/'
  14. def _real_extract(self, url):
  15. destination_code, content_id = self._match_valid_url(url).groups()
  16. api_base_url = self._API_BASE_TEMPLATE % (destination_code, content_id)
  17. content = self._download_json(api_base_url, content_id, query={
  18. '$include': '[Media.Name,Season,ContentPackages.Duration,ContentPackages.Id]',
  19. })
  20. title = content['Name']
  21. content_package = content['ContentPackages'][0]
  22. package_id = content_package['Id']
  23. content_package_url = api_base_url + f'contentpackages/{package_id}/'
  24. content_package = self._download_json(
  25. content_package_url, content_id, query={
  26. '$include': '[HasClosedCaptions]',
  27. })
  28. if (not self.get_param('allow_unplayable_formats')
  29. and try_get(content_package, lambda x: x['Constraints']['Security']['Type'])):
  30. self.report_drm(content_id)
  31. manifest_base_url = content_package_url + 'manifest.'
  32. formats = []
  33. formats.extend(self._extract_m3u8_formats(
  34. manifest_base_url + 'm3u8', content_id, 'mp4',
  35. 'm3u8_native', m3u8_id='hls', fatal=False))
  36. formats.extend(self._extract_f4m_formats(
  37. manifest_base_url + 'f4m', content_id,
  38. f4m_id='hds', fatal=False))
  39. formats.extend(self._extract_mpd_formats(
  40. manifest_base_url + 'mpd', content_id,
  41. mpd_id='dash', fatal=False))
  42. thumbnails = []
  43. for image in (content.get('Images') or []):
  44. image_url = image.get('Url')
  45. if not image_url:
  46. continue
  47. thumbnails.append({
  48. 'url': image_url,
  49. 'width': int_or_none(image.get('Width')),
  50. 'height': int_or_none(image.get('Height')),
  51. })
  52. tags, categories = [], []
  53. for source_name, container in (('Tags', tags), ('Genres', categories)):
  54. for e in content.get(source_name, []):
  55. e_name = e.get('Name')
  56. if not e_name:
  57. continue
  58. container.append(e_name)
  59. season = content.get('Season') or {}
  60. info = {
  61. 'id': content_id,
  62. 'title': title,
  63. 'description': content.get('Desc') or content.get('ShortDesc'),
  64. 'timestamp': parse_iso8601(content.get('BroadcastDateTime')),
  65. 'episode_number': int_or_none(content.get('Episode')),
  66. 'season': season.get('Name'),
  67. 'season_number': int_or_none(season.get('Number')),
  68. 'season_id': str_or_none(season.get('Id')),
  69. 'series': try_get(content, lambda x: x['Media']['Name']),
  70. 'tags': tags,
  71. 'categories': categories,
  72. 'duration': float_or_none(content_package.get('Duration')),
  73. 'formats': formats,
  74. 'thumbnails': thumbnails,
  75. }
  76. if content_package.get('HasClosedCaptions'):
  77. info['subtitles'] = {
  78. 'en': [{
  79. 'url': manifest_base_url + 'vtt',
  80. 'ext': 'vtt',
  81. }, {
  82. 'url': manifest_base_url + 'srt',
  83. 'ext': 'srt',
  84. }],
  85. }
  86. return info
  87. class CPTwentyFourIE(InfoExtractor):
  88. IE_NAME = 'cp24'
  89. _GEO_COUNTRIES = ['CA']
  90. _VALID_URL = r'https?://(?:www\.)?cp24\.com/news/(?P<id>[^?#]+)'
  91. _TESTS = [{
  92. 'url': 'https://www.cp24.com/news/video-shows-atm-being-ripped-out-of-business-by-pickup-truck-driver-in-mississauga-1.5676877',
  93. 'info_dict': {
  94. 'id': '2328005',
  95. 'ext': 'mp4',
  96. 'title': 'WATCH: Truck rips ATM from Mississauga business',
  97. 'description': 'md5:cf7498480885f080a754389a2b2f7073',
  98. 'timestamp': 1637618377,
  99. 'season': 'Season 0',
  100. 'season_number': 0,
  101. 'season_id': '57974',
  102. 'series': 'CTV News Toronto',
  103. 'duration': 26.86,
  104. 'thumbnail': 'http://images2.9c9media.com/image_asset/2014_11_5_2eb609a0-475b-0132-fbd6-34b52f6f1279_jpg_2000x1125.jpg',
  105. 'upload_date': '20211122',
  106. },
  107. 'params': {'skip_download': True, 'format': 'bv'},
  108. }]
  109. def _real_extract(self, url):
  110. display_id = self._match_id(url)
  111. webpage = self._download_webpage(url, display_id)
  112. video_id, destination = self._search_regex(
  113. r'getAuthStates\("(?P<id>[^"]+)",\s?"(?P<destination>[^"]+)"\);',
  114. webpage, 'video id and destination', group=('id', 'destination'))
  115. return self.url_result(f'9c9media:{destination}:{video_id}', NineCNineMediaIE, video_id)