]>
Commit | Line | Data |
---|---|---|
f6e43d6f | 1 | import base64 |
2e11e51c | 2 | import re |
f6e43d6f | 3 | import urllib.error |
4 | import urllib.parse | |
2e11e51c RA |
5 | import zlib |
6 | ||
f6e43d6f | 7 | from .anvato import AnvatoIE |
fd3a1f3d | 8 | from .common import InfoExtractor |
f6e43d6f | 9 | from .paramountplus import ParamountPlusIE |
3d2623a8 | 10 | from ..networking import HEADRequest |
8b809a07 | 11 | from ..utils import ( |
f6e43d6f | 12 | ExtractorError, |
f6e43d6f | 13 | UserNotLive, |
14 | determine_ext, | |
15 | float_or_none, | |
16 | format_field, | |
17 | int_or_none, | |
18 | make_archive_id, | |
19 | mimetype2ext, | |
8b809a07 | 20 | parse_duration, |
f6e43d6f | 21 | smuggle_url, |
22 | traverse_obj, | |
23 | url_or_none, | |
8b809a07 | 24 | ) |
85e787f5 S |
25 | |
26 | ||
f6e43d6f | 27 | class CBSNewsBaseIE(InfoExtractor): |
28 | _LOCALES = { | |
29 | 'atlanta': None, | |
30 | 'baltimore': 'BAL', | |
31 | 'boston': 'BOS', | |
32 | 'chicago': 'CHI', | |
33 | 'colorado': 'DEN', | |
34 | 'detroit': 'DET', | |
35 | 'losangeles': 'LA', | |
36 | 'miami': 'MIA', | |
37 | 'minnesota': 'MIN', | |
38 | 'newyork': 'NY', | |
39 | 'philadelphia': 'PHI', | |
40 | 'pittsburgh': 'PIT', | |
41 | 'sacramento': 'SAC', | |
42 | 'sanfrancisco': 'SF', | |
43 | 'texas': 'DAL', | |
44 | } | |
45 | _LOCALE_RE = '|'.join(map(re.escape, _LOCALES)) | |
46 | _ANVACK = '5VD6Eyd6djewbCmNwBFnsJj17YAvGRwl' | |
47 | ||
48 | def _get_item(self, webpage, display_id): | |
49 | return traverse_obj(self._search_json( | |
50 | r'CBSNEWS\.defaultPayload\s*=', webpage, 'payload', display_id, | |
51 | default={}), ('items', 0, {dict})) or {} | |
52 | ||
53 | def _get_video_url(self, item): | |
54 | return traverse_obj(item, 'video', 'video2', expected_type=url_or_none) | |
55 | ||
56 | def _extract_playlist(self, webpage, playlist_id): | |
57 | entries = [self.url_result(embed_url, CBSNewsEmbedIE) for embed_url in re.findall( | |
58 | r'<iframe[^>]+data-src="(https?://(?:www\.)?cbsnews\.com/embed/video/[^#]*#[^"]+)"', webpage)] | |
59 | if entries: | |
60 | return self.playlist_result( | |
61 | entries, playlist_id, self._html_search_meta(['og:title', 'twitter:title'], webpage), | |
62 | self._html_search_meta(['og:description', 'twitter:description', 'description'], webpage)) | |
63 | ||
64 | def _extract_video(self, item, video_url, video_id): | |
65 | if mimetype2ext(item.get('format'), default=determine_ext(video_url)) == 'mp4': | |
66 | formats = [{'url': video_url, 'ext': 'mp4'}] | |
67 | ||
68 | else: | |
69 | manifest = self._download_webpage(video_url, video_id, note='Downloading m3u8 information') | |
70 | ||
71 | anvato_id = self._search_regex(r'anvato-(\d+)', manifest, 'Anvato ID', default=None) | |
72 | # Prefer Anvato if available; cbsnews.com m3u8 formats are re-encoded from Anvato source | |
73 | if anvato_id: | |
74 | return self.url_result( | |
75 | smuggle_url(f'anvato:{self._ANVACK}:{anvato_id}', {'token': 'default'}), | |
76 | AnvatoIE, url_transparent=True, _old_archive_ids=[make_archive_id(self, anvato_id)]) | |
77 | ||
78 | formats, _ = self._parse_m3u8_formats_and_subtitles( | |
79 | manifest, video_url, 'mp4', m3u8_id='hls', video_id=video_id) | |
80 | ||
81 | def get_subtitles(subs_url): | |
82 | return { | |
83 | 'en': [{ | |
84 | 'url': subs_url, | |
85 | 'ext': 'dfxp', # TTAF1 | |
86 | }], | |
87 | } if url_or_none(subs_url) else None | |
88 | ||
89 | episode_meta = traverse_obj(item, { | |
90 | 'season_number': ('season', {int_or_none}), | |
91 | 'episode_number': ('episode', {int_or_none}), | |
92 | }) if item.get('isFullEpisode') else {} | |
93 | ||
94 | return { | |
95 | 'id': video_id, | |
96 | 'formats': formats, | |
97 | **traverse_obj(item, { | |
98 | 'title': (None, ('fulltitle', 'title')), | |
99 | 'description': 'dek', | |
100 | 'timestamp': ('timestamp', {lambda x: float_or_none(x, 1000)}), | |
101 | 'duration': ('duration', {float_or_none}), | |
102 | 'subtitles': ('captions', {get_subtitles}), | |
103 | 'thumbnail': ('images', ('hd', 'sd'), {url_or_none}), | |
104 | 'is_live': ('type', {lambda x: x == 'live'}), | |
105 | }, get_all=False), | |
106 | **episode_meta, | |
107 | } | |
108 | ||
109 | ||
110 | class CBSNewsEmbedIE(CBSNewsBaseIE): | |
2e11e51c RA |
111 | IE_NAME = 'cbsnews:embed' |
112 | _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/embed/video[^#]*#(?P<id>.+)' | |
113 | _TESTS = [{ | |
114 | 'url': 'https://www.cbsnews.com/embed/video/?v=1.c9b5b61492913d6660db0b2f03579ef25e86307a#1Vb7b9s2EP5XBAHbT6Gt98PAMKTJ0se6LVjWYWtdGBR1stlIpEBSTtwi%2F%2FvuJNkNhmHdGxgM2NL57vjd6zt%2B8PngdN%2Fyg79qeGvhzN%2FLGrS%2F%2BuBLB531V28%2B%2BO7Qg7%2Fy97r2z3xZ42NW8yLhDbA0S0KWlHnIijwKWJBHZZnHBa8Cgbpdf%2F89NM9Hi9fXifhpr8sr%2FlP848tn%2BTdXycX25zh4cdX%2FvHl6PmmPqnWQv9w8Ed%2B9GjYRim07bFEqdG%2BZVHuwTm65A7bVRrYtR5lAyMox7pigF6W4k%2By91mjspGsJ%2BwVae4%2BsvdnaO1p73HkXs%2FVisUDTGm7R8IcdnOROeq%2B19qT1amhA1VJtPenoTUgrtfKc9m7Rq8dP7nnjwOB7wg7ADdNt7VX64DWAWlKhPtmDEq22g4GF99x6Dk9E8OSsankHXqPNKDxC%2FdK7MLKTircTDgsI3mmj4OBdSq64dy7fd1x577RU1rt4cvMtOaulFYOd%2FLewRWvDO9lIgXFpZSnkZmjbv5SxKTPoQXClFbpsf%2Fhbbpzs0IB3vb8KkyzJQ%2BywOAgCrMpgRrz%2BKk4fvb7kFbR4XJCu0gAdtNO7woCwZTu%2BBUs9bam%2Fds71drVerpeisgrubLjAB4nnOSkWQnfr5W6o1ku5Xpr1MgrCbL0M0vUyDtfLLK15WiYp47xKWSLyjFVpwVmVJSLIoCjSOFkv3W7oKsVliwZJcB9nwXpZ5GEQQwY8jNKqKCBrgjTLeFxgdCIpazojDgnRtn43J6kG7nZ6cAbxh0EeFFk4%2B1u867cY5u4344n%2FxXjCqAjucdTHgLKojNKmSfO8KRsOFY%2FzKEYCKEJBzv90QA9nfm9gL%2BHulaFqUkz9ULUYxl62B3U%2FRVNLA8IhggaPycOoBuwOCESciDQVSSUgiOMsROB%2FhKfwCKOzEk%2B4k6rWd4uuT%2FwTDz7K7t3d3WLO8ISD95jSPQbayBacthbz86XVgxHwhex5zawzgDOmtp%2F3GPcXn0VXHdSS029%2Fj99UC%2FwJUvyKQ%2FzKyixIEVlYJOn4RxxuaH43Ty9fbJ5OObykHH435XAzJTHeOF4hhEUXD8URe%2FQ%2FBT%2BMpf8d5GN02Ox%2FfiGsl7TA7POu1xZ5%2BbTzcAVKMe48mqcC21hkacVEVScM26liVVBnrKkC4CLKyzAvHu0lhEaTKMFwI3a4SN9MsrfYzdBLq2vkwRD1gVviLT8kY9h2CHH6Y%2Bix6609weFtey4ESp60WtyeWMy%2BsmBuhsoKIyuoT%2Bq2R%2FrW5qi3g%2FvzS2j40DoixDP8%2BKP0yUdpXJ4l6Vla%2Bg9vce%2BC4yM5YlUcbA%2F0jLKdpmTwvsdN5z88nAIe08%2F0HgxeG1iv%2B6Hlhjh7uiW0SDzYNI92L401uha3JKYk268UVRzdOzNQvAaJqoXzAc80dAV440NZ1WVVAAMRYQ2KrGJFmDUsq8saWSnjvIj8t78y%2FRa3JRnbHVfyFpfwoDiGpPgjzekyUiKNlU3OMlwuLMmzgvEojllYVE2Z1HhImvsnk%2BuhusTEoB21PAtSFodeFK3iYhXEH9WOG2%2FkOE833sfeG%2Ff5cfHtEFNXgYes0%2FXj7aGivUgJ9XpusCtoNcNYVVnJVrrDo0OmJAutHCpuZul4W9lLcfy7BnuLPT02%2ByXsCTk%2B9zhzswIN04YueNSK%2BPtM0jS88QdLqSLJDTLsuGZJNolm2yO0PXh3UPnz9Ix5bfIAqxPjvETQsDCEiPG4QbqNyhBZISxybLnZYCrW5H3Axp690%2F0BJdXtDZ5ITuM4xj3f4oUHGzc5JeJmZKpp%2FjwKh4wMV%2FV1yx3emLoR0MwbG4K%2F%2BZgVep3PnzXGDHZ6a3i%2Fk%2BJrONDN13%2Bnq6tBTYk4o7cLGhBtqCC4KwacGHpEVuoH5JNro%2FE6JfE6d5RydbiR76k%2BW5wioDHBIjw1euhHjUGRB0y5A97KoaPx6MlL%2BwgboUVtUFRI%2FLemgTpdtF59ii7pab08kuPcfWzs0l%2FRI5takWnFpka0zOgWRtYcuf9aIxZMxlwr6IiGpsb6j2DQUXPl%2FimXI599Ev7fWjoPD78A', | |
f6e43d6f | 115 | 'info_dict': { |
116 | 'id': '6ZP4cXvo9FaX3VLH7MF4CgY30JFpY_GA', | |
117 | 'ext': 'mp4', | |
118 | 'title': 'Cops investigate gorilla incident at Cincinnati Zoo', | |
119 | 'description': 'md5:fee7441ab8aaeb3c693482394738102b', | |
120 | 'duration': 350, | |
121 | 'timestamp': 1464719713, | |
122 | 'upload_date': '20160531', | |
123 | 'thumbnail': r're:^https?://.*\.jpg$', | |
124 | }, | |
125 | 'params': {'skip_download': 'm3u8'}, | |
2e11e51c RA |
126 | }] |
127 | ||
128 | def _real_extract(self, url): | |
f6e43d6f | 129 | item = traverse_obj(self._parse_json(zlib.decompress(base64.b64decode( |
130 | urllib.parse.unquote(self._match_id(url))), | |
131 | -zlib.MAX_WBITS).decode(), None), ('video', 'items', 0, {dict})) or {} | |
2e11e51c | 132 | |
f6e43d6f | 133 | video_id = item['mpxRefId'] |
134 | video_url = self._get_video_url(item) | |
135 | if not video_url: | |
136 | # Old embeds redirect user to ParamountPlus but most links are 404 | |
137 | pplus_url = f'https://www.paramountplus.com/shows/video/{video_id}' | |
138 | try: | |
139 | self._request_webpage(HEADRequest(pplus_url), video_id) | |
140 | return self.url_result(pplus_url, ParamountPlusIE) | |
141 | except ExtractorError: | |
142 | self.raise_no_formats('This video is no longer available', True, video_id) | |
2e11e51c | 143 | |
f6e43d6f | 144 | return self._extract_video(item, video_url, video_id) |
145 | ||
146 | ||
147 | class CBSNewsIE(CBSNewsBaseIE): | |
7fd57de6 | 148 | IE_NAME = 'cbsnews' |
85e787f5 | 149 | IE_DESC = 'CBS News' |
f6e43d6f | 150 | _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/(?:news|video)/(?P<id>[\w-]+)' |
85e787f5 S |
151 | |
152 | _TESTS = [ | |
153 | { | |
a919ca0a S |
154 | # 60 minutes |
155 | 'url': 'http://www.cbsnews.com/news/artificial-intelligence-positioned-to-be-a-game-changer/', | |
85e787f5 | 156 | 'info_dict': { |
2e11e51c RA |
157 | 'id': 'Y_nf_aEg6WwO9OLAq0MpKaPgfnBUxfW4', |
158 | 'ext': 'flv', | |
159 | 'title': 'Artificial Intelligence, real-life applications', | |
160 | 'description': 'md5:a7aaf27f1b4777244de8b0b442289304', | |
a919ca0a | 161 | 'thumbnail': r're:^https?://.*\.jpg$', |
2e11e51c | 162 | 'duration': 317, |
a919ca0a | 163 | 'uploader': 'CBSI-NEW', |
2e11e51c RA |
164 | 'timestamp': 1476046464, |
165 | 'upload_date': '20161009', | |
85e787f5 | 166 | }, |
f6e43d6f | 167 | 'skip': 'This video is no longer available', |
85e787f5 S |
168 | }, |
169 | { | |
2e11e51c | 170 | 'url': 'https://www.cbsnews.com/video/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/', |
85e787f5 | 171 | 'info_dict': { |
43518503 | 172 | 'id': 'SNJBOYzXiWBOvaLsdzwH8fmtP1SCd91Y', |
f125d911 | 173 | 'ext': 'mp4', |
85e787f5 | 174 | 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack', |
43518503 | 175 | 'description': 'md5:4a6983e480542d8b333a947bfc64ddc7', |
dabe1570 RA |
176 | 'upload_date': '20140404', |
177 | 'timestamp': 1396650660, | |
ec85ded8 | 178 | 'thumbnail': r're:^https?://.*\.jpg$', |
85e787f5 | 179 | 'duration': 205, |
220ee33f S |
180 | 'subtitles': { |
181 | 'en': [{ | |
f6e43d6f | 182 | 'ext': 'dfxp', |
220ee33f S |
183 | }], |
184 | }, | |
4118cc02 JA |
185 | }, |
186 | 'params': { | |
f6e43d6f | 187 | 'skip_download': 'm3u8', |
4118cc02 JA |
188 | }, |
189 | }, | |
88d6b7c2 | 190 | { |
a919ca0a | 191 | # 48 hours |
88d6b7c2 PV |
192 | 'url': 'http://www.cbsnews.com/news/maria-ridulph-murder-will-the-nations-oldest-cold-case-to-go-to-trial-ever-get-solved/', |
193 | 'info_dict': { | |
f6e43d6f | 194 | 'id': 'maria-ridulph-murder-will-the-nations-oldest-cold-case-to-go-to-trial-ever-get-solved', |
88d6b7c2 | 195 | 'title': 'Cold as Ice', |
2e11e51c | 196 | 'description': 'Can a childhood memory solve the 1957 murder of 7-year-old Maria Ridulph?', |
88d6b7c2 | 197 | }, |
2e11e51c | 198 | 'playlist_mincount': 7, |
88d6b7c2 | 199 | }, |
f6e43d6f | 200 | { |
201 | 'url': 'https://www.cbsnews.com/video/032823-cbs-evening-news/', | |
202 | 'info_dict': { | |
203 | 'id': '_2wuO7hD9LwtyM_TwSnVwnKp6kxlcXgE', | |
204 | 'ext': 'mp4', | |
205 | 'title': 'CBS Evening News, March 28, 2023', | |
206 | 'description': 'md5:db20615aae54adc1d55a1fd69dc75d13', | |
207 | 'duration': 1189, | |
208 | 'timestamp': 1680042600, | |
209 | 'upload_date': '20230328', | |
210 | 'season': 'Season 2023', | |
211 | 'season_number': 2023, | |
212 | 'episode': 'Episode 83', | |
213 | 'episode_number': 83, | |
214 | 'thumbnail': r're:^https?://.*\.jpg$', | |
215 | }, | |
216 | 'params': { | |
217 | 'skip_download': 'm3u8', | |
218 | }, | |
219 | }, | |
85e787f5 S |
220 | ] |
221 | ||
222 | def _real_extract(self, url): | |
2e11e51c | 223 | display_id = self._match_id(url) |
f6e43d6f | 224 | webpage = self._download_webpage(url, display_id) |
225 | ||
226 | playlist = self._extract_playlist(webpage, display_id) | |
227 | if playlist: | |
228 | return playlist | |
85e787f5 | 229 | |
f6e43d6f | 230 | item = self._get_item(webpage, display_id) |
231 | video_id = item.get('mpxRefId') or display_id | |
232 | video_url = self._get_video_url(item) | |
233 | if not video_url: | |
234 | self.raise_no_formats('No video content was found', expected=True, video_id=video_id) | |
235 | ||
236 | return self._extract_video(item, video_url, video_id) | |
237 | ||
238 | ||
239 | class CBSLocalBaseIE(CBSNewsBaseIE): | |
240 | def _real_extract(self, url): | |
241 | display_id = self._match_id(url) | |
2e11e51c | 242 | webpage = self._download_webpage(url, display_id) |
85e787f5 | 243 | |
f6e43d6f | 244 | item = self._get_item(webpage, display_id) |
245 | video_id = item.get('mpxRefId') or display_id | |
246 | anvato_id = None | |
247 | video_url = self._get_video_url(item) | |
248 | ||
249 | if not video_url: | |
250 | anv_params = self._search_regex( | |
251 | r'<iframe[^>]+\bdata-src="https?://w3\.mp\.lura\.live/player/prod/v3/anvload\.html\?key=([^"]+)"', | |
252 | webpage, 'Anvato URL', default=None) | |
253 | ||
254 | if not anv_params: | |
255 | playlist = self._extract_playlist(webpage, display_id) | |
256 | if playlist: | |
257 | return playlist | |
258 | self.raise_no_formats('No video content was found', expected=True, video_id=video_id) | |
259 | ||
260 | anv_data = self._parse_json(base64.urlsafe_b64decode(f'{anv_params}===').decode(), video_id) | |
261 | anvato_id = anv_data['v'] | |
262 | return self.url_result( | |
263 | smuggle_url(f'anvato:{anv_data.get("anvack") or self._ANVACK}:{anvato_id}', { | |
264 | 'token': anv_data.get('token') or 'default', | |
265 | }), AnvatoIE, url_transparent=True, _old_archive_ids=[make_archive_id(self, anvato_id)]) | |
266 | ||
267 | return self._extract_video(item, video_url, video_id) | |
268 | ||
7f4c3a74 | 269 | |
f6e43d6f | 270 | class CBSLocalIE(CBSLocalBaseIE): |
271 | _VALID_URL = rf'https?://(?:www\.)?cbsnews\.com/(?:{CBSNewsBaseIE._LOCALE_RE})/(?:live/)?video/(?P<id>[\w-]+)' | |
272 | _TESTS = [{ | |
273 | # Anvato video via defaultPayload JSON | |
274 | 'url': 'https://www.cbsnews.com/newyork/video/1st-cannabis-dispensary-opens-in-queens/', | |
275 | 'info_dict': { | |
276 | 'id': '6376747', | |
277 | 'ext': 'mp4', | |
278 | 'title': '1st cannabis dispensary opens in Queens', | |
279 | 'description': 'The dispensary is women-owned and located in Jamaica.', | |
280 | 'uploader': 'CBS', | |
281 | 'duration': 20, | |
282 | 'timestamp': 1680193657, | |
283 | 'upload_date': '20230330', | |
284 | 'categories': ['Stations\\Spoken Word\\WCBSTV', 'Content\\Google', 'Content\\News', 'Content\\News\\Local News'], | |
285 | 'tags': 'count:11', | |
286 | 'thumbnail': 're:^https?://.*', | |
287 | '_old_archive_ids': ['cbslocal 6376747'], | |
288 | }, | |
289 | 'params': {'skip_download': 'm3u8'}, | |
290 | }, { | |
291 | # cbsnews.com video via defaultPayload JSON | |
292 | 'url': 'https://www.cbsnews.com/newyork/live/video/20230330171655-the-city-is-sounding-the-alarm-on-dangerous-social-media-challenges/', | |
293 | 'info_dict': { | |
294 | 'id': 'sJqfw7YvgSC6ant2zVmzt3y1jYKoL5J3', | |
295 | 'ext': 'mp4', | |
296 | 'title': 'the city is sounding the alarm on dangerous social media challenges', | |
297 | 'description': 'md5:8eccc9b1b73be5138a52e9c4350d2cd6', | |
298 | 'thumbnail': 'https://images-cbsn.cbsnews.com/prod/2023/03/30/story_22509622_1680196925.jpg', | |
299 | 'duration': 41.0, | |
300 | 'timestamp': 1680196615, | |
301 | 'upload_date': '20230330', | |
302 | }, | |
303 | 'params': {'skip_download': 'm3u8'}, | |
304 | }] | |
305 | ||
306 | ||
307 | class CBSLocalArticleIE(CBSLocalBaseIE): | |
308 | _VALID_URL = rf'https?://(?:www\.)?cbsnews\.com/(?:{CBSNewsBaseIE._LOCALE_RE})/news/(?P<id>[\w-]+)' | |
309 | _TESTS = [{ | |
310 | # Anvato video via iframe embed | |
311 | 'url': 'https://www.cbsnews.com/newyork/news/mta-station-agents-leaving-their-booths-to-provide-more-direct-customer-service/', | |
312 | 'playlist_count': 2, | |
313 | 'info_dict': { | |
314 | 'id': 'mta-station-agents-leaving-their-booths-to-provide-more-direct-customer-service', | |
315 | 'title': 'MTA station agents begin leaving their booths to provide more direct customer service', | |
316 | 'description': 'The more than 2,200 agents will provide face-to-face customer service to passengers.', | |
317 | }, | |
318 | }, { | |
319 | 'url': 'https://www.cbsnews.com/losangeles/news/safety-advocates-say-fatal-car-seat-failures-are-public-health-crisis/', | |
320 | 'md5': 'f0ee3081e3843f575fccef901199b212', | |
321 | 'info_dict': { | |
322 | 'id': '3401037', | |
323 | 'ext': 'mp4', | |
324 | 'title': 'Safety Advocates Say Fatal Car Seat Failures Are \'Public Health Crisis\'', | |
325 | 'thumbnail': 're:^https?://.*', | |
326 | 'timestamp': 1463440500, | |
327 | 'upload_date': '20160516', | |
328 | }, | |
329 | 'skip': 'Video has been removed', | |
330 | }] | |
331 | ||
332 | ||
333 | class CBSNewsLiveBaseIE(CBSNewsBaseIE): | |
334 | def _get_id(self, url): | |
335 | raise NotImplementedError('This method must be implemented by subclasses') | |
336 | ||
337 | def _real_extract(self, url): | |
338 | video_id = self._get_id(url) | |
339 | if not video_id: | |
340 | raise ExtractorError('Livestream is not available', expected=True) | |
341 | ||
342 | data = traverse_obj(self._download_json( | |
343 | 'https://feeds-cbsn.cbsnews.com/2.0/rundown/', video_id, query={ | |
344 | 'partner': 'cbsnsite', | |
345 | 'edition': video_id, | |
346 | 'type': 'live', | |
347 | }), ('navigation', 'data', 0, {dict})) | |
348 | ||
349 | video_url = traverse_obj(data, (('videoUrlDAI', ('videoUrl', 'base')), {url_or_none}), get_all=False) | |
350 | if not video_url: | |
351 | raise UserNotLive(video_id=video_id) | |
352 | ||
353 | formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_url, video_id, 'mp4', m3u8_id='hls') | |
354 | ||
355 | return { | |
356 | 'id': video_id, | |
357 | 'formats': formats, | |
358 | 'subtitles': subtitles, | |
359 | 'is_live': True, | |
360 | **traverse_obj(data, { | |
361 | 'title': 'headline', | |
362 | 'description': 'rundown_slug', | |
363 | 'thumbnail': ('images', 'thumbnail_url_hd', {url_or_none}), | |
364 | }), | |
365 | } | |
366 | ||
367 | ||
368 | class CBSLocalLiveIE(CBSNewsLiveBaseIE): | |
369 | _VALID_URL = rf'https?://(?:www\.)?cbsnews\.com/(?P<id>{CBSNewsBaseIE._LOCALE_RE})/live/?(?:[?#]|$)' | |
370 | _TESTS = [{ | |
371 | 'url': 'https://www.cbsnews.com/losangeles/live/', | |
372 | 'info_dict': { | |
373 | 'id': 'CBSN-LA', | |
374 | 'ext': 'mp4', | |
375 | 'title': str, | |
376 | 'description': r're:KCBS/CBSN_LA.CRISPIN.\w+.RUNDOWN \w+ \w+', | |
377 | 'thumbnail': r're:^https?://.*\.jpg$', | |
378 | 'live_status': 'is_live', | |
379 | }, | |
380 | 'params': {'skip_download': 'm3u8'}, | |
381 | }] | |
382 | ||
383 | def _get_id(self, url): | |
384 | return format_field(self._LOCALES, self._match_id(url), 'CBSN-%s') | |
385 | ||
386 | ||
387 | class CBSNewsLiveIE(CBSNewsLiveBaseIE): | |
388 | IE_NAME = 'cbsnews:live' | |
389 | IE_DESC = 'CBS News Livestream' | |
390 | _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/live/?(?:[?#]|$)' | |
391 | _TESTS = [{ | |
392 | 'url': 'https://www.cbsnews.com/live/', | |
393 | 'info_dict': { | |
394 | 'id': 'CBSN-US', | |
395 | 'ext': 'mp4', | |
396 | 'title': str, | |
397 | 'description': r're:\w+ \w+ CRISPIN RUNDOWN', | |
398 | 'thumbnail': r're:^https?://.*\.jpg$', | |
399 | 'live_status': 'is_live', | |
400 | }, | |
401 | 'params': {'skip_download': 'm3u8'}, | |
402 | }] | |
403 | ||
404 | def _get_id(self, url): | |
405 | return 'CBSN-US' | |
fd3a1f3d | 406 | |
407 | ||
408 | class CBSNewsLiveVideoIE(InfoExtractor): | |
7fd57de6 | 409 | IE_NAME = 'cbsnews:livevideo' |
fd3a1f3d | 410 | IE_DESC = 'CBS News Live Videos' |
7fd57de6 | 411 | _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/live/video/(?P<id>[^/?#]+)' |
fd3a1f3d | 412 | |
69eb4d69 | 413 | # Live videos get deleted soon. See http://www.cbsnews.com/live/ for the latest examples |
f6e43d6f | 414 | _TESTS = [{ |
fd3a1f3d | 415 | 'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/', |
416 | 'info_dict': { | |
417 | 'id': 'clinton-sanders-prepare-to-face-off-in-nh', | |
7fd57de6 | 418 | 'ext': 'mp4', |
fd3a1f3d | 419 | 'title': 'Clinton, Sanders Prepare To Face Off In NH', |
420 | 'duration': 334, | |
421 | }, | |
69eb4d69 | 422 | 'skip': 'Video gone', |
f6e43d6f | 423 | }] |
fd3a1f3d | 424 | |
425 | def _real_extract(self, url): | |
7fd57de6 | 426 | display_id = self._match_id(url) |
fd3a1f3d | 427 | |
7fd57de6 RA |
428 | video_info = self._download_json( |
429 | 'http://feeds.cbsn.cbsnews.com/rundown/story', display_id, query={ | |
430 | 'device': 'desktop', | |
431 | 'dvr_slug': display_id, | |
432 | }) | |
fd3a1f3d | 433 | |
fd3a1f3d | 434 | return { |
7fd57de6 RA |
435 | 'id': display_id, |
436 | 'display_id': display_id, | |
f6e43d6f | 437 | 'formats': self._extract_akamai_formats(video_info['url'], display_id), |
438 | **traverse_obj(video_info, { | |
439 | 'title': 'headline', | |
440 | 'thumbnail': ('thumbnail_url_hd', {url_or_none}), | |
441 | 'duration': ('segmentDur', {parse_duration}), | |
442 | }), | |
fd3a1f3d | 443 | } |