]>
Commit | Line | Data |
---|---|---|
8b85ac3f | 1 | import re |
d183af3c | 2 | import json |
3 | import base64 | |
4 | import time | |
ed711897 | 5 | import urllib.parse |
8b85ac3f | 6 | |
7 | from .common import InfoExtractor | |
64f03e5b S |
8 | from ..compat import ( |
9 | compat_str, | |
64f03e5b | 10 | ) |
52f7c75c | 11 | from ..utils import ( |
7a7b1376 | 12 | ExtractorError, |
54c2521c DS |
13 | int_or_none, |
14 | join_nonempty, | |
52f7c75c | 15 | js_to_json, |
f20f6365 | 16 | orderedSet, |
7a7b1376 | 17 | parse_iso8601, |
54c2521c | 18 | smuggle_url, |
986c0b02 | 19 | strip_or_none, |
7a7b1376 | 20 | traverse_obj, |
54c2521c | 21 | try_get, |
52f7c75c | 22 | ) |
8b85ac3f | 23 | |
24 | ||
25 | class CBCIE(InfoExtractor): | |
30afe4ae | 26 | IE_NAME = 'cbc.ca' |
043dc9d3 | 27 | _VALID_URL = r'https?://(?:www\.)?cbc\.ca/(?!player/)(?:[^/]+/)+(?P<id>[^/?#]+)' |
8b85ac3f | 28 | _TESTS = [{ |
29 | # with mediaId | |
30 | 'url': 'http://www.cbc.ca/22minutes/videos/clips-season-23/don-cherry-play-offs', | |
52f7c75c | 31 | 'md5': '97e24d09672fc4cf56256d6faa6c25bc', |
8b85ac3f | 32 | 'info_dict': { |
33 | 'id': '2682904050', | |
52f7c75c | 34 | 'ext': 'mp4', |
8b85ac3f | 35 | 'title': 'Don Cherry – All-Stars', |
36 | 'description': 'Don Cherry has a bee in his bonnet about AHL player John Scott because that guy’s got heart.', | |
52f7c75c | 37 | 'timestamp': 1454463000, |
8b85ac3f | 38 | 'upload_date': '20160203', |
52f7c75c | 39 | 'uploader': 'CBCC-NEW', |
8b85ac3f | 40 | }, |
21ba7d09 | 41 | 'skip': 'Geo-restricted to Canada', |
8b85ac3f | 42 | }, { |
88bd486b S |
43 | # with clipId, feed available via tpfeed.cbc.ca and feed.theplatform.com |
44 | 'url': 'http://www.cbc.ca/22minutes/videos/22-minutes-update/22-minutes-update-episode-4', | |
45 | 'md5': '162adfa070274b144f4fdc3c3b8207db', | |
46 | 'info_dict': { | |
47 | 'id': '2414435309', | |
48 | 'ext': 'mp4', | |
49 | 'title': '22 Minutes Update: What Not To Wear Quebec', | |
50 | 'description': "This week's latest Canadian top political story is What Not To Wear Quebec.", | |
51 | 'upload_date': '20131025', | |
52 | 'uploader': 'CBCC-NEW', | |
53 | 'timestamp': 1382717907, | |
54 | }, | |
0d32e124 | 55 | 'skip': 'No longer available', |
88bd486b S |
56 | }, { |
57 | # with clipId, feed only available via tpfeed.cbc.ca | |
8b85ac3f | 58 | 'url': 'http://www.cbc.ca/archives/entry/1978-robin-williams-freestyles-on-90-minutes-live', |
64413f75 | 59 | 'md5': '0274a90b51a9b4971fe005c63f592f12', |
8b85ac3f | 60 | 'info_dict': { |
61 | 'id': '2487345465', | |
52f7c75c | 62 | 'ext': 'mp4', |
8b85ac3f | 63 | 'title': 'Robin Williams freestyles on 90 Minutes Live', |
64 | 'description': 'Wacky American comedian Robin Williams shows off his infamous "freestyle" comedic talents while being interviewed on CBC\'s 90 Minutes Live.', | |
52f7c75c | 65 | 'upload_date': '19780210', |
0738187f | 66 | 'uploader': 'CBCC-NEW', |
52f7c75c | 67 | 'timestamp': 255977160, |
8b85ac3f | 68 | }, |
19c90e40 | 69 | 'skip': '404 Not Found', |
8b85ac3f | 70 | }, { |
71 | # multiple iframes | |
72 | 'url': 'http://www.cbc.ca/natureofthings/blog/birds-eye-view-from-vancouvers-burrard-street-bridge-how-we-got-the-shot', | |
73 | 'playlist': [{ | |
52f7c75c | 74 | 'md5': '377572d0b49c4ce0c9ad77470e0b96b4', |
8b85ac3f | 75 | 'info_dict': { |
76 | 'id': '2680832926', | |
52f7c75c | 77 | 'ext': 'mp4', |
8b85ac3f | 78 | 'title': 'An Eagle\'s-Eye View Off Burrard Bridge', |
79 | 'description': 'Hercules the eagle flies from Vancouver\'s Burrard Bridge down to a nearby park with a mini-camera strapped to his back.', | |
52f7c75c | 80 | 'upload_date': '20160201', |
81 | 'timestamp': 1454342820, | |
82 | 'uploader': 'CBCC-NEW', | |
8b85ac3f | 83 | }, |
84 | }, { | |
52f7c75c | 85 | 'md5': '415a0e3f586113894174dfb31aa5bb1a', |
8b85ac3f | 86 | 'info_dict': { |
87 | 'id': '2658915080', | |
52f7c75c | 88 | 'ext': 'mp4', |
8b85ac3f | 89 | 'title': 'Fly like an eagle!', |
90 | 'description': 'Eagle equipped with a mini camera flies from the world\'s tallest tower', | |
52f7c75c | 91 | 'upload_date': '20150315', |
92 | 'timestamp': 1426443984, | |
93 | 'uploader': 'CBCC-NEW', | |
8b85ac3f | 94 | }, |
95 | }], | |
21ba7d09 | 96 | 'skip': 'Geo-restricted to Canada', |
abe8cb76 S |
97 | }, { |
98 | # multiple CBC.APP.Caffeine.initInstance(...) | |
99 | 'url': 'http://www.cbc.ca/news/canada/calgary/dog-indoor-exercise-winter-1.3928238', | |
100 | 'info_dict': { | |
19c90e40 | 101 | 'title': 'Keep Rover active during the deep freeze with doggie pushups and other fun indoor tasks', # FIXME |
abe8cb76 | 102 | 'id': 'dog-indoor-exercise-winter-1.3928238', |
c95e2b59 | 103 | 'description': 'md5:c18552e41726ee95bd75210d1ca9194c', |
abe8cb76 S |
104 | }, |
105 | 'playlist_mincount': 6, | |
8b85ac3f | 106 | }] |
107 | ||
108 | @classmethod | |
109 | def suitable(cls, url): | |
110 | return False if CBCPlayerIE.suitable(url) else super(CBCIE, cls).suitable(url) | |
111 | ||
abe8cb76 S |
112 | def _extract_player_init(self, player_init, display_id): |
113 | player_info = self._parse_json(player_init, display_id, js_to_json) | |
114 | media_id = player_info.get('mediaId') | |
115 | if not media_id: | |
116 | clip_id = player_info['clipId'] | |
117 | feed = self._download_json( | |
118 | 'http://tpfeed.cbc.ca/f/ExhSPC/vms_5akSXx4Ng_Zn?byCustomValue={:mpsReleases}{%s}' % clip_id, | |
119 | clip_id, fatal=False) | |
120 | if feed: | |
121 | media_id = try_get(feed, lambda x: x['entries'][0]['guid'], compat_str) | |
122 | if not media_id: | |
123 | media_id = self._download_json( | |
124 | 'http://feed.theplatform.com/f/h9dtGB/punlNGjMlc1F?fields=id&byContent=byReleases%3DbyId%253D' + clip_id, | |
125 | clip_id)['entries'][0]['id'].split('/')[-1] | |
126 | return self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id) | |
127 | ||
8b85ac3f | 128 | def _real_extract(self, url): |
129 | display_id = self._match_id(url) | |
130 | webpage = self._download_webpage(url, display_id) | |
04f3fd2c | 131 | title = (self._og_search_title(webpage, default=None) |
132 | or self._html_search_meta('twitter:title', webpage, 'title', default=None) | |
133 | or self._html_extract_title(webpage)) | |
abe8cb76 S |
134 | entries = [ |
135 | self._extract_player_init(player_init, display_id) | |
136 | for player_init in re.findall(r'CBC\.APP\.Caffeine\.initInstance\(({.+?})\);', webpage)] | |
f20f6365 S |
137 | media_ids = [] |
138 | for media_id_re in ( | |
139 | r'<iframe[^>]+src="[^"]+?mediaId=(\d+)"', | |
140 | r'<div[^>]+\bid=["\']player-(\d+)', | |
141 | r'guid["\']\s*:\s*["\'](\d+)'): | |
142 | media_ids.extend(re.findall(media_id_re, webpage)) | |
abe8cb76 S |
143 | entries.extend([ |
144 | self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id) | |
f20f6365 | 145 | for media_id in orderedSet(media_ids)]) |
abe8cb76 | 146 | return self.playlist_result( |
986c0b02 | 147 | entries, display_id, strip_or_none(title), |
abe8cb76 | 148 | self._og_search_description(webpage)) |
8b85ac3f | 149 | |
150 | ||
151 | class CBCPlayerIE(InfoExtractor): | |
30afe4ae | 152 | IE_NAME = 'cbc.ca:player' |
8b85ac3f | 153 | _VALID_URL = r'(?:cbcplayer:|https?://(?:www\.)?cbc\.ca/(?:player/play/|i/caffeine/syndicate/\?mediaId=))(?P<id>\d+)' |
31a70191 | 154 | _TESTS = [{ |
8b85ac3f | 155 | 'url': 'http://www.cbc.ca/player/play/2683190193', |
64413f75 | 156 | 'md5': '64d25f841ddf4ddb28a235338af32e2c', |
8b85ac3f | 157 | 'info_dict': { |
158 | 'id': '2683190193', | |
52f7c75c | 159 | 'ext': 'mp4', |
8b85ac3f | 160 | 'title': 'Gerry Runs a Sweat Shop', |
161 | 'description': 'md5:b457e1c01e8ff408d9d801c1c2cd29b0', | |
52f7c75c | 162 | 'timestamp': 1455071400, |
8b85ac3f | 163 | 'upload_date': '20160210', |
52f7c75c | 164 | 'uploader': 'CBCC-NEW', |
8b85ac3f | 165 | }, |
339c339f | 166 | 'skip': 'Geo-restricted to Canada and no longer available', |
31a70191 YCH |
167 | }, { |
168 | # Redirected from http://www.cbc.ca/player/AudioMobile/All%20in%20a%20Weekend%20Montreal/ID/2657632011/ | |
169 | 'url': 'http://www.cbc.ca/player/play/2657631896', | |
170 | 'md5': 'e5e708c34ae6fca156aafe17c43e8b75', | |
171 | 'info_dict': { | |
172 | 'id': '2657631896', | |
173 | 'ext': 'mp3', | |
174 | 'title': 'CBC Montreal is organizing its first ever community hackathon!', | |
175 | 'description': 'The modern technology we tend to depend on so heavily, is never without it\'s share of hiccups and headaches. Next weekend - CBC Montreal will be getting members of the public for its first Hackathon.', | |
176 | 'timestamp': 1425704400, | |
177 | 'upload_date': '20150307', | |
178 | 'uploader': 'CBCC-NEW', | |
339c339f | 179 | 'thumbnail': 'http://thumbnails.cbc.ca/maven_legacy/thumbnails/sonali-karnick-220.jpg', |
180 | 'chapters': [], | |
181 | 'duration': 494.811, | |
31a70191 | 182 | }, |
64413f75 | 183 | }, { |
64413f75 | 184 | 'url': 'http://www.cbc.ca/player/play/2164402062', |
c95e2b59 | 185 | 'md5': '33fcd8f6719b9dd60a5e73adcb83b9f6', |
64413f75 | 186 | 'info_dict': { |
187 | 'id': '2164402062', | |
c95e2b59 | 188 | 'ext': 'mp4', |
64413f75 | 189 | 'title': 'Cancer survivor four times over', |
190 | 'description': 'Tim Mayer has beaten three different forms of cancer four times in five years.', | |
191 | 'timestamp': 1320410746, | |
192 | 'upload_date': '20111104', | |
193 | 'uploader': 'CBCC-NEW', | |
339c339f | 194 | 'thumbnail': 'https://thumbnails.cbc.ca/maven_legacy/thumbnails/277/67/cancer_852x480_2164412612.jpg', |
195 | 'chapters': [], | |
196 | 'duration': 186.867, | |
197 | }, | |
198 | }, { | |
199 | # Has subtitles | |
200 | # These broadcasts expire after ~1 month, can find new test URL here: | |
201 | # https://www.cbc.ca/player/news/TV%20Shows/The%20National/Latest%20Broadcast | |
202 | 'url': 'http://www.cbc.ca/player/play/2249992771553', | |
203 | 'md5': '2f2fb675dd4f0f8a5bb7588d1b13bacd', | |
204 | 'info_dict': { | |
205 | 'id': '2249992771553', | |
206 | 'ext': 'mp4', | |
207 | 'title': 'The National | Women’s soccer pay, Florida seawater, Swift quake', | |
208 | 'description': 'md5:adba28011a56cfa47a080ff198dad27a', | |
209 | 'timestamp': 1690596000, | |
210 | 'duration': 2716.333, | |
211 | 'subtitles': {'eng': [{'ext': 'vtt', 'protocol': 'm3u8_native'}]}, | |
212 | 'thumbnail': 'https://thumbnails.cbc.ca/maven_legacy/thumbnails/481/326/thumbnail.jpeg', | |
213 | 'uploader': 'CBCC-NEW', | |
214 | 'chapters': 'count:5', | |
215 | 'upload_date': '20230729', | |
64413f75 | 216 | }, |
31a70191 | 217 | }] |
8b85ac3f | 218 | |
219 | def _real_extract(self, url): | |
220 | video_id = self._match_id(url) | |
52f7c75c | 221 | return { |
222 | '_type': 'url_transparent', | |
223 | 'ie_key': 'ThePlatform', | |
224 | 'url': smuggle_url( | |
64413f75 | 225 | 'http://link.theplatform.com/s/ExhSPC/media/guid/2655402169/%s?mbr=true&formats=MPEG4,FLV,MP3' % video_id, { |
52f7c75c | 226 | 'force_smil_url': True |
227 | }), | |
228 | 'id': video_id, | |
339c339f | 229 | '_format_sort_fields': ('res', 'proto') # Prioritize direct http formats over HLS |
52f7c75c | 230 | } |
30afe4ae RA |
231 | |
232 | ||
ed711897 | 233 | class CBCPlayerPlaylistIE(InfoExtractor): |
234 | IE_NAME = 'cbc.ca:player:playlist' | |
235 | _VALID_URL = r'https?://(?:www\.)?cbc\.ca/(?:player/)(?!play/)(?P<id>[^?#]+)' | |
236 | _TESTS = [{ | |
237 | 'url': 'https://www.cbc.ca/player/news/TV%20Shows/The%20National/Latest%20Broadcast', | |
238 | 'playlist_mincount': 25, | |
239 | 'info_dict': { | |
240 | 'id': 'news/tv shows/the national/latest broadcast', | |
241 | } | |
242 | }, { | |
243 | 'url': 'https://www.cbc.ca/player/news/Canada/North', | |
244 | 'playlist_mincount': 25, | |
245 | 'info_dict': { | |
246 | 'id': 'news/canada/north', | |
247 | } | |
248 | }] | |
249 | ||
250 | def _real_extract(self, url): | |
251 | playlist_id = urllib.parse.unquote(self._match_id(url)).lower() | |
252 | webpage = self._download_webpage(url, playlist_id) | |
253 | json_content = self._search_json( | |
254 | r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', playlist_id) | |
255 | ||
256 | def entries(): | |
257 | for video_id in traverse_obj(json_content, ( | |
258 | 'video', 'clipsByCategory', lambda k, _: k.lower() == playlist_id, 'items', ..., 'id' | |
259 | )): | |
260 | yield self.url_result(f'https://www.cbc.ca/player/play/{video_id}', CBCPlayerIE) | |
261 | ||
262 | return self.playlist_result(entries(), playlist_id) | |
263 | ||
264 | ||
0d32e124 | 265 | class CBCGemIE(InfoExtractor): |
266 | IE_NAME = 'gem.cbc.ca' | |
871c9074 | 267 | _VALID_URL = r'https?://gem\.cbc\.ca/(?:media/)?(?P<id>[0-9a-z-]+/s[0-9]+[a-z][0-9]+)' |
0d32e124 | 268 | _TESTS = [{ |
0d32e124 | 269 | # This is a normal, public, TV show video |
270 | 'url': 'https://gem.cbc.ca/media/schitts-creek/s06e01', | |
271 | 'md5': '93dbb31c74a8e45b378cf13bd3f6f11e', | |
272 | 'info_dict': { | |
273 | 'id': 'schitts-creek/s06e01', | |
274 | 'ext': 'mp4', | |
275 | 'title': 'Smoke Signals', | |
276 | 'description': 'md5:929868d20021c924020641769eb3e7f1', | |
277 | 'thumbnail': 'https://images.radio-canada.ca/v1/synps-cbc/episode/perso/cbc_schitts_creek_season_06e01_thumbnail_v01.jpg?im=Resize=(Size)', | |
278 | 'duration': 1314, | |
279 | 'categories': ['comedy'], | |
280 | 'series': 'Schitt\'s Creek', | |
281 | 'season': 'Season 6', | |
282 | 'season_number': 6, | |
283 | 'episode': 'Smoke Signals', | |
284 | 'episode_number': 1, | |
285 | 'episode_id': 'schitts-creek/s06e01', | |
286 | }, | |
287 | 'params': {'format': 'bv'}, | |
288 | 'skip': 'Geo-restricted to Canada', | |
289 | }, { | |
0d32e124 | 290 | # This video requires an account in the browser, but works fine in yt-dlp |
291 | 'url': 'https://gem.cbc.ca/media/schitts-creek/s01e01', | |
292 | 'md5': '297a9600f554f2258aed01514226a697', | |
293 | 'info_dict': { | |
294 | 'id': 'schitts-creek/s01e01', | |
295 | 'ext': 'mp4', | |
296 | 'title': 'The Cup Runneth Over', | |
297 | 'description': 'md5:9bca14ea49ab808097530eb05a29e797', | |
298 | 'thumbnail': 'https://images.radio-canada.ca/v1/synps-cbc/episode/perso/cbc_schitts_creek_season_01e01_thumbnail_v01.jpg?im=Resize=(Size)', | |
299 | 'series': 'Schitt\'s Creek', | |
300 | 'season_number': 1, | |
301 | 'season': 'Season 1', | |
302 | 'episode_number': 1, | |
303 | 'episode': 'The Cup Runneth Over', | |
304 | 'episode_id': 'schitts-creek/s01e01', | |
305 | 'duration': 1309, | |
306 | 'categories': ['comedy'], | |
307 | }, | |
308 | 'params': {'format': 'bv'}, | |
309 | 'skip': 'Geo-restricted to Canada', | |
871c9074 | 310 | }, { |
311 | 'url': 'https://gem.cbc.ca/nadiyas-family-favourites/s01e01', | |
312 | 'only_matching': True, | |
0d32e124 | 313 | }] |
d183af3c | 314 | |
315 | _GEO_COUNTRIES = ['CA'] | |
316 | _TOKEN_API_KEY = '3f4beddd-2061-49b0-ae80-6f1f2ed65b37' | |
317 | _NETRC_MACHINE = 'cbcgem' | |
318 | _claims_token = None | |
319 | ||
320 | def _new_claims_token(self, email, password): | |
321 | data = json.dumps({ | |
322 | 'email': email, | |
323 | 'password': password, | |
324 | }).encode() | |
325 | headers = {'content-type': 'application/json'} | |
326 | query = {'apikey': self._TOKEN_API_KEY} | |
327 | resp = self._download_json('https://api.loginradius.com/identity/v2/auth/login', | |
328 | None, data=data, headers=headers, query=query) | |
329 | access_token = resp['access_token'] | |
330 | ||
331 | query = { | |
332 | 'access_token': access_token, | |
333 | 'apikey': self._TOKEN_API_KEY, | |
334 | 'jwtapp': 'jwt', | |
335 | } | |
336 | resp = self._download_json('https://cloud-api.loginradius.com/sso/jwt/api/token', | |
337 | None, headers=headers, query=query) | |
338 | sig = resp['signature'] | |
339 | ||
340 | data = json.dumps({'jwt': sig}).encode() | |
341 | headers = {'content-type': 'application/json', 'ott-device-type': 'web'} | |
342 | resp = self._download_json('https://services.radio-canada.ca/ott/cbc-api/v2/token', | |
9bf14be7 | 343 | None, data=data, headers=headers, expected_status=426) |
d183af3c | 344 | cbc_access_token = resp['accessToken'] |
345 | ||
346 | headers = {'content-type': 'application/json', 'ott-device-type': 'web', 'ott-access-token': cbc_access_token} | |
347 | resp = self._download_json('https://services.radio-canada.ca/ott/cbc-api/v2/profile', | |
9bf14be7 | 348 | None, headers=headers, expected_status=426) |
d183af3c | 349 | return resp['claimsToken'] |
350 | ||
351 | def _get_claims_token_expiry(self): | |
352 | # Token is a JWT | |
353 | # JWT is decoded here and 'exp' field is extracted | |
354 | # It is a Unix timestamp for when the token expires | |
355 | b64_data = self._claims_token.split('.')[1] | |
356 | data = base64.urlsafe_b64decode(b64_data + "==") | |
357 | return json.loads(data)['exp'] | |
358 | ||
359 | def claims_token_expired(self): | |
360 | exp = self._get_claims_token_expiry() | |
361 | if exp - time.time() < 10: | |
362 | # It will expire in less than 10 seconds, or has already expired | |
363 | return True | |
364 | return False | |
365 | ||
366 | def claims_token_valid(self): | |
367 | return self._claims_token is not None and not self.claims_token_expired() | |
368 | ||
369 | def _get_claims_token(self, email, password): | |
370 | if not self.claims_token_valid(): | |
371 | self._claims_token = self._new_claims_token(email, password) | |
9809740b | 372 | self.cache.store(self._NETRC_MACHINE, 'claims_token', self._claims_token) |
d183af3c | 373 | return self._claims_token |
374 | ||
375 | def _real_initialize(self): | |
376 | if self.claims_token_valid(): | |
377 | return | |
9809740b | 378 | self._claims_token = self.cache.load(self._NETRC_MACHINE, 'claims_token') |
30afe4ae | 379 | |
54c2521c DS |
380 | def _find_secret_formats(self, formats, video_id): |
381 | """ Find a valid video url and convert it to the secret variant """ | |
382 | base_format = next((f for f in formats if f.get('vcodec') != 'none'), None) | |
383 | if not base_format: | |
384 | return | |
385 | ||
386 | base_url = re.sub(r'(Manifest\(.*?),filter=[\w-]+(.*?\))', r'\1\2', base_format['url']) | |
387 | url = re.sub(r'(Manifest\(.*?),format=[\w-]+(.*?\))', r'\1\2', base_url) | |
388 | ||
389 | secret_xml = self._download_xml(url, video_id, note='Downloading secret XML', fatal=False) | |
390 | if not secret_xml: | |
391 | return | |
392 | ||
393 | for child in secret_xml: | |
394 | if child.attrib.get('Type') != 'video': | |
395 | continue | |
396 | for video_quality in child: | |
397 | bitrate = int_or_none(video_quality.attrib.get('Bitrate')) | |
398 | if not bitrate or 'Index' not in video_quality.attrib: | |
399 | continue | |
400 | height = int_or_none(video_quality.attrib.get('MaxHeight')) | |
401 | ||
402 | yield { | |
403 | **base_format, | |
404 | 'format_id': join_nonempty('sec', height), | |
332da56f | 405 | # Note: \g<1> is necessary instead of \1 since bitrate is a number |
406 | 'url': re.sub(r'(QualityLevels\()\d+(\))', fr'\g<1>{bitrate}\2', base_url), | |
54c2521c DS |
407 | 'width': int_or_none(video_quality.attrib.get('MaxWidth')), |
408 | 'tbr': bitrate / 1000.0, | |
409 | 'height': height, | |
410 | } | |
411 | ||
30afe4ae RA |
412 | def _real_extract(self, url): |
413 | video_id = self._match_id(url) | |
4afb208c | 414 | video_info = self._download_json( |
415 | f'https://services.radio-canada.ca/ott/cbc-api/v2/assets/{video_id}', | |
416 | video_id, expected_status=426) | |
d183af3c | 417 | |
418 | email, password = self._get_login_info() | |
419 | if email and password: | |
420 | claims_token = self._get_claims_token(email, password) | |
421 | headers = {'x-claims-token': claims_token} | |
422 | else: | |
423 | headers = {} | |
424 | m3u8_info = self._download_json(video_info['playSession']['url'], video_id, headers=headers) | |
425 | m3u8_url = m3u8_info.get('url') | |
0d32e124 | 426 | |
d183af3c | 427 | if m3u8_info.get('errorCode') == 1: |
428 | self.raise_geo_restricted(countries=['CA']) | |
429 | elif m3u8_info.get('errorCode') == 35: | |
430 | self.raise_login_required(method='password') | |
431 | elif m3u8_info.get('errorCode') != 0: | |
432 | raise ExtractorError(f'{self.IE_NAME} said: {m3u8_info.get("errorCode")} - {m3u8_info.get("message")}') | |
0d32e124 | 433 | |
434 | formats = self._extract_m3u8_formats(m3u8_url, video_id, m3u8_id='hls') | |
435 | self._remove_duplicate_formats(formats) | |
54c2521c | 436 | formats.extend(self._find_secret_formats(formats, video_id)) |
0d32e124 | 437 | |
d183af3c | 438 | for format in formats: |
0d32e124 | 439 | if format.get('vcodec') == 'none': |
440 | if format.get('ext') is None: | |
441 | format['ext'] = 'm4a' | |
442 | if format.get('acodec') is None: | |
443 | format['acodec'] = 'mp4a.40.2' | |
444 | ||
445 | # Put described audio at the beginning of the list, so that it | |
446 | # isn't chosen by default, as most people won't want it. | |
447 | if 'descriptive' in format['format_id'].lower(): | |
448 | format['preference'] = -2 | |
449 | ||
0d32e124 | 450 | return { |
30afe4ae | 451 | 'id': video_id, |
0d32e124 | 452 | 'title': video_info['title'], |
453 | 'description': video_info.get('description'), | |
454 | 'thumbnail': video_info.get('image'), | |
455 | 'series': video_info.get('series'), | |
456 | 'season_number': video_info.get('season'), | |
457 | 'season': f'Season {video_info.get("season")}', | |
458 | 'episode_number': video_info.get('episode'), | |
459 | 'episode': video_info.get('title'), | |
460 | 'episode_id': video_id, | |
461 | 'duration': video_info.get('duration'), | |
462 | 'categories': [video_info.get('category')], | |
30afe4ae | 463 | 'formats': formats, |
0d32e124 | 464 | 'release_timestamp': video_info.get('airDate'), |
465 | 'timestamp': video_info.get('availableDate'), | |
30afe4ae RA |
466 | } |
467 | ||
30afe4ae | 468 | |
0d32e124 | 469 | class CBCGemPlaylistIE(InfoExtractor): |
470 | IE_NAME = 'gem.cbc.ca:playlist' | |
7a7b1376 | 471 | _VALID_URL = r'https?://gem\.cbc\.ca/(?:media/)?(?P<id>(?P<show>[0-9a-z-]+)/s(?P<season>[0-9]+))/?(?:[?#]|$)' |
30afe4ae | 472 | _TESTS = [{ |
0d32e124 | 473 | # TV show playlist, all public videos |
474 | 'url': 'https://gem.cbc.ca/media/schitts-creek/s06', | |
475 | 'playlist_count': 16, | |
30afe4ae | 476 | 'info_dict': { |
0d32e124 | 477 | 'id': 'schitts-creek/s06', |
478 | 'title': 'Season 6', | |
479 | 'description': 'md5:6a92104a56cbeb5818cc47884d4326a2', | |
19c90e40 | 480 | 'series': 'Schitt\'s Creek', |
481 | 'season_number': 6, | |
482 | 'season': 'Season 6', | |
483 | 'thumbnail': 'https://images.radio-canada.ca/v1/synps-cbc/season/perso/cbc_schitts_creek_season_06_carousel_v03.jpg?impolicy=ott&im=Resize=(_Size_)&quality=75', | |
30afe4ae | 484 | }, |
7a7b1376 | 485 | }, { |
486 | 'url': 'https://gem.cbc.ca/schitts-creek/s06', | |
487 | 'only_matching': True, | |
30afe4ae | 488 | }] |
0d32e124 | 489 | _API_BASE = 'https://services.radio-canada.ca/ott/cbc-api/v2/shows/' |
30afe4ae RA |
490 | |
491 | def _real_extract(self, url): | |
0d32e124 | 492 | match = self._match_valid_url(url) |
493 | season_id = match.group('id') | |
494 | show = match.group('show') | |
4afb208c | 495 | show_info = self._download_json(self._API_BASE + show, season_id, expected_status=426) |
0d32e124 | 496 | season = int(match.group('season')) |
013ae2e5 | 497 | |
498 | season_info = next((s for s in show_info['seasons'] if s.get('season') == season), None) | |
0d32e124 | 499 | |
500 | if season_info is None: | |
501 | raise ExtractorError(f'Couldn\'t find season {season} of {show}') | |
502 | ||
503 | episodes = [] | |
504 | for episode in season_info['assets']: | |
505 | episodes.append({ | |
506 | '_type': 'url_transparent', | |
507 | 'ie_key': 'CBCGem', | |
508 | 'url': 'https://gem.cbc.ca/media/' + episode['id'], | |
509 | 'id': episode['id'], | |
510 | 'title': episode.get('title'), | |
511 | 'description': episode.get('description'), | |
512 | 'thumbnail': episode.get('image'), | |
513 | 'series': episode.get('series'), | |
514 | 'season_number': episode.get('season'), | |
515 | 'season': season_info['title'], | |
516 | 'season_id': season_info.get('id'), | |
517 | 'episode_number': episode.get('episode'), | |
518 | 'episode': episode.get('title'), | |
519 | 'episode_id': episode['id'], | |
520 | 'duration': episode.get('duration'), | |
521 | 'categories': [episode.get('category')], | |
522 | }) | |
b12cf31b | 523 | |
0d32e124 | 524 | thumbnail = None |
525 | tn_uri = season_info.get('image') | |
526 | # the-national was observed to use a "data:image/png;base64" | |
527 | # URI for their 'image' value. The image was 1x1, and is | |
528 | # probably just a placeholder, so it is ignored. | |
529 | if tn_uri is not None and not tn_uri.startswith('data:'): | |
530 | thumbnail = tn_uri | |
b12cf31b | 531 | |
0d32e124 | 532 | return { |
533 | '_type': 'playlist', | |
534 | 'entries': episodes, | |
535 | 'id': season_id, | |
536 | 'title': season_info['title'], | |
537 | 'description': season_info.get('description'), | |
538 | 'thumbnail': thumbnail, | |
539 | 'series': show_info.get('title'), | |
540 | 'season_number': season_info.get('season'), | |
541 | 'season': season_info['title'], | |
542 | } | |
543 | ||
544 | ||
545 | class CBCGemLiveIE(InfoExtractor): | |
546 | IE_NAME = 'gem.cbc.ca:live' | |
7a7b1376 | 547 | _VALID_URL = r'https?://gem\.cbc\.ca/live(?:-event)?/(?P<id>\d+)' |
548 | _TESTS = [ | |
549 | { | |
550 | 'url': 'https://gem.cbc.ca/live/920604739687', | |
551 | 'info_dict': { | |
552 | 'title': 'Ottawa', | |
553 | 'description': 'The live TV channel and local programming from Ottawa', | |
554 | 'thumbnail': 'https://thumbnails.cbc.ca/maven_legacy/thumbnails/CBC_OTT_VMS/Live_Channel_Static_Images/Ottawa_2880x1620.jpg', | |
555 | 'is_live': True, | |
556 | 'id': 'AyqZwxRqh8EH', | |
557 | 'ext': 'mp4', | |
558 | 'timestamp': 1492106160, | |
559 | 'upload_date': '20170413', | |
560 | 'uploader': 'CBCC-NEW', | |
561 | }, | |
562 | 'skip': 'Live might have ended', | |
0d32e124 | 563 | }, |
7a7b1376 | 564 | { |
565 | 'url': 'https://gem.cbc.ca/live/44', | |
566 | 'info_dict': { | |
567 | 'id': '44', | |
568 | 'ext': 'mp4', | |
569 | 'is_live': True, | |
570 | 'title': r're:^Ottawa [0-9\-: ]+', | |
571 | 'description': 'The live TV channel and local programming from Ottawa', | |
572 | 'live_status': 'is_live', | |
573 | 'thumbnail': r're:https://images.gem.cbc.ca/v1/cbc-gem/live/.*' | |
574 | }, | |
575 | 'params': {'skip_download': True}, | |
576 | 'skip': 'Live might have ended', | |
577 | }, | |
578 | { | |
579 | 'url': 'https://gem.cbc.ca/live-event/10835', | |
580 | 'info_dict': { | |
581 | 'id': '10835', | |
582 | 'ext': 'mp4', | |
583 | 'is_live': True, | |
584 | 'title': r're:^The National \| Biden’s trip wraps up, Paltrow testifies, Bird flu [0-9\-: ]+', | |
585 | 'description': 'March 24, 2023 | President Biden’s Ottawa visit ends with big pledges from both countries. Plus, Gwyneth Paltrow testifies in her ski collision trial.', | |
586 | 'live_status': 'is_live', | |
587 | 'thumbnail': r're:https://images.gem.cbc.ca/v1/cbc-gem/live/.*', | |
588 | 'timestamp': 1679706000, | |
589 | 'upload_date': '20230325', | |
590 | }, | |
591 | 'params': {'skip_download': True}, | |
592 | 'skip': 'Live might have ended', | |
593 | } | |
594 | ] | |
b12cf31b RA |
595 | |
596 | def _real_extract(self, url): | |
0d32e124 | 597 | video_id = self._match_id(url) |
7a7b1376 | 598 | webpage = self._download_webpage(url, video_id) |
599 | video_info = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['data'] | |
0d32e124 | 600 | |
7a7b1376 | 601 | # Two types of metadata JSON |
602 | if not video_info.get('formattedIdMedia'): | |
603 | video_info = traverse_obj( | |
604 | video_info, (('freeTv', ('streams', ...)), 'items', lambda _, v: v['key'] == video_id, {dict}), | |
605 | get_all=False, default={}) | |
606 | ||
607 | video_stream_id = video_info.get('formattedIdMedia') | |
608 | if not video_stream_id: | |
3c239332 | 609 | raise ExtractorError('Couldn\'t find video metadata, maybe this livestream is now offline', expected=True) |
b12cf31b | 610 | |
7a7b1376 | 611 | stream_data = self._download_json( |
612 | 'https://services.radio-canada.ca/media/validation/v2/', video_id, query={ | |
613 | 'appCode': 'mpx', | |
614 | 'connectionType': 'hd', | |
615 | 'deviceType': 'ipad', | |
616 | 'idMedia': video_stream_id, | |
617 | 'multibitrate': 'true', | |
618 | 'output': 'json', | |
619 | 'tech': 'hls', | |
620 | 'manifestType': 'desktop', | |
621 | }) | |
622 | ||
b12cf31b RA |
623 | return { |
624 | 'id': video_id, | |
7a7b1376 | 625 | 'formats': self._extract_m3u8_formats(stream_data['url'], video_id, 'mp4', live=True), |
0d32e124 | 626 | 'is_live': True, |
7a7b1376 | 627 | **traverse_obj(video_info, { |
628 | 'title': 'title', | |
629 | 'description': 'description', | |
630 | 'thumbnail': ('images', 'card', 'url'), | |
631 | 'timestamp': ('airDate', {parse_iso8601}), | |
632 | }) | |
b12cf31b | 633 | } |