logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

ctvnews.py (7438B)


  1. import json
  2. import re
  3. import urllib.parse
  4. from .common import InfoExtractor
  5. from .ninecninemedia import NineCNineMediaIE
  6. from ..utils import extract_attributes, orderedSet
  7. from ..utils.traversal import find_element, traverse_obj
  8. class CTVNewsIE(InfoExtractor):
  9. _BASE_REGEX = r'https?://(?:[^.]+\.)?ctvnews\.ca/'
  10. _VIDEO_ID_RE = r'(?P<id>\d{5,})'
  11. _PLAYLIST_ID_RE = r'(?P<id>\d\.\d{5,})'
  12. _VALID_URL = [
  13. rf'{_BASE_REGEX}video/c{_VIDEO_ID_RE}',
  14. rf'{_BASE_REGEX}video(?:-gallery)?/?\?clipId={_VIDEO_ID_RE}',
  15. rf'{_BASE_REGEX}video/?\?(?:playlist|bin)Id={_PLAYLIST_ID_RE}',
  16. rf'{_BASE_REGEX}(?!video/)[^?#]*?{_PLAYLIST_ID_RE}/?(?:$|[?#])',
  17. rf'{_BASE_REGEX}(?!video/)[^?#]+\?binId={_PLAYLIST_ID_RE}',
  18. ]
  19. _TESTS = [{
  20. 'url': 'http://www.ctvnews.ca/video?clipId=901995',
  21. 'md5': 'b608f466c7fa24b9666c6439d766ab7e',
  22. 'info_dict': {
  23. 'id': '901995',
  24. 'ext': 'flv',
  25. 'title': 'Extended: \'That person cannot be me\' Johnson says',
  26. 'description': 'md5:958dd3b4f5bbbf0ed4d045c790d89285',
  27. 'timestamp': 1467286284,
  28. 'upload_date': '20160630',
  29. 'categories': [],
  30. 'season_number': 0,
  31. 'season': 'Season 0',
  32. 'tags': [],
  33. 'series': 'CTV News National | Archive | Stories 2',
  34. 'season_id': '57981',
  35. 'thumbnail': r're:https?://.*\.jpg$',
  36. 'duration': 764.631,
  37. },
  38. }, {
  39. 'url': 'https://barrie.ctvnews.ca/video/c3030933-here_s-what_s-making-news-for-nov--15?binId=1272429',
  40. 'md5': '8b8c2b33c5c1803e3c26bc74ff8694d5',
  41. 'info_dict': {
  42. 'id': '3030933',
  43. 'ext': 'flv',
  44. 'title': 'Here’s what’s making news for Nov. 15',
  45. 'description': 'Here are the top stories we’re working on for CTV News at 11 for Nov. 15',
  46. 'thumbnail': 'http://images2.9c9media.com/image_asset/2021_2_22_a602e68e-1514-410e-a67a-e1f7cccbacab_png_2000x1125.jpg',
  47. 'season_id': '58104',
  48. 'season_number': 0,
  49. 'tags': [],
  50. 'season': 'Season 0',
  51. 'categories': [],
  52. 'series': 'CTV News Barrie',
  53. 'upload_date': '20241116',
  54. 'duration': 42.943,
  55. 'timestamp': 1731722452,
  56. },
  57. }, {
  58. 'url': 'http://www.ctvnews.ca/video?playlistId=1.2966224',
  59. 'info_dict':
  60. {
  61. 'id': '1.2966224',
  62. },
  63. 'playlist_mincount': 19,
  64. }, {
  65. 'url': 'http://www.ctvnews.ca/video?binId=1.2876780',
  66. 'info_dict':
  67. {
  68. 'id': '1.2876780',
  69. },
  70. 'playlist_mincount': 100,
  71. }, {
  72. 'url': 'https://www.ctvnews.ca/it-s-been-23-years-since-toronto-called-in-the-army-after-a-major-snowstorm-1.5736957',
  73. 'info_dict':
  74. {
  75. 'id': '1.5736957',
  76. },
  77. 'playlist_mincount': 6,
  78. }, {
  79. 'url': 'https://www.ctvnews.ca/business/respondents-to-bank-of-canada-questionnaire-largely-oppose-creating-a-digital-loonie-1.6665797',
  80. 'md5': '24bc4b88cdc17d8c3fc01dfc228ab72c',
  81. 'info_dict': {
  82. 'id': '2695026',
  83. 'ext': 'flv',
  84. 'season_id': '89852',
  85. 'series': 'From CTV News Channel',
  86. 'description': 'md5:796a985a23cacc7e1e2fafefd94afd0a',
  87. 'season': '2023',
  88. 'title': 'Bank of Canada asks public about digital currency',
  89. 'categories': [],
  90. 'tags': [],
  91. 'upload_date': '20230526',
  92. 'season_number': 2023,
  93. 'thumbnail': 'http://images2.9c9media.com/image_asset/2019_3_28_35f5afc3-10f6-4d92-b194-8b9a86f55c6a_png_1920x1080.jpg',
  94. 'timestamp': 1685105157,
  95. 'duration': 253.553,
  96. },
  97. }, {
  98. 'url': 'https://stox.ctvnews.ca/video-gallery?clipId=582589',
  99. 'md5': '135cc592df607d29dddc931f1b756ae2',
  100. 'info_dict': {
  101. 'id': '582589',
  102. 'ext': 'flv',
  103. 'categories': [],
  104. 'timestamp': 1427906183,
  105. 'season_number': 0,
  106. 'duration': 125.559,
  107. 'thumbnail': 'http://images2.9c9media.com/image_asset/2019_3_28_35f5afc3-10f6-4d92-b194-8b9a86f55c6a_png_1920x1080.jpg',
  108. 'series': 'CTV News Stox',
  109. 'description': 'CTV original footage of the rise and fall of the Berlin Wall.',
  110. 'title': 'Berlin Wall',
  111. 'season_id': '63817',
  112. 'season': 'Season 0',
  113. 'tags': [],
  114. 'upload_date': '20150401',
  115. },
  116. }, {
  117. 'url': 'https://ottawa.ctvnews.ca/features/regional-contact/regional-contact-archive?binId=1.1164587#3023759',
  118. 'md5': 'a14c0603557decc6531260791c23cc5e',
  119. 'info_dict': {
  120. 'id': '3023759',
  121. 'ext': 'flv',
  122. 'season_number': 2024,
  123. 'timestamp': 1731798000,
  124. 'season': '2024',
  125. 'episode': 'Episode 125',
  126. 'description': 'CTV News Ottawa at Six',
  127. 'duration': 2712.076,
  128. 'episode_number': 125,
  129. 'upload_date': '20241116',
  130. 'title': 'CTV News Ottawa at Six for Saturday, November 16, 2024',
  131. 'thumbnail': 'http://images2.9c9media.com/image_asset/2019_3_28_35f5afc3-10f6-4d92-b194-8b9a86f55c6a_png_1920x1080.jpg',
  132. 'categories': [],
  133. 'tags': [],
  134. 'series': 'CTV News Ottawa at Six',
  135. 'season_id': '92667',
  136. },
  137. }, {
  138. 'url': 'http://www.ctvnews.ca/1.810401',
  139. 'only_matching': True,
  140. }, {
  141. 'url': 'http://www.ctvnews.ca/canadiens-send-p-k-subban-to-nashville-in-blockbuster-trade-1.2967231',
  142. 'only_matching': True,
  143. }, {
  144. 'url': 'http://vancouverisland.ctvnews.ca/video?clipId=761241',
  145. 'only_matching': True,
  146. }]
  147. def _ninecninemedia_url_result(self, clip_id):
  148. return self.url_result(f'9c9media:ctvnews_web:{clip_id}', NineCNineMediaIE, clip_id)
  149. def _real_extract(self, url):
  150. page_id = self._match_id(url)
  151. if mobj := re.fullmatch(self._VIDEO_ID_RE, urllib.parse.urlparse(url).fragment):
  152. page_id = mobj.group('id')
  153. if re.fullmatch(self._VIDEO_ID_RE, page_id):
  154. return self._ninecninemedia_url_result(page_id)
  155. webpage = self._download_webpage(f'https://www.ctvnews.ca/{page_id}', page_id, query={
  156. 'ot': 'example.AjaxPageLayout.ot',
  157. 'maxItemsPerPage': 1000000,
  158. })
  159. entries = [self._ninecninemedia_url_result(clip_id)
  160. for clip_id in orderedSet(re.findall(r'clip\.id\s*=\s*(\d+);', webpage))]
  161. if not entries:
  162. webpage = self._download_webpage(url, page_id)
  163. if 'getAuthStates("' in webpage:
  164. entries = [self._ninecninemedia_url_result(clip_id) for clip_id in
  165. self._search_regex(r'getAuthStates\("([\d+,]+)"', webpage, 'clip ids').split(',')]
  166. else:
  167. entries = [
  168. self._ninecninemedia_url_result(clip_id) for clip_id in
  169. traverse_obj(webpage, (
  170. {find_element(tag='jasper-player-container', html=True)},
  171. {extract_attributes}, 'axis-ids', {json.loads}, ..., 'axisId', {str}))
  172. ]
  173. return self.playlist_result(entries, page_id)