]>
Commit | Line | Data |
---|---|---|
1 | import hashlib | |
2 | import hmac | |
3 | import re | |
4 | import time | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..compat import compat_str | |
8 | from ..utils import ( | |
9 | dict_get, | |
10 | ExtractorError, | |
11 | js_to_json, | |
12 | int_or_none, | |
13 | parse_iso8601, | |
14 | str_or_none, | |
15 | traverse_obj, | |
16 | try_get, | |
17 | unescapeHTML, | |
18 | update_url_query, | |
19 | ) | |
20 | ||
21 | ||
22 | class ABCIE(InfoExtractor): | |
23 | IE_NAME = 'abc.net.au' | |
24 | _VALID_URL = r'https?://(?:www\.)?abc\.net\.au/(?:news|btn)/(?:[^/]+/){1,4}(?P<id>\d{5,})' | |
25 | ||
26 | _TESTS = [{ | |
27 | 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334', | |
28 | 'md5': 'cb3dd03b18455a661071ee1e28344d9f', | |
29 | 'info_dict': { | |
30 | 'id': '5868334', | |
31 | 'ext': 'mp4', | |
32 | 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone', | |
33 | 'description': 'md5:809ad29c67a05f54eb41f2a105693a67', | |
34 | }, | |
35 | 'skip': 'this video has expired', | |
36 | }, { | |
37 | 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326', | |
38 | 'md5': '4ebd61bdc82d9a8b722f64f1f4b4d121', | |
39 | 'info_dict': { | |
40 | 'id': 'NvqvPeNZsHU', | |
41 | 'ext': 'mp4', | |
42 | 'upload_date': '20150816', | |
43 | 'uploader': 'ABC News (Australia)', | |
44 | 'description': 'Government backbencher Warren Entsch introduces a cross-party sponsored bill to legalise same-sex marriage, saying the bill is designed to promote "an inclusive Australia, not a divided one.". Read more here: http://ab.co/1Mwc6ef', | |
45 | 'uploader_id': 'NewsOnABC', | |
46 | 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill', | |
47 | }, | |
48 | 'add_ie': ['Youtube'], | |
49 | 'skip': 'Not accessible from Travis CI server', | |
50 | }, { | |
51 | 'url': 'http://www.abc.net.au/news/2015-10-23/nab-lifts-interest-rates-following-westpac-and-cba/6880080', | |
52 | 'md5': 'b96eee7c9edf4fc5a358a0252881cc1f', | |
53 | 'info_dict': { | |
54 | 'id': '6880080', | |
55 | 'ext': 'mp3', | |
56 | 'title': 'NAB lifts interest rates, following Westpac and CBA', | |
57 | 'description': 'md5:f13d8edc81e462fce4a0437c7dc04728', | |
58 | }, | |
59 | }, { | |
60 | 'url': 'http://www.abc.net.au/news/2015-10-19/6866214', | |
61 | 'only_matching': True, | |
62 | }, { | |
63 | 'url': 'https://www.abc.net.au/btn/classroom/wwi-centenary/10527914', | |
64 | 'info_dict': { | |
65 | 'id': '10527914', | |
66 | 'ext': 'mp4', | |
67 | 'title': 'WWI Centenary', | |
68 | 'description': 'md5:c2379ec0ca84072e86b446e536954546', | |
69 | } | |
70 | }, { | |
71 | 'url': 'https://www.abc.net.au/news/programs/the-world/2020-06-10/black-lives-matter-protests-spawn-support-for/12342074', | |
72 | 'info_dict': { | |
73 | 'id': '12342074', | |
74 | 'ext': 'mp4', | |
75 | 'title': 'Black Lives Matter protests spawn support for Papuans in Indonesia', | |
76 | 'description': 'md5:2961a17dc53abc558589ccd0fb8edd6f', | |
77 | } | |
78 | }, { | |
79 | 'url': 'https://www.abc.net.au/btn/newsbreak/btn-newsbreak-20200814/12560476', | |
80 | 'info_dict': { | |
81 | 'id': 'tDL8Ld4dK_8', | |
82 | 'ext': 'mp4', | |
83 | 'title': 'Fortnite Banned From Apple and Google App Stores', | |
84 | 'description': 'md5:a6df3f36ce8f816b74af4bd6462f5651', | |
85 | 'upload_date': '20200813', | |
86 | 'uploader': 'Behind the News', | |
87 | 'uploader_id': 'behindthenews', | |
88 | } | |
89 | }, { | |
90 | 'url': 'https://www.abc.net.au/news/2023-06-25/wagner-boss-orders-troops-back-to-bases-to-avoid-bloodshed/102520540', | |
91 | 'info_dict': { | |
92 | 'id': '102520540', | |
93 | 'title': 'Wagner Group retreating from Russia, leader Prigozhin to move to Belarus', | |
94 | 'ext': 'mp4', | |
95 | 'description': 'Wagner troops leave Rostov-on-Don and\xa0Yevgeny Prigozhin will move to Belarus under a deal brokered by Belarusian President Alexander Lukashenko to end the mutiny.', | |
96 | 'thumbnail': 'https://live-production.wcms.abc-cdn.net.au/0c170f5b57f0105c432f366c0e8e267b?impolicy=wcms_crop_resize&cropH=2813&cropW=5000&xPos=0&yPos=249&width=862&height=485', | |
97 | } | |
98 | }] | |
99 | ||
100 | def _real_extract(self, url): | |
101 | video_id = self._match_id(url) | |
102 | webpage = self._download_webpage(url, video_id) | |
103 | ||
104 | mobj = re.search(r'<a\s+href="(?P<url>[^"]+)"\s+data-duration="\d+"\s+title="Download audio directly">', webpage) | |
105 | if mobj: | |
106 | urls_info = mobj.groupdict() | |
107 | youtube = False | |
108 | video = False | |
109 | else: | |
110 | mobj = re.search(r'<a href="(?P<url>http://www\.youtube\.com/watch\?v=[^"]+)"><span><strong>External Link:</strong>', | |
111 | webpage) | |
112 | if mobj is None: | |
113 | mobj = re.search(r'<iframe width="100%" src="(?P<url>//www\.youtube-nocookie\.com/embed/[^?"]+)', webpage) | |
114 | if mobj: | |
115 | urls_info = mobj.groupdict() | |
116 | youtube = True | |
117 | video = True | |
118 | ||
119 | if mobj is None: | |
120 | mobj = re.search(r'(?P<type>)"(?:sources|files|renditions)":\s*(?P<json_data>\[[^\]]+\])', webpage) | |
121 | if mobj is None: | |
122 | mobj = re.search( | |
123 | r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);', | |
124 | webpage) | |
125 | if mobj is None: | |
126 | expired = self._html_search_regex(r'(?s)class="expired-(?:video|audio)".+?<span>(.+?)</span>', webpage, 'expired', None) | |
127 | if expired: | |
128 | raise ExtractorError('%s said: %s' % (self.IE_NAME, expired), expected=True) | |
129 | raise ExtractorError('Unable to extract video urls') | |
130 | ||
131 | urls_info = self._parse_json( | |
132 | mobj.group('json_data'), video_id, transform_source=js_to_json) | |
133 | youtube = mobj.group('type') == 'YouTube' | |
134 | video = mobj.group('type') == 'Video' or traverse_obj( | |
135 | urls_info, (0, ('contentType', 'MIMEType')), get_all=False) == 'video/mp4' | |
136 | ||
137 | if not isinstance(urls_info, list): | |
138 | urls_info = [urls_info] | |
139 | ||
140 | if youtube: | |
141 | return self.playlist_result([ | |
142 | self.url_result(url_info['url']) for url_info in urls_info]) | |
143 | ||
144 | formats = [] | |
145 | for url_info in urls_info: | |
146 | height = int_or_none(url_info.get('height')) | |
147 | bitrate = int_or_none(url_info.get('bitrate')) | |
148 | width = int_or_none(url_info.get('width')) | |
149 | format_id = None | |
150 | mobj = re.search(r'_(?:(?P<height>\d+)|(?P<bitrate>\d+)k)\.mp4$', url_info['url']) | |
151 | if mobj: | |
152 | height_from_url = mobj.group('height') | |
153 | if height_from_url: | |
154 | height = height or int_or_none(height_from_url) | |
155 | width = width or int_or_none(url_info.get('label')) | |
156 | else: | |
157 | bitrate = bitrate or int_or_none(mobj.group('bitrate')) | |
158 | format_id = str_or_none(url_info.get('label')) | |
159 | formats.append({ | |
160 | 'url': url_info['url'], | |
161 | 'vcodec': url_info.get('codec') if video else 'none', | |
162 | 'width': width, | |
163 | 'height': height, | |
164 | 'tbr': bitrate, | |
165 | 'filesize': int_or_none(url_info.get('filesize')), | |
166 | 'format_id': format_id | |
167 | }) | |
168 | ||
169 | return { | |
170 | 'id': video_id, | |
171 | 'title': self._og_search_title(webpage), | |
172 | 'formats': formats, | |
173 | 'description': self._og_search_description(webpage), | |
174 | 'thumbnail': self._og_search_thumbnail(webpage), | |
175 | } | |
176 | ||
177 | ||
178 | class ABCIViewIE(InfoExtractor): | |
179 | IE_NAME = 'abc.net.au:iview' | |
180 | _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*video/(?P<id>[^/?#]+)' | |
181 | _GEO_COUNTRIES = ['AU'] | |
182 | ||
183 | _TESTS = [{ | |
184 | 'url': 'https://iview.abc.net.au/show/utopia/series/1/video/CO1211V001S00', | |
185 | 'md5': '52a942bfd7a0b79a6bfe9b4ce6c9d0ed', | |
186 | 'info_dict': { | |
187 | 'id': 'CO1211V001S00', | |
188 | 'ext': 'mp4', | |
189 | 'title': 'Series 1 Ep 1 Wood For The Trees', | |
190 | 'series': 'Utopia', | |
191 | 'description': 'md5:0cfb2c183c1b952d1548fd65c8a95c00', | |
192 | 'upload_date': '20230726', | |
193 | 'uploader_id': 'abc1', | |
194 | 'series_id': 'CO1211V', | |
195 | 'episode_id': 'CO1211V001S00', | |
196 | 'season_number': 1, | |
197 | 'season': 'Season 1', | |
198 | 'episode_number': 1, | |
199 | 'episode': 'Wood For The Trees', | |
200 | 'thumbnail': 'https://cdn.iview.abc.net.au/thumbs/i/co/CO1211V001S00_5ad8353f4df09_1280.jpg', | |
201 | 'timestamp': 1690403700, | |
202 | }, | |
203 | 'params': { | |
204 | 'skip_download': True, | |
205 | }, | |
206 | }, { | |
207 | 'note': 'No episode name', | |
208 | 'url': 'https://iview.abc.net.au/show/gruen/series/11/video/LE1927H001S00', | |
209 | 'md5': '67715ce3c78426b11ba167d875ac6abf', | |
210 | 'info_dict': { | |
211 | 'id': 'LE1927H001S00', | |
212 | 'ext': 'mp4', | |
213 | 'title': 'Series 11 Ep 1', | |
214 | 'series': 'Gruen', | |
215 | 'description': 'md5:52cc744ad35045baf6aded2ce7287f67', | |
216 | 'upload_date': '20190925', | |
217 | 'uploader_id': 'abc1', | |
218 | 'series_id': 'LE1927H', | |
219 | 'episode_id': 'LE1927H001S00', | |
220 | 'season_number': 11, | |
221 | 'season': 'Season 11', | |
222 | 'episode_number': 1, | |
223 | 'episode': 'Episode 1', | |
224 | 'thumbnail': 'https://cdn.iview.abc.net.au/thumbs/i/le/LE1927H001S00_5d954fbd79e25_1280.jpg', | |
225 | 'timestamp': 1569445289, | |
226 | }, | |
227 | 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'], | |
228 | 'params': { | |
229 | 'skip_download': True, | |
230 | }, | |
231 | }, { | |
232 | 'note': 'No episode number', | |
233 | 'url': 'https://iview.abc.net.au/show/four-corners/series/2022/video/NC2203H039S00', | |
234 | 'md5': '77cb7d8434440e3b28fbebe331c2456a', | |
235 | 'info_dict': { | |
236 | 'id': 'NC2203H039S00', | |
237 | 'ext': 'mp4', | |
238 | 'title': 'Series 2022 Locking Up Kids', | |
239 | 'series': 'Four Corners', | |
240 | 'description': 'md5:54829ca108846d1a70e1fcce2853e720', | |
241 | 'upload_date': '20221114', | |
242 | 'uploader_id': 'abc1', | |
243 | 'series_id': 'NC2203H', | |
244 | 'episode_id': 'NC2203H039S00', | |
245 | 'season_number': 2022, | |
246 | 'season': 'Season 2022', | |
247 | 'episode_number': None, | |
248 | 'episode': 'Locking Up Kids', | |
249 | 'thumbnail': 'https://cdn.iview.abc.net.au/thumbs/i/nc/NC2203H039S00_636d8a0944a22_1920.jpg', | |
250 | 'timestamp': 1668460497, | |
251 | ||
252 | }, | |
253 | 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'], | |
254 | 'params': { | |
255 | 'skip_download': True, | |
256 | }, | |
257 | }, { | |
258 | 'note': 'No episode name or number', | |
259 | 'url': 'https://iview.abc.net.au/show/landline/series/2021/video/RF2004Q043S00', | |
260 | 'md5': '2e17dec06b13cc81dc119d2565289396', | |
261 | 'info_dict': { | |
262 | 'id': 'RF2004Q043S00', | |
263 | 'ext': 'mp4', | |
264 | 'title': 'Series 2021', | |
265 | 'series': 'Landline', | |
266 | 'description': 'md5:c9f30d9c0c914a7fd23842f6240be014', | |
267 | 'upload_date': '20211205', | |
268 | 'uploader_id': 'abc1', | |
269 | 'series_id': 'RF2004Q', | |
270 | 'episode_id': 'RF2004Q043S00', | |
271 | 'season_number': 2021, | |
272 | 'season': 'Season 2021', | |
273 | 'episode_number': None, | |
274 | 'episode': None, | |
275 | 'thumbnail': 'https://cdn.iview.abc.net.au/thumbs/i/rf/RF2004Q043S00_61a950639dbc0_1920.jpg', | |
276 | 'timestamp': 1638710705, | |
277 | ||
278 | }, | |
279 | 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'], | |
280 | 'params': { | |
281 | 'skip_download': True, | |
282 | }, | |
283 | }] | |
284 | ||
285 | def _real_extract(self, url): | |
286 | video_id = self._match_id(url) | |
287 | video_params = self._download_json( | |
288 | 'https://iview.abc.net.au/api/programs/' + video_id, video_id) | |
289 | title = unescapeHTML(video_params.get('title') or video_params['seriesTitle']) | |
290 | stream = next(s for s in video_params['playlist'] if s.get('type') in ('program', 'livestream')) | |
291 | ||
292 | house_number = video_params.get('episodeHouseNumber') or video_id | |
293 | path = '/auth/hls/sign?ts={0}&hn={1}&d=android-tablet'.format( | |
294 | int(time.time()), house_number) | |
295 | sig = hmac.new( | |
296 | b'android.content.res.Resources', | |
297 | path.encode('utf-8'), hashlib.sha256).hexdigest() | |
298 | token = self._download_webpage( | |
299 | 'http://iview.abc.net.au{0}&sig={1}'.format(path, sig), video_id) | |
300 | ||
301 | def tokenize_url(url, token): | |
302 | return update_url_query(url, { | |
303 | 'hdnea': token, | |
304 | }) | |
305 | ||
306 | for sd in ('1080', '720', 'sd', 'sd-low'): | |
307 | sd_url = try_get( | |
308 | stream, lambda x: x['streams']['hls'][sd], compat_str) | |
309 | if not sd_url: | |
310 | continue | |
311 | formats = self._extract_m3u8_formats( | |
312 | tokenize_url(sd_url, token), video_id, 'mp4', | |
313 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False) | |
314 | if formats: | |
315 | break | |
316 | ||
317 | subtitles = {} | |
318 | src_vtt = stream.get('captions', {}).get('src-vtt') | |
319 | if src_vtt: | |
320 | subtitles['en'] = [{ | |
321 | 'url': src_vtt, | |
322 | 'ext': 'vtt', | |
323 | }] | |
324 | ||
325 | is_live = video_params.get('livestream') == '1' | |
326 | ||
327 | return { | |
328 | 'id': video_id, | |
329 | 'title': title, | |
330 | 'description': video_params.get('description'), | |
331 | 'thumbnail': video_params.get('thumbnail'), | |
332 | 'duration': int_or_none(video_params.get('eventDuration')), | |
333 | 'timestamp': parse_iso8601(video_params.get('pubDate'), ' '), | |
334 | 'series': unescapeHTML(video_params.get('seriesTitle')), | |
335 | 'series_id': video_params.get('seriesHouseNumber') or video_id[:7], | |
336 | 'season_number': int_or_none(self._search_regex( | |
337 | r'\bSeries\s+(\d+)\b', title, 'season number', default=None)), | |
338 | 'episode_number': int_or_none(self._search_regex( | |
339 | r'\bEp\s+(\d+)\b', title, 'episode number', default=None)), | |
340 | 'episode_id': house_number, | |
341 | 'episode': self._search_regex( | |
342 | r'^(?:Series\s+\d+)?\s*(?:Ep\s+\d+)?\s*(.*)$', title, 'episode', default='') or None, | |
343 | 'uploader_id': video_params.get('channel'), | |
344 | 'formats': formats, | |
345 | 'subtitles': subtitles, | |
346 | 'is_live': is_live, | |
347 | } | |
348 | ||
349 | ||
350 | class ABCIViewShowSeriesIE(InfoExtractor): | |
351 | IE_NAME = 'abc.net.au:iview:showseries' | |
352 | _VALID_URL = r'https?://iview\.abc\.net\.au/show/(?P<id>[^/]+)(?:/series/\d+)?$' | |
353 | _GEO_COUNTRIES = ['AU'] | |
354 | ||
355 | _TESTS = [{ | |
356 | 'url': 'https://iview.abc.net.au/show/upper-middle-bogan', | |
357 | 'info_dict': { | |
358 | 'id': '124870-1', | |
359 | 'title': 'Series 1', | |
360 | 'description': 'md5:93119346c24a7c322d446d8eece430ff', | |
361 | 'series': 'Upper Middle Bogan', | |
362 | 'season': 'Series 1', | |
363 | 'thumbnail': r're:^https?://cdn\.iview\.abc\.net\.au/thumbs/.*\.jpg$' | |
364 | }, | |
365 | 'playlist_count': 8, | |
366 | }, { | |
367 | 'url': 'https://iview.abc.net.au/show/upper-middle-bogan', | |
368 | 'info_dict': { | |
369 | 'id': 'CO1108V001S00', | |
370 | 'ext': 'mp4', | |
371 | 'title': 'Series 1 Ep 1 I\'m A Swan', | |
372 | 'description': 'md5:7b676758c1de11a30b79b4d301e8da93', | |
373 | 'series': 'Upper Middle Bogan', | |
374 | 'uploader_id': 'abc1', | |
375 | 'upload_date': '20210630', | |
376 | 'timestamp': 1625036400, | |
377 | }, | |
378 | 'params': { | |
379 | 'noplaylist': True, | |
380 | 'skip_download': 'm3u8', | |
381 | }, | |
382 | }] | |
383 | ||
384 | def _real_extract(self, url): | |
385 | show_id = self._match_id(url) | |
386 | webpage = self._download_webpage(url, show_id) | |
387 | webpage_data = self._search_regex( | |
388 | r'window\.__INITIAL_STATE__\s*=\s*[\'"](.+?)[\'"]\s*;', | |
389 | webpage, 'initial state') | |
390 | video_data = self._parse_json( | |
391 | unescapeHTML(webpage_data).encode('utf-8').decode('unicode_escape'), show_id) | |
392 | video_data = video_data['route']['pageData']['_embedded'] | |
393 | ||
394 | highlight = try_get(video_data, lambda x: x['highlightVideo']['shareUrl']) | |
395 | if not self._yes_playlist(show_id, bool(highlight), video_label='highlight video'): | |
396 | return self.url_result(highlight, ie=ABCIViewIE.ie_key()) | |
397 | ||
398 | series = video_data['selectedSeries'] | |
399 | return { | |
400 | '_type': 'playlist', | |
401 | 'entries': [self.url_result(episode['shareUrl']) | |
402 | for episode in series['_embedded']['videoEpisodes']], | |
403 | 'id': series.get('id'), | |
404 | 'title': dict_get(series, ('title', 'displaySubtitle')), | |
405 | 'description': series.get('description'), | |
406 | 'series': dict_get(series, ('showTitle', 'displayTitle')), | |
407 | 'season': dict_get(series, ('title', 'displaySubtitle')), | |
408 | 'thumbnail': series.get('thumbnail'), | |
409 | } |