]>
Commit | Line | Data |
---|---|---|
64ce58db JMF |
1 | from __future__ import unicode_literals |
2 | ||
2e65e7db | 3 | import hashlib |
4 | import hmac | |
64ce58db | 5 | import re |
2e65e7db | 6 | import time |
64ce58db JMF |
7 | |
8 | from .common import InfoExtractor | |
58179eb7 | 9 | from ..compat import compat_str |
17a64763 | 10 | from ..utils import ( |
6839d02c | 11 | dict_get, |
17a64763 YCH |
12 | ExtractorError, |
13 | js_to_json, | |
c0a65687 | 14 | int_or_none, |
55d119e2 | 15 | parse_iso8601, |
76b01870 | 16 | str_or_none, |
58179eb7 | 17 | try_get, |
9e6a4180 | 18 | unescapeHTML, |
77341dae | 19 | update_url_query, |
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 | } | |
17a64763 | 90 | }] |
64ce58db JMF |
91 | |
92 | def _real_extract(self, url): | |
ed9266db | 93 | video_id = self._match_id(url) |
64ce58db JMF |
94 | webpage = self._download_webpage(url, video_id) |
95 | ||
76b01870 AH |
96 | mobj = re.search(r'<a\s+href="(?P<url>[^"]+)"\s+data-duration="\d+"\s+title="Download audio directly">', webpage) |
97 | if mobj: | |
98 | urls_info = mobj.groupdict() | |
99 | youtube = False | |
100 | video = False | |
101 | else: | |
102 | mobj = re.search(r'<a href="(?P<url>http://www\.youtube\.com/watch\?v=[^"]+)"><span><strong>External Link:</strong>', | |
103 | webpage) | |
5630d797 AH |
104 | if mobj is None: |
105 | mobj = re.search(r'<iframe width="100%" src="(?P<url>//www\.youtube-nocookie\.com/embed/[^?"]+)', webpage) | |
76b01870 AH |
106 | if mobj: |
107 | urls_info = mobj.groupdict() | |
108 | youtube = True | |
109 | video = True | |
17a64763 | 110 | |
76b01870 AH |
111 | if mobj is None: |
112 | mobj = re.search(r'(?P<type>)"sources": (?P<json_data>\[[^\]]+\]),', webpage) | |
113 | if mobj is None: | |
114 | mobj = re.search( | |
115 | r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);', | |
116 | webpage) | |
117 | if mobj is None: | |
118 | expired = self._html_search_regex(r'(?s)class="expired-(?:video|audio)".+?<span>(.+?)</span>', webpage, 'expired', None) | |
119 | if expired: | |
120 | raise ExtractorError('%s said: %s' % (self.IE_NAME, expired), expected=True) | |
121 | raise ExtractorError('Unable to extract video urls') | |
122 | ||
123 | urls_info = self._parse_json( | |
124 | mobj.group('json_data'), video_id, transform_source=js_to_json) | |
125 | youtube = mobj.group('type') == 'YouTube' | |
126 | video = mobj.group('type') == 'Video' or urls_info[0]['contentType'] == 'video/mp4' | |
17a64763 YCH |
127 | |
128 | if not isinstance(urls_info, list): | |
129 | urls_info = [urls_info] | |
130 | ||
76b01870 | 131 | if youtube: |
17a64763 YCH |
132 | return self.playlist_result([ |
133 | self.url_result(url_info['url']) for url_info in urls_info]) | |
134 | ||
76b01870 AH |
135 | formats = [] |
136 | for url_info in urls_info: | |
137 | height = int_or_none(url_info.get('height')) | |
138 | bitrate = int_or_none(url_info.get('bitrate')) | |
139 | width = int_or_none(url_info.get('width')) | |
140 | format_id = None | |
141 | mobj = re.search(r'_(?:(?P<height>\d+)|(?P<bitrate>\d+)k)\.mp4$', url_info['url']) | |
142 | if mobj: | |
143 | height_from_url = mobj.group('height') | |
144 | if height_from_url: | |
145 | height = height or int_or_none(height_from_url) | |
146 | width = width or int_or_none(url_info.get('label')) | |
147 | else: | |
148 | bitrate = bitrate or int_or_none(mobj.group('bitrate')) | |
149 | format_id = str_or_none(url_info.get('label')) | |
150 | formats.append({ | |
151 | 'url': url_info['url'], | |
152 | 'vcodec': url_info.get('codec') if video else 'none', | |
153 | 'width': width, | |
154 | 'height': height, | |
155 | 'tbr': bitrate, | |
156 | 'filesize': int_or_none(url_info.get('filesize')), | |
157 | 'format_id': format_id | |
158 | }) | |
7687b354 | 159 | |
64ce58db JMF |
160 | self._sort_formats(formats) |
161 | ||
162 | return { | |
163 | 'id': video_id, | |
164 | 'title': self._og_search_title(webpage), | |
165 | 'formats': formats, | |
166 | 'description': self._og_search_description(webpage), | |
167 | 'thumbnail': self._og_search_thumbnail(webpage), | |
168 | } | |
55d119e2 RA |
169 | |
170 | ||
171 | class ABCIViewIE(InfoExtractor): | |
172 | IE_NAME = 'abc.net.au:iview' | |
e0671819 | 173 | _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*video/(?P<id>[^/?#]+)' |
77341dae | 174 | _GEO_COUNTRIES = ['AU'] |
55d119e2 | 175 | |
bfcda07a | 176 | # ABC iview programs are normally available for 14 days only. |
55d119e2 | 177 | _TESTS = [{ |
d6aa1db7 | 178 | 'url': 'https://iview.abc.net.au/show/gruen/series/11/video/LE1927H001S00', |
179 | 'md5': '67715ce3c78426b11ba167d875ac6abf', | |
55d119e2 | 180 | 'info_dict': { |
d6aa1db7 | 181 | 'id': 'LE1927H001S00', |
55d119e2 | 182 | 'ext': 'mp4', |
d6aa1db7 | 183 | 'title': "Series 11 Ep 1", |
184 | 'series': "Gruen", | |
185 | 'description': 'md5:52cc744ad35045baf6aded2ce7287f67', | |
186 | 'upload_date': '20190925', | |
187 | 'uploader_id': 'abc1', | |
188 | 'timestamp': 1569445289, | |
77341dae S |
189 | }, |
190 | 'params': { | |
191 | 'skip_download': True, | |
55d119e2 RA |
192 | }, |
193 | }] | |
194 | ||
195 | def _real_extract(self, url): | |
196 | video_id = self._match_id(url) | |
e0671819 RA |
197 | video_params = self._download_json( |
198 | 'https://iview.abc.net.au/api/programs/' + video_id, video_id) | |
199 | title = unescapeHTML(video_params.get('title') or video_params['seriesTitle']) | |
200 | stream = next(s for s in video_params['playlist'] if s.get('type') in ('program', 'livestream')) | |
55d119e2 | 201 | |
e0671819 RA |
202 | house_number = video_params.get('episodeHouseNumber') or video_id |
203 | path = '/auth/hls/sign?ts={0}&hn={1}&d=android-tablet'.format( | |
77341dae S |
204 | int(time.time()), house_number) |
205 | sig = hmac.new( | |
e0671819 | 206 | b'android.content.res.Resources', |
77341dae S |
207 | path.encode('utf-8'), hashlib.sha256).hexdigest() |
208 | token = self._download_webpage( | |
209 | 'http://iview.abc.net.au{0}&sig={1}'.format(path, sig), video_id) | |
2e65e7db | 210 | |
211 | def tokenize_url(url, token): | |
77341dae S |
212 | return update_url_query(url, { |
213 | 'hdnea': token, | |
214 | }) | |
215 | ||
d6aa1db7 | 216 | for sd in ('720', 'sd', 'sd-low'): |
77341dae S |
217 | sd_url = try_get( |
218 | stream, lambda x: x['streams']['hls'][sd], compat_str) | |
219 | if not sd_url: | |
220 | continue | |
221 | formats = self._extract_m3u8_formats( | |
222 | tokenize_url(sd_url, token), video_id, 'mp4', | |
223 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False) | |
224 | if formats: | |
225 | break | |
55d119e2 RA |
226 | self._sort_formats(formats) |
227 | ||
228 | subtitles = {} | |
229 | src_vtt = stream.get('captions', {}).get('src-vtt') | |
230 | if src_vtt: | |
231 | subtitles['en'] = [{ | |
232 | 'url': src_vtt, | |
233 | 'ext': 'vtt', | |
234 | }] | |
235 | ||
e0671819 | 236 | is_live = video_params.get('livestream') == '1' |
e0671819 | 237 | |
55d119e2 RA |
238 | return { |
239 | 'id': video_id, | |
e0671819 RA |
240 | 'title': title, |
241 | 'description': video_params.get('description'), | |
242 | 'thumbnail': video_params.get('thumbnail'), | |
55d119e2 RA |
243 | 'duration': int_or_none(video_params.get('eventDuration')), |
244 | 'timestamp': parse_iso8601(video_params.get('pubDate'), ' '), | |
9e6a4180 | 245 | 'series': unescapeHTML(video_params.get('seriesTitle')), |
55d119e2 | 246 | 'series_id': video_params.get('seriesHouseNumber') or video_id[:7], |
9aca7fe6 S |
247 | 'season_number': int_or_none(self._search_regex( |
248 | r'\bSeries\s+(\d+)\b', title, 'season number', default=None)), | |
249 | 'episode_number': int_or_none(self._search_regex( | |
250 | r'\bEp\s+(\d+)\b', title, 'episode number', default=None)), | |
251 | 'episode_id': house_number, | |
55d119e2 RA |
252 | 'uploader_id': video_params.get('channel'), |
253 | 'formats': formats, | |
254 | 'subtitles': subtitles, | |
e0671819 | 255 | 'is_live': is_live, |
55d119e2 | 256 | } |
6839d02c PW |
257 | |
258 | ||
259 | class ABCIViewShowSeriesIE(InfoExtractor): | |
260 | IE_NAME = 'abc.net.au:iview:showseries' | |
261 | _VALID_URL = r'https?://iview\.abc\.net\.au/show/(?P<id>[^/]+)(?:/series/\d+)?$' | |
262 | _GEO_COUNTRIES = ['AU'] | |
263 | ||
264 | _TESTS = [{ | |
265 | 'url': 'https://iview.abc.net.au/show/upper-middle-bogan', | |
266 | 'info_dict': { | |
267 | 'id': '124870-1', | |
268 | 'title': 'Series 1', | |
269 | 'description': 'md5:93119346c24a7c322d446d8eece430ff', | |
270 | 'series': 'Upper Middle Bogan', | |
271 | 'season': 'Series 1', | |
272 | 'thumbnail': r're:^https?://cdn\.iview\.abc\.net\.au/thumbs/.*\.jpg$' | |
273 | }, | |
274 | 'playlist_count': 8, | |
275 | }, { | |
276 | 'url': 'https://iview.abc.net.au/show/upper-middle-bogan', | |
277 | 'info_dict': { | |
278 | 'id': 'CO1108V001S00', | |
279 | 'ext': 'mp4', | |
280 | 'title': 'Series 1 Ep 1 I\'m A Swan', | |
281 | 'description': 'md5:7b676758c1de11a30b79b4d301e8da93', | |
282 | 'series': 'Upper Middle Bogan', | |
283 | 'uploader_id': 'abc1', | |
284 | 'upload_date': '20210630', | |
285 | 'timestamp': 1625036400, | |
286 | }, | |
287 | 'params': { | |
288 | 'noplaylist': True, | |
289 | 'skip_download': 'm3u8', | |
290 | }, | |
291 | }] | |
292 | ||
293 | def _real_extract(self, url): | |
294 | show_id = self._match_id(url) | |
295 | webpage = self._download_webpage(url, show_id) | |
296 | webpage_data = self._search_regex( | |
297 | r'window\.__INITIAL_STATE__\s*=\s*[\'"](.+?)[\'"]\s*;', | |
298 | webpage, 'initial state') | |
299 | video_data = self._parse_json( | |
300 | unescapeHTML(webpage_data).encode('utf-8').decode('unicode_escape'), show_id) | |
301 | video_data = video_data['route']['pageData']['_embedded'] | |
302 | ||
303 | if self.get_param('noplaylist') and 'highlightVideo' in video_data: | |
304 | self.to_screen('Downloading just the highlight video because of --no-playlist') | |
305 | return self.url_result(video_data['highlightVideo']['shareUrl'], ie=ABCIViewIE.ie_key()) | |
306 | ||
307 | self.to_screen(f'Downloading playlist {show_id} - add --no-playlist to just download the highlight video') | |
308 | series = video_data['selectedSeries'] | |
309 | return { | |
310 | '_type': 'playlist', | |
311 | 'entries': [self.url_result(episode['shareUrl']) | |
312 | for episode in series['_embedded']['videoEpisodes']], | |
313 | 'id': series.get('id'), | |
314 | 'title': dict_get(series, ('title', 'displaySubtitle')), | |
315 | 'description': series.get('description'), | |
316 | 'series': dict_get(series, ('showTitle', 'displayTitle')), | |
317 | 'season': dict_get(series, ('title', 'displaySubtitle')), | |
318 | 'thumbnail': series.get('thumbnail'), | |
319 | } |