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