]>
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 YCH |
10 | from ..utils import ( |
11 | ExtractorError, | |
12 | js_to_json, | |
c0a65687 | 13 | int_or_none, |
55d119e2 | 14 | parse_iso8601, |
58179eb7 | 15 | try_get, |
77341dae | 16 | update_url_query, |
17a64763 | 17 | ) |
64ce58db JMF |
18 | |
19 | ||
20 | class ABCIE(InfoExtractor): | |
21 | IE_NAME = 'abc.net.au' | |
92519402 | 22 | _VALID_URL = r'https?://(?:www\.)?abc\.net\.au/news/(?:[^/]+/){1,2}(?P<id>\d+)' |
64ce58db | 23 | |
17a64763 | 24 | _TESTS = [{ |
732c848c MK |
25 | 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334', |
26 | 'md5': 'cb3dd03b18455a661071ee1e28344d9f', | |
64ce58db | 27 | 'info_dict': { |
732c848c | 28 | 'id': '5868334', |
64ce58db | 29 | 'ext': 'mp4', |
732c848c MK |
30 | 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone', |
31 | 'description': 'md5:809ad29c67a05f54eb41f2a105693a67', | |
64ce58db | 32 | }, |
5c5a3ecf | 33 | 'skip': 'this video has expired', |
17a64763 YCH |
34 | }, { |
35 | 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326', | |
36 | 'md5': 'db2a5369238b51f9811ad815b69dc086', | |
37 | 'info_dict': { | |
38 | 'id': 'NvqvPeNZsHU', | |
39 | 'ext': 'mp4', | |
40 | 'upload_date': '20150816', | |
41 | 'uploader': 'ABC News (Australia)', | |
42 | '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', | |
43 | 'uploader_id': 'NewsOnABC', | |
44 | 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill', | |
45 | }, | |
46 | 'add_ie': ['Youtube'], | |
5c5a3ecf | 47 | 'skip': 'Not accessible from Travis CI server', |
7687b354 | 48 | }, { |
49 | 'url': 'http://www.abc.net.au/news/2015-10-23/nab-lifts-interest-rates-following-westpac-and-cba/6880080', | |
50 | 'md5': 'b96eee7c9edf4fc5a358a0252881cc1f', | |
51 | 'info_dict': { | |
52 | 'id': '6880080', | |
53 | 'ext': 'mp3', | |
54 | 'title': 'NAB lifts interest rates, following Westpac and CBA', | |
55 | 'description': 'md5:f13d8edc81e462fce4a0437c7dc04728', | |
56 | }, | |
d97da29d JMF |
57 | }, { |
58 | 'url': 'http://www.abc.net.au/news/2015-10-19/6866214', | |
59 | 'only_matching': True, | |
17a64763 | 60 | }] |
64ce58db JMF |
61 | |
62 | def _real_extract(self, url): | |
ed9266db | 63 | video_id = self._match_id(url) |
64ce58db JMF |
64 | webpage = self._download_webpage(url, video_id) |
65 | ||
17a64763 | 66 | mobj = re.search( |
7687b354 | 67 | r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);', |
17a64763 YCH |
68 | webpage) |
69 | if mobj is None: | |
5c5a3ecf | 70 | expired = self._html_search_regex(r'(?s)class="expired-(?:video|audio)".+?<span>(.+?)</span>', webpage, 'expired', None) |
71 | if expired: | |
72 | raise ExtractorError('%s said: %s' % (self.IE_NAME, expired), expected=True) | |
17a64763 YCH |
73 | raise ExtractorError('Unable to extract video urls') |
74 | ||
75 | urls_info = self._parse_json( | |
76 | mobj.group('json_data'), video_id, transform_source=js_to_json) | |
77 | ||
78 | if not isinstance(urls_info, list): | |
79 | urls_info = [urls_info] | |
80 | ||
81 | if mobj.group('type') == 'YouTube': | |
82 | return self.playlist_result([ | |
83 | self.url_result(url_info['url']) for url_info in urls_info]) | |
84 | ||
64ce58db JMF |
85 | formats = [{ |
86 | 'url': url_info['url'], | |
7687b354 | 87 | 'vcodec': url_info.get('codec') if mobj.group('type') == 'Video' else 'none', |
c0a65687 YCH |
88 | 'width': int_or_none(url_info.get('width')), |
89 | 'height': int_or_none(url_info.get('height')), | |
90 | 'tbr': int_or_none(url_info.get('bitrate')), | |
91 | 'filesize': int_or_none(url_info.get('filesize')), | |
64ce58db | 92 | } for url_info in urls_info] |
7687b354 | 93 | |
64ce58db JMF |
94 | self._sort_formats(formats) |
95 | ||
96 | return { | |
97 | 'id': video_id, | |
98 | 'title': self._og_search_title(webpage), | |
99 | 'formats': formats, | |
100 | 'description': self._og_search_description(webpage), | |
101 | 'thumbnail': self._og_search_thumbnail(webpage), | |
102 | } | |
55d119e2 RA |
103 | |
104 | ||
105 | class ABCIViewIE(InfoExtractor): | |
106 | IE_NAME = 'abc.net.au:iview' | |
107 | _VALID_URL = r'https?://iview\.abc\.net\.au/programs/[^/]+/(?P<id>[^/?#]+)' | |
77341dae | 108 | _GEO_COUNTRIES = ['AU'] |
55d119e2 | 109 | |
bfcda07a | 110 | # ABC iview programs are normally available for 14 days only. |
55d119e2 | 111 | _TESTS = [{ |
77341dae | 112 | 'url': 'http://iview.abc.net.au/programs/call-the-midwife/ZW0898A003S00', |
f165ca70 | 113 | 'md5': 'cde42d728b3b7c2b32b1b94b4a548afc', |
55d119e2 | 114 | 'info_dict': { |
77341dae | 115 | 'id': 'ZW0898A003S00', |
55d119e2 | 116 | 'ext': 'mp4', |
77341dae S |
117 | 'title': 'Series 5 Ep 3', |
118 | 'description': 'md5:e0ef7d4f92055b86c4f33611f180ed79', | |
119 | 'upload_date': '20171228', | |
120 | 'uploader_id': 'abc1', | |
121 | 'timestamp': 1514499187, | |
122 | }, | |
123 | 'params': { | |
124 | 'skip_download': True, | |
55d119e2 RA |
125 | }, |
126 | }] | |
127 | ||
128 | def _real_extract(self, url): | |
129 | video_id = self._match_id(url) | |
130 | webpage = self._download_webpage(url, video_id) | |
131 | video_params = self._parse_json(self._search_regex( | |
132 | r'videoParams\s*=\s*({.+?});', webpage, 'video params'), video_id) | |
f165ca70 | 133 | title = video_params.get('title') or video_params['seriesTitle'] |
55d119e2 RA |
134 | stream = next(s for s in video_params['playlist'] if s.get('type') == 'program') |
135 | ||
2e65e7db | 136 | house_number = video_params.get('episodeHouseNumber') |
137 | path = '/auth/hls/sign?ts={0}&hn={1}&d=android-mobile'.format( | |
77341dae S |
138 | int(time.time()), house_number) |
139 | sig = hmac.new( | |
140 | 'android.content.res.Resources'.encode('utf-8'), | |
141 | path.encode('utf-8'), hashlib.sha256).hexdigest() | |
142 | token = self._download_webpage( | |
143 | 'http://iview.abc.net.au{0}&sig={1}'.format(path, sig), video_id) | |
2e65e7db | 144 | |
145 | def tokenize_url(url, token): | |
77341dae S |
146 | return update_url_query(url, { |
147 | 'hdnea': token, | |
148 | }) | |
149 | ||
150 | for sd in ('sd', 'sd-low'): | |
151 | sd_url = try_get( | |
152 | stream, lambda x: x['streams']['hls'][sd], compat_str) | |
153 | if not sd_url: | |
154 | continue | |
155 | formats = self._extract_m3u8_formats( | |
156 | tokenize_url(sd_url, token), video_id, 'mp4', | |
157 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False) | |
158 | if formats: | |
159 | break | |
55d119e2 RA |
160 | self._sort_formats(formats) |
161 | ||
162 | subtitles = {} | |
163 | src_vtt = stream.get('captions', {}).get('src-vtt') | |
164 | if src_vtt: | |
165 | subtitles['en'] = [{ | |
166 | 'url': src_vtt, | |
167 | 'ext': 'vtt', | |
168 | }] | |
169 | ||
170 | return { | |
171 | 'id': video_id, | |
172 | 'title': title, | |
173 | 'description': self._html_search_meta(['og:description', 'twitter:description'], webpage), | |
174 | 'thumbnail': self._html_search_meta(['og:image', 'twitter:image:src'], webpage), | |
175 | 'duration': int_or_none(video_params.get('eventDuration')), | |
176 | 'timestamp': parse_iso8601(video_params.get('pubDate'), ' '), | |
177 | 'series': video_params.get('seriesTitle'), | |
178 | 'series_id': video_params.get('seriesHouseNumber') or video_id[:7], | |
f165ca70 YCH |
179 | 'episode_number': int_or_none(self._html_search_meta('episodeNumber', webpage, default=None)), |
180 | 'episode': self._html_search_meta('episode_title', webpage, default=None), | |
55d119e2 RA |
181 | 'uploader_id': video_params.get('channel'), |
182 | 'formats': formats, | |
183 | 'subtitles': subtitles, | |
184 | } |