]>
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, |
17a64763 | 19 | ) |
64ce58db JMF |
20 | |
21 | ||
22 | class ABCIE(InfoExtractor): | |
23 | IE_NAME = 'abc.net.au' | |
5630d797 | 24 | _VALID_URL = r'https?://(?:www\.)?abc\.net\.au/(?:news|btn)/(?:[^/]+/){1,4}(?P<id>\d{5,})' |
64ce58db | 25 | |
17a64763 | 26 | _TESTS = [{ |
732c848c MK |
27 | 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334', |
28 | 'md5': 'cb3dd03b18455a661071ee1e28344d9f', | |
64ce58db | 29 | 'info_dict': { |
732c848c | 30 | 'id': '5868334', |
64ce58db | 31 | 'ext': 'mp4', |
732c848c MK |
32 | 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone', |
33 | 'description': 'md5:809ad29c67a05f54eb41f2a105693a67', | |
64ce58db | 34 | }, |
5c5a3ecf | 35 | 'skip': 'this video has expired', |
17a64763 YCH |
36 | }, { |
37 | 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326', | |
76b01870 | 38 | 'md5': '4ebd61bdc82d9a8b722f64f1f4b4d121', |
17a64763 YCH |
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'], | |
5c5a3ecf | 49 | 'skip': 'Not accessible from Travis CI server', |
7687b354 | 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 | }, | |
d97da29d JMF |
59 | }, { |
60 | 'url': 'http://www.abc.net.au/news/2015-10-19/6866214', | |
61 | 'only_matching': True, | |
5630d797 AH |
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 | } | |
76b01870 AH |
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 | } | |
5630d797 AH |
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 | } | |
8f05fbae XH |
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 | } | |
17a64763 | 98 | }] |
64ce58db JMF |
99 | |
100 | def _real_extract(self, url): | |
ed9266db | 101 | video_id = self._match_id(url) |
64ce58db JMF |
102 | webpage = self._download_webpage(url, video_id) |
103 | ||
76b01870 AH |
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) | |
5630d797 AH |
112 | if mobj is None: |
113 | mobj = re.search(r'<iframe width="100%" src="(?P<url>//www\.youtube-nocookie\.com/embed/[^?"]+)', webpage) | |
76b01870 AH |
114 | if mobj: |
115 | urls_info = mobj.groupdict() | |
116 | youtube = True | |
117 | video = True | |
17a64763 | 118 | |
76b01870 | 119 | if mobj is None: |
8f05fbae | 120 | mobj = re.search(r'(?P<type>)"(?:sources|files|renditions)":\s*(?P<json_data>\[[^\]]+\])', webpage) |
76b01870 AH |
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' | |
8f05fbae XH |
134 | video = mobj.group('type') == 'Video' or traverse_obj( |
135 | urls_info, (0, ('contentType', 'MIMEType')), get_all=False) == 'video/mp4' | |
17a64763 YCH |
136 | |
137 | if not isinstance(urls_info, list): | |
138 | urls_info = [urls_info] | |
139 | ||
76b01870 | 140 | if youtube: |
17a64763 YCH |
141 | return self.playlist_result([ |
142 | self.url_result(url_info['url']) for url_info in urls_info]) | |
143 | ||
76b01870 AH |
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 | }) | |
7687b354 | 168 | |
64ce58db JMF |
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 | } | |
55d119e2 RA |
176 | |
177 | ||
178 | class ABCIViewIE(InfoExtractor): | |
179 | IE_NAME = 'abc.net.au:iview' | |
e0671819 | 180 | _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*video/(?P<id>[^/?#]+)' |
77341dae | 181 | _GEO_COUNTRIES = ['AU'] |
55d119e2 | 182 | |
bfcda07a | 183 | # ABC iview programs are normally available for 14 days only. |
55d119e2 | 184 | _TESTS = [{ |
d6aa1db7 | 185 | 'url': 'https://iview.abc.net.au/show/gruen/series/11/video/LE1927H001S00', |
186 | 'md5': '67715ce3c78426b11ba167d875ac6abf', | |
55d119e2 | 187 | 'info_dict': { |
d6aa1db7 | 188 | 'id': 'LE1927H001S00', |
55d119e2 | 189 | 'ext': 'mp4', |
d6aa1db7 | 190 | 'title': "Series 11 Ep 1", |
191 | 'series': "Gruen", | |
192 | 'description': 'md5:52cc744ad35045baf6aded2ce7287f67', | |
193 | 'upload_date': '20190925', | |
194 | 'uploader_id': 'abc1', | |
195 | 'timestamp': 1569445289, | |
77341dae S |
196 | }, |
197 | 'params': { | |
198 | 'skip_download': True, | |
55d119e2 RA |
199 | }, |
200 | }] | |
201 | ||
202 | def _real_extract(self, url): | |
203 | video_id = self._match_id(url) | |
e0671819 RA |
204 | video_params = self._download_json( |
205 | 'https://iview.abc.net.au/api/programs/' + video_id, video_id) | |
206 | title = unescapeHTML(video_params.get('title') or video_params['seriesTitle']) | |
207 | stream = next(s for s in video_params['playlist'] if s.get('type') in ('program', 'livestream')) | |
55d119e2 | 208 | |
e0671819 RA |
209 | house_number = video_params.get('episodeHouseNumber') or video_id |
210 | path = '/auth/hls/sign?ts={0}&hn={1}&d=android-tablet'.format( | |
77341dae S |
211 | int(time.time()), house_number) |
212 | sig = hmac.new( | |
e0671819 | 213 | b'android.content.res.Resources', |
77341dae S |
214 | path.encode('utf-8'), hashlib.sha256).hexdigest() |
215 | token = self._download_webpage( | |
216 | 'http://iview.abc.net.au{0}&sig={1}'.format(path, sig), video_id) | |
2e65e7db | 217 | |
218 | def tokenize_url(url, token): | |
77341dae S |
219 | return update_url_query(url, { |
220 | 'hdnea': token, | |
221 | }) | |
222 | ||
c15c316b | 223 | for sd in ('1080', '720', 'sd', 'sd-low'): |
77341dae S |
224 | sd_url = try_get( |
225 | stream, lambda x: x['streams']['hls'][sd], compat_str) | |
226 | if not sd_url: | |
227 | continue | |
228 | formats = self._extract_m3u8_formats( | |
229 | tokenize_url(sd_url, token), video_id, 'mp4', | |
230 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False) | |
231 | if formats: | |
232 | break | |
55d119e2 RA |
233 | |
234 | subtitles = {} | |
235 | src_vtt = stream.get('captions', {}).get('src-vtt') | |
236 | if src_vtt: | |
237 | subtitles['en'] = [{ | |
238 | 'url': src_vtt, | |
239 | 'ext': 'vtt', | |
240 | }] | |
241 | ||
e0671819 | 242 | is_live = video_params.get('livestream') == '1' |
e0671819 | 243 | |
55d119e2 RA |
244 | return { |
245 | 'id': video_id, | |
e0671819 RA |
246 | 'title': title, |
247 | 'description': video_params.get('description'), | |
248 | 'thumbnail': video_params.get('thumbnail'), | |
55d119e2 RA |
249 | 'duration': int_or_none(video_params.get('eventDuration')), |
250 | 'timestamp': parse_iso8601(video_params.get('pubDate'), ' '), | |
9e6a4180 | 251 | 'series': unescapeHTML(video_params.get('seriesTitle')), |
55d119e2 | 252 | 'series_id': video_params.get('seriesHouseNumber') or video_id[:7], |
9aca7fe6 S |
253 | 'season_number': int_or_none(self._search_regex( |
254 | r'\bSeries\s+(\d+)\b', title, 'season number', default=None)), | |
255 | 'episode_number': int_or_none(self._search_regex( | |
256 | r'\bEp\s+(\d+)\b', title, 'episode number', default=None)), | |
257 | 'episode_id': house_number, | |
55d119e2 RA |
258 | 'uploader_id': video_params.get('channel'), |
259 | 'formats': formats, | |
260 | 'subtitles': subtitles, | |
e0671819 | 261 | 'is_live': is_live, |
55d119e2 | 262 | } |
6839d02c PW |
263 | |
264 | ||
265 | class ABCIViewShowSeriesIE(InfoExtractor): | |
266 | IE_NAME = 'abc.net.au:iview:showseries' | |
267 | _VALID_URL = r'https?://iview\.abc\.net\.au/show/(?P<id>[^/]+)(?:/series/\d+)?$' | |
268 | _GEO_COUNTRIES = ['AU'] | |
269 | ||
270 | _TESTS = [{ | |
271 | 'url': 'https://iview.abc.net.au/show/upper-middle-bogan', | |
272 | 'info_dict': { | |
273 | 'id': '124870-1', | |
274 | 'title': 'Series 1', | |
275 | 'description': 'md5:93119346c24a7c322d446d8eece430ff', | |
276 | 'series': 'Upper Middle Bogan', | |
277 | 'season': 'Series 1', | |
278 | 'thumbnail': r're:^https?://cdn\.iview\.abc\.net\.au/thumbs/.*\.jpg$' | |
279 | }, | |
280 | 'playlist_count': 8, | |
281 | }, { | |
282 | 'url': 'https://iview.abc.net.au/show/upper-middle-bogan', | |
283 | 'info_dict': { | |
284 | 'id': 'CO1108V001S00', | |
285 | 'ext': 'mp4', | |
286 | 'title': 'Series 1 Ep 1 I\'m A Swan', | |
287 | 'description': 'md5:7b676758c1de11a30b79b4d301e8da93', | |
288 | 'series': 'Upper Middle Bogan', | |
289 | 'uploader_id': 'abc1', | |
290 | 'upload_date': '20210630', | |
291 | 'timestamp': 1625036400, | |
292 | }, | |
293 | 'params': { | |
294 | 'noplaylist': True, | |
295 | 'skip_download': 'm3u8', | |
296 | }, | |
297 | }] | |
298 | ||
299 | def _real_extract(self, url): | |
300 | show_id = self._match_id(url) | |
301 | webpage = self._download_webpage(url, show_id) | |
302 | webpage_data = self._search_regex( | |
303 | r'window\.__INITIAL_STATE__\s*=\s*[\'"](.+?)[\'"]\s*;', | |
304 | webpage, 'initial state') | |
305 | video_data = self._parse_json( | |
306 | unescapeHTML(webpage_data).encode('utf-8').decode('unicode_escape'), show_id) | |
307 | video_data = video_data['route']['pageData']['_embedded'] | |
308 | ||
88f23a18 | 309 | highlight = try_get(video_data, lambda x: x['highlightVideo']['shareUrl']) |
f40ee5e9 | 310 | if not self._yes_playlist(show_id, bool(highlight), video_label='highlight video'): |
311 | return self.url_result(highlight, ie=ABCIViewIE.ie_key()) | |
6839d02c | 312 | |
6839d02c PW |
313 | series = video_data['selectedSeries'] |
314 | return { | |
315 | '_type': 'playlist', | |
316 | 'entries': [self.url_result(episode['shareUrl']) | |
317 | for episode in series['_embedded']['videoEpisodes']], | |
318 | 'id': series.get('id'), | |
319 | 'title': dict_get(series, ('title', 'displaySubtitle')), | |
320 | 'description': series.get('description'), | |
321 | 'series': dict_get(series, ('showTitle', 'displayTitle')), | |
322 | 'season': dict_get(series, ('title', 'displaySubtitle')), | |
323 | 'thumbnail': series.get('thumbnail'), | |
324 | } |