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