]>
Commit | Line | Data |
---|---|---|
e42a692f PH |
1 | from __future__ import unicode_literals |
2 | ||
43518503 | 3 | from .theplatform import ThePlatformFeedIE |
5c2266df | 4 | from ..utils import ( |
21dedcb5 | 5 | ExtractorError, |
63c55e9f | 6 | int_or_none, |
63c55e9f | 7 | find_xpath_attr, |
45cae3b0 RA |
8 | xpath_element, |
9 | xpath_text, | |
10 | update_url_query, | |
6e6e0d95 | 11 | url_or_none, |
5c2266df | 12 | ) |
fa3ae234 PH |
13 | |
14 | ||
43518503 | 15 | class CBSBaseIE(ThePlatformFeedIE): |
3e0c3d14 | 16 | def _parse_smil_subtitles(self, smil, namespace=None, subtitles_lang='en'): |
180a9dff RA |
17 | subtitles = {} |
18 | for k, ext in [('sMPTE-TTCCURL', 'tt'), ('ClosedCaptionURL', 'ttml'), ('webVTTCaptionURL', 'vtt')]: | |
19 | cc_e = find_xpath_attr(smil, self._xpath_ns('.//param', namespace), 'name', k) | |
20 | if cc_e is not None: | |
21 | cc_url = cc_e.get('value') | |
22 | if cc_url: | |
23 | subtitles.setdefault(subtitles_lang, []).append({ | |
24 | 'ext': ext, | |
25 | 'url': cc_url, | |
26 | }) | |
27 | return subtitles | |
3e0c3d14 | 28 | |
6e6e0d95 | 29 | def _extract_common_video_info(self, content_id, asset_types, mpx_acc, extra_info): |
30 | tp_path = 'dJ5BDC/media/guid/%d/%s' % (mpx_acc, content_id) | |
31 | tp_release_url = f'https://link.theplatform.com/s/{tp_path}' | |
32 | info = self._extract_theplatform_metadata(tp_path, content_id) | |
33 | ||
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 | 'Downloading %s SMIL data' % asset_type) | |
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 | 'Downloading %s SMIL data, trying again with another format' % asset_type) | |
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 | self._sort_formats(formats) | |
58 | ||
59 | extra_info.update({ | |
60 | 'id': content_id, | |
61 | 'formats': formats, | |
62 | 'subtitles': subtitles, | |
63 | }) | |
64 | info.update({k: v for k, v in extra_info.items() if v is not None}) | |
65 | return info | |
66 | ||
67 | def _extract_video_info(self, *args, **kwargs): | |
68 | # Extract assets + metadata and call _extract_common_video_info | |
69 | raise NotImplementedError('This method must be implemented by subclasses') | |
70 | ||
71 | def _real_extract(self, url): | |
72 | return self._extract_video_info(self._match_id(url)) | |
73 | ||
3e0c3d14 | 74 | |
75 | class CBSIE(CBSBaseIE): | |
c755f190 | 76 | _VALID_URL = r'''(?x) |
77 | (?: | |
78 | cbs:| | |
79 | https?://(?:www\.)?(?: | |
6e6e0d95 | 80 | cbs\.com/(?:shows/[^/]+/video|movies/[^/]+)/| |
c755f190 | 81 | colbertlateshow\.com/(?:video|podcasts)/) |
82 | )(?P<id>[\w-]+)''' | |
fa3ae234 | 83 | |
6e6e0d95 | 84 | # All tests are blocked outside US |
2871d489 | 85 | _TESTS = [{ |
2c736b4f | 86 | 'url': 'https://www.cbs.com/shows/garth-brooks/video/_u7W953k6la293J7EPTd9oHkSPs6Xn6_/connect-chat-feat-garth-brooks/', |
e42a692f | 87 | 'info_dict': { |
63c55e9f | 88 | 'id': '_u7W953k6la293J7EPTd9oHkSPs6Xn6_', |
63c55e9f | 89 | 'ext': 'mp4', |
e42a692f PH |
90 | 'title': 'Connect Chat feat. Garth Brooks', |
91 | 'description': 'Connect with country music singer Garth Brooks, as he chats with fans on Wednesday November 27, 2013. Be sure to tune in to Garth Brooks: Live from Las Vegas, Friday November 29, at 9/8c on CBS!', | |
92 | 'duration': 1495, | |
79ba9140 | 93 | 'timestamp': 1385585425, |
94 | 'upload_date': '20131127', | |
95 | 'uploader': 'CBSI-NEW', | |
fa3ae234 | 96 | }, |
dabe1570 RA |
97 | 'params': { |
98 | # m3u8 download | |
99 | 'skip_download': True, | |
100 | }, | |
68f5867c L |
101 | }, { |
102 | 'url': 'https://www.cbs.com/shows/the-late-show-with-stephen-colbert/video/60icOhMb9NcjbcWnF_gub9XXHdeBcNk2/the-late-show-6-23-21-christine-baranski-joy-oladokun-', | |
103 | 'info_dict': { | |
104 | 'id': '60icOhMb9NcjbcWnF_gub9XXHdeBcNk2', | |
105 | 'title': 'The Late Show - 6/23/21 (Christine Baranski, Joy Oladokun)', | |
106 | 'timestamp': 1624507140, | |
107 | 'description': 'md5:e01af24e95c74d55e8775aef86117b95', | |
108 | 'uploader': 'CBSI-NEW', | |
109 | 'upload_date': '20210624', | |
110 | }, | |
111 | 'params': { | |
112 | 'ignore_no_formats_error': True, | |
113 | 'skip_download': True, | |
114 | }, | |
115 | 'expected_warnings': [ | |
116 | 'This content expired on', 'No video formats found', 'Requested format is not available'], | |
9bf99891 S |
117 | }, { |
118 | 'url': 'http://colbertlateshow.com/video/8GmB0oY0McANFvp2aEffk9jZZZ2YyXxy/the-colbeard/', | |
119 | 'only_matching': True, | |
120 | }, { | |
9d581f3d | 121 | 'url': 'http://www.colbertlateshow.com/podcasts/dYSwjqPs_X1tvbV_P2FcPWRa_qT6akTC/in-the-bad-room-with-stephen/', |
9bf99891 | 122 | 'only_matching': True, |
2871d489 | 123 | }] |
dabe1570 | 124 | |
96820c1c | 125 | def _extract_video_info(self, content_id, site='cbs', mpx_acc=2198311517): |
45cae3b0 | 126 | items_data = self._download_xml( |
2c736b4f | 127 | 'https://can.cbs.com/thunder/player/videoPlayerService.php', |
96820c1c | 128 | content_id, query={'partner': site, 'contentId': content_id}) |
45cae3b0 | 129 | video_data = xpath_element(items_data, './/item') |
430c2757 | 130 | title = xpath_text(video_data, 'videoTitle', 'title') or xpath_text(video_data, 'videotitle', 'title') |
45cae3b0 | 131 | |
6e6e0d95 | 132 | asset_types = {} |
8f70b0b8 | 133 | has_drm = False |
45cae3b0 RA |
134 | for item in items_data.findall('.//item'): |
135 | asset_type = xpath_text(item, 'assetType') | |
45cae3b0 RA |
136 | query = { |
137 | 'mbr': 'true', | |
138 | 'assetTypes': asset_type, | |
139 | } | |
68f5867c L |
140 | if not asset_type: |
141 | # fallback for content_ids that videoPlayerService doesn't return anything for | |
68f5867c L |
142 | asset_type = 'fallback' |
143 | query['formats'] = 'M3U+none,MPEG4,M3U+appleHlsEncryption,MP3' | |
144 | del query['assetTypes'] | |
6e6e0d95 | 145 | if asset_type in asset_types: |
68f5867c L |
146 | continue |
147 | elif any(excluded in asset_type for excluded in ('HLS_FPS', 'DASH_CENC', 'OnceURL')): | |
8f70b0b8 | 148 | if 'DASH_CENC' in asset_type: |
149 | has_drm = True | |
68f5867c | 150 | continue |
68f5867c | 151 | if asset_type.startswith('HLS') or 'StreamPack' in asset_type: |
45cae3b0 RA |
152 | query['formats'] = 'MPEG4,M3U' |
153 | elif asset_type in ('RTMP', 'WIFI', '3G'): | |
154 | query['formats'] = 'MPEG4,FLV' | |
6e6e0d95 | 155 | asset_types[asset_type] = query |
45cae3b0 | 156 | |
8f70b0b8 | 157 | if not asset_types and has_drm: |
158 | self.report_drm(content_id) | |
159 | ||
6e6e0d95 | 160 | return self._extract_common_video_info(content_id, asset_types, mpx_acc, extra_info={ |
161 | 'title': title, | |
162 | 'series': xpath_text(video_data, 'seriesTitle'), | |
163 | 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')), | |
164 | 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')), | |
165 | 'duration': int_or_none(xpath_text(video_data, 'videoLength'), 1000), | |
166 | 'thumbnail': url_or_none(xpath_text(video_data, 'previewImageURL')), | |
dabe1570 | 167 | }) |