cbs.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. from .brightcove import BrightcoveNewIE
  2. from .common import InfoExtractor
  3. from .theplatform import ThePlatformFeedIE
  4. from .youtube import YoutubeIE
  5. from ..utils import (
  6. ExtractorError,
  7. extract_attributes,
  8. find_xpath_attr,
  9. get_element_html_by_id,
  10. int_or_none,
  11. smuggle_url,
  12. update_url_query,
  13. url_or_none,
  14. xpath_element,
  15. xpath_text,
  16. )
  17. class CBSBaseIE(ThePlatformFeedIE): # XXX: Do not subclass from concrete IE
  18. def _parse_smil_subtitles(self, smil, namespace=None, subtitles_lang='en'):
  19. subtitles = {}
  20. for k, ext in [('sMPTE-TTCCURL', 'tt'), ('ClosedCaptionURL', 'ttml'), ('webVTTCaptionURL', 'vtt')]:
  21. cc_e = find_xpath_attr(smil, self._xpath_ns('.//param', namespace), 'name', k)
  22. if cc_e is not None:
  23. cc_url = cc_e.get('value')
  24. if cc_url:
  25. subtitles.setdefault(subtitles_lang, []).append({
  26. 'ext': ext,
  27. 'url': cc_url,
  28. })
  29. return subtitles
  30. def _extract_common_video_info(self, content_id, asset_types, mpx_acc, extra_info):
  31. tp_path = f'dJ5BDC/media/guid/{mpx_acc}/{content_id}'
  32. tp_release_url = f'https://link.theplatform.com/s/{tp_path}'
  33. info = self._extract_theplatform_metadata(tp_path, content_id)
  34. formats, subtitles = [], {}
  35. last_e = None
  36. for asset_type, query in asset_types.items():
  37. try:
  38. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  39. update_url_query(tp_release_url, query), content_id,
  40. f'Downloading {asset_type} SMIL data')
  41. except ExtractorError as e:
  42. last_e = e
  43. if asset_type != 'fallback':
  44. continue
  45. query['formats'] = '' # blank query to check if expired
  46. try:
  47. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  48. update_url_query(tp_release_url, query), content_id,
  49. f'Downloading {asset_type} SMIL data, trying again with another format')
  50. except ExtractorError as e:
  51. last_e = e
  52. continue
  53. formats.extend(tp_formats)
  54. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  55. if last_e and not formats:
  56. self.raise_no_formats(last_e, True, content_id)
  57. extra_info.update({
  58. 'id': content_id,
  59. 'formats': formats,
  60. 'subtitles': subtitles,
  61. })
  62. info.update({k: v for k, v in extra_info.items() if v is not None})
  63. return info
  64. def _extract_video_info(self, *args, **kwargs):
  65. # Extract assets + metadata and call _extract_common_video_info
  66. raise NotImplementedError('This method must be implemented by subclasses')
  67. def _real_extract(self, url):
  68. return self._extract_video_info(self._match_id(url))
  69. class CBSIE(CBSBaseIE):
  70. _WORKING = False
  71. _VALID_URL = r'''(?x)
  72. (?:
  73. cbs:|
  74. https?://(?:www\.)?(?:
  75. cbs\.com/(?:shows|movies)/(?:video|[^/]+/video|[^/]+)/|
  76. colbertlateshow\.com/(?:video|podcasts)/)
  77. )(?P<id>[\w-]+)'''
  78. # All tests are blocked outside US
  79. _TESTS = [{
  80. 'url': 'https://www.cbs.com/shows/video/xrUyNLtl9wd8D_RWWAg9NU2F_V6QpB3R/',
  81. 'info_dict': {
  82. 'id': 'xrUyNLtl9wd8D_RWWAg9NU2F_V6QpB3R',
  83. 'ext': 'mp4',
  84. 'title': 'Tough As Nails - Dreams Never Die',
  85. 'description': 'md5:a3535a62531cdd52b0364248a2c1ae33',
  86. 'duration': 2588,
  87. 'timestamp': 1639015200,
  88. 'upload_date': '20211209',
  89. 'uploader': 'CBSI-NEW',
  90. },
  91. 'params': {
  92. # m3u8 download
  93. 'skip_download': True,
  94. },
  95. 'skip': 'Subscription required',
  96. }, {
  97. 'url': 'https://www.cbs.com/shows/video/sZH1MGgomIosZgxGJ1l263MFq16oMtW1/',
  98. 'info_dict': {
  99. 'id': 'sZH1MGgomIosZgxGJ1l263MFq16oMtW1',
  100. 'title': 'The Late Show - 3/16/22 (Michael Buble, Rose Matafeo)',
  101. 'timestamp': 1647488100,
  102. 'description': 'md5:d0e6ec23c544b7fa8e39a8e6844d2439',
  103. 'uploader': 'CBSI-NEW',
  104. 'upload_date': '20220317',
  105. },
  106. 'params': {
  107. 'ignore_no_formats_error': True,
  108. 'skip_download': True,
  109. },
  110. 'expected_warnings': [
  111. 'This content expired on', 'No video formats found', 'Requested format is not available'],
  112. 'skip': '404 Not Found',
  113. }, {
  114. 'url': 'http://colbertlateshow.com/video/8GmB0oY0McANFvp2aEffk9jZZZ2YyXxy/the-colbeard/',
  115. 'only_matching': True,
  116. }, {
  117. 'url': 'http://www.colbertlateshow.com/podcasts/dYSwjqPs_X1tvbV_P2FcPWRa_qT6akTC/in-the-bad-room-with-stephen/',
  118. 'only_matching': True,
  119. }]
  120. def _extract_video_info(self, content_id, site='cbs', mpx_acc=2198311517):
  121. items_data = self._download_xml(
  122. 'https://can.cbs.com/thunder/player/videoPlayerService.php',
  123. content_id, query={'partner': site, 'contentId': content_id})
  124. video_data = xpath_element(items_data, './/item')
  125. title = xpath_text(video_data, 'videoTitle', 'title') or xpath_text(video_data, 'videotitle', 'title')
  126. asset_types = {}
  127. has_drm = False
  128. for item in items_data.findall('.//item'):
  129. asset_type = xpath_text(item, 'assetType')
  130. query = {
  131. 'mbr': 'true',
  132. 'assetTypes': asset_type,
  133. }
  134. if not asset_type:
  135. # fallback for content_ids that videoPlayerService doesn't return anything for
  136. asset_type = 'fallback'
  137. query['formats'] = 'M3U+none,MPEG4,M3U+appleHlsEncryption,MP3'
  138. del query['assetTypes']
  139. if asset_type in asset_types:
  140. continue
  141. elif any(excluded in asset_type for excluded in ('HLS_FPS', 'DASH_CENC', 'OnceURL')):
  142. if 'DASH_CENC' in asset_type:
  143. has_drm = True
  144. continue
  145. if asset_type.startswith('HLS') or 'StreamPack' in asset_type:
  146. query['formats'] = 'MPEG4,M3U'
  147. elif asset_type in ('RTMP', 'WIFI', '3G'):
  148. query['formats'] = 'MPEG4,FLV'
  149. asset_types[asset_type] = query
  150. if not asset_types and has_drm:
  151. self.report_drm(content_id)
  152. return self._extract_common_video_info(content_id, asset_types, mpx_acc, extra_info={
  153. 'title': title,
  154. 'series': xpath_text(video_data, 'seriesTitle'),
  155. 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
  156. 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),
  157. 'duration': int_or_none(xpath_text(video_data, 'videoLength'), 1000),
  158. 'thumbnail': url_or_none(xpath_text(video_data, 'previewImageURL')),
  159. })
  160. class ParamountPressExpressIE(InfoExtractor):
  161. _VALID_URL = r'https?://(?:www\.)?paramountpressexpress\.com(?:/[\w-]+)+/(?P<yt>yt-)?video/?\?watch=(?P<id>[\w-]+)'
  162. _TESTS = [{
  163. 'url': 'https://www.paramountpressexpress.com/cbs-entertainment/shows/survivor/video/?watch=pnzew7e2hx',
  164. 'md5': '56631dbcadaab980d1fc47cb7b76cba4',
  165. 'info_dict': {
  166. 'id': '6322981580112',
  167. 'ext': 'mp4',
  168. 'title': 'I’m Felicia',
  169. 'description': 'md5:88fad93f8eede1c9c8f390239e4c6290',
  170. 'uploader_id': '6055873637001',
  171. 'upload_date': '20230320',
  172. 'timestamp': 1679334960,
  173. 'duration': 49.557,
  174. 'thumbnail': r're:^https://.+\.jpg',
  175. 'tags': [],
  176. },
  177. }, {
  178. 'url': 'https://www.paramountpressexpress.com/cbs-entertainment/video/?watch=2s5eh8kppc',
  179. 'md5': 'edcb03e3210b88a3e56c05aa863e0e5b',
  180. 'info_dict': {
  181. 'id': '6323036027112',
  182. 'ext': 'mp4',
  183. 'title': '‘Y&R’ Set Visit: Jerry O’Connell Quizzes Cast on Pre-Love Scene Rituals and More',
  184. 'description': 'md5:b929867a357aac5544b783d834c78383',
  185. 'uploader_id': '6055873637001',
  186. 'upload_date': '20230321',
  187. 'timestamp': 1679430180,
  188. 'duration': 132.032,
  189. 'thumbnail': r're:^https://.+\.jpg',
  190. 'tags': [],
  191. },
  192. }, {
  193. 'url': 'https://www.paramountpressexpress.com/paramount-plus/yt-video/?watch=OX9wJWOcqck',
  194. 'info_dict': {
  195. 'id': 'OX9wJWOcqck',
  196. 'ext': 'mp4',
  197. 'title': 'Rugrats | Season 2 Official Trailer | Paramount+',
  198. 'description': 'md5:1f7e26f5625a9f0d6564d9ad97a9f7de',
  199. 'uploader': 'Paramount Plus',
  200. 'uploader_id': '@paramountplus',
  201. 'uploader_url': 'http://www.youtube.com/@paramountplus',
  202. 'channel': 'Paramount Plus',
  203. 'channel_id': 'UCrRttZIypNTA1Mrfwo745Sg',
  204. 'channel_url': 'https://www.youtube.com/channel/UCrRttZIypNTA1Mrfwo745Sg',
  205. 'upload_date': '20230316',
  206. 'duration': 88,
  207. 'age_limit': 0,
  208. 'availability': 'public',
  209. 'live_status': 'not_live',
  210. 'playable_in_embed': True,
  211. 'view_count': int,
  212. 'like_count': int,
  213. 'channel_follower_count': int,
  214. 'thumbnail': 'https://i.ytimg.com/vi/OX9wJWOcqck/maxresdefault.jpg',
  215. 'categories': ['Entertainment'],
  216. 'tags': ['Rugrats'],
  217. },
  218. }, {
  219. 'url': 'https://www.paramountpressexpress.com/showtime/yt-video/?watch=_ljssSoDLkw',
  220. 'info_dict': {
  221. 'id': '_ljssSoDLkw',
  222. 'ext': 'mp4',
  223. 'title': 'Lavell Crawford: THEE Lavell Crawford Comedy Special Official Trailer | SHOWTIME',
  224. 'description': 'md5:39581bcc3fd810209b642609f448af70',
  225. 'uploader': 'SHOWTIME',
  226. 'uploader_id': '@Showtime',
  227. 'uploader_url': 'http://www.youtube.com/@Showtime',
  228. 'channel': 'SHOWTIME',
  229. 'channel_id': 'UCtwMWJr2BFPkuJTnSvCESSQ',
  230. 'channel_url': 'https://www.youtube.com/channel/UCtwMWJr2BFPkuJTnSvCESSQ',
  231. 'upload_date': '20230209',
  232. 'duration': 49,
  233. 'age_limit': 0,
  234. 'availability': 'public',
  235. 'live_status': 'not_live',
  236. 'playable_in_embed': True,
  237. 'view_count': int,
  238. 'like_count': int,
  239. 'comment_count': int,
  240. 'channel_follower_count': int,
  241. 'thumbnail': 'https://i.ytimg.com/vi_webp/_ljssSoDLkw/maxresdefault.webp',
  242. 'categories': ['People & Blogs'],
  243. 'tags': 'count:27',
  244. },
  245. }]
  246. def _real_extract(self, url):
  247. display_id, is_youtube = self._match_valid_url(url).group('id', 'yt')
  248. if is_youtube:
  249. return self.url_result(display_id, YoutubeIE)
  250. webpage = self._download_webpage(url, display_id)
  251. video_id = self._search_regex(
  252. r'\bvideo_id\s*=\s*["\'](\d+)["\']\s*,', webpage, 'Brightcove ID')
  253. token = self._search_regex(r'\btoken\s*=\s*["\']([\w.-]+)["\']', webpage, 'token')
  254. player = extract_attributes(get_element_html_by_id('vcbrightcoveplayer', webpage) or '')
  255. account_id = player.get('data-account') or '6055873637001'
  256. player_id = player.get('data-player') or 'OtLKgXlO9F'
  257. embed = player.get('data-embed') or 'default'
  258. return self.url_result(smuggle_url(
  259. f'https://players.brightcove.net/{account_id}/{player_id}_{embed}/index.html?videoId={video_id}',
  260. {'token': token}), BrightcoveNewIE)