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