]>
Commit | Line | Data |
---|---|---|
64ce58db JMF |
1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
64ce58db JMF |
4 | |
5 | from .common import InfoExtractor | |
17a64763 YCH |
6 | from ..utils import ( |
7 | ExtractorError, | |
8 | js_to_json, | |
c0a65687 | 9 | int_or_none, |
55d119e2 | 10 | parse_iso8601, |
17a64763 | 11 | ) |
64ce58db JMF |
12 | |
13 | ||
14 | class ABCIE(InfoExtractor): | |
15 | IE_NAME = 'abc.net.au' | |
92519402 | 16 | _VALID_URL = r'https?://(?:www\.)?abc\.net\.au/news/(?:[^/]+/){1,2}(?P<id>\d+)' |
64ce58db | 17 | |
17a64763 | 18 | _TESTS = [{ |
732c848c MK |
19 | 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334', |
20 | 'md5': 'cb3dd03b18455a661071ee1e28344d9f', | |
64ce58db | 21 | 'info_dict': { |
732c848c | 22 | 'id': '5868334', |
64ce58db | 23 | 'ext': 'mp4', |
732c848c MK |
24 | 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone', |
25 | 'description': 'md5:809ad29c67a05f54eb41f2a105693a67', | |
64ce58db | 26 | }, |
5c5a3ecf | 27 | 'skip': 'this video has expired', |
17a64763 YCH |
28 | }, { |
29 | 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326', | |
30 | 'md5': 'db2a5369238b51f9811ad815b69dc086', | |
31 | 'info_dict': { | |
32 | 'id': 'NvqvPeNZsHU', | |
33 | 'ext': 'mp4', | |
34 | 'upload_date': '20150816', | |
35 | 'uploader': 'ABC News (Australia)', | |
36 | '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', | |
37 | 'uploader_id': 'NewsOnABC', | |
38 | 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill', | |
39 | }, | |
40 | 'add_ie': ['Youtube'], | |
5c5a3ecf | 41 | 'skip': 'Not accessible from Travis CI server', |
7687b354 | 42 | }, { |
43 | 'url': 'http://www.abc.net.au/news/2015-10-23/nab-lifts-interest-rates-following-westpac-and-cba/6880080', | |
44 | 'md5': 'b96eee7c9edf4fc5a358a0252881cc1f', | |
45 | 'info_dict': { | |
46 | 'id': '6880080', | |
47 | 'ext': 'mp3', | |
48 | 'title': 'NAB lifts interest rates, following Westpac and CBA', | |
49 | 'description': 'md5:f13d8edc81e462fce4a0437c7dc04728', | |
50 | }, | |
d97da29d JMF |
51 | }, { |
52 | 'url': 'http://www.abc.net.au/news/2015-10-19/6866214', | |
53 | 'only_matching': True, | |
17a64763 | 54 | }] |
64ce58db JMF |
55 | |
56 | def _real_extract(self, url): | |
ed9266db | 57 | video_id = self._match_id(url) |
64ce58db JMF |
58 | webpage = self._download_webpage(url, video_id) |
59 | ||
17a64763 | 60 | mobj = re.search( |
7687b354 | 61 | r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);', |
17a64763 YCH |
62 | webpage) |
63 | if mobj is None: | |
5c5a3ecf | 64 | expired = self._html_search_regex(r'(?s)class="expired-(?:video|audio)".+?<span>(.+?)</span>', webpage, 'expired', None) |
65 | if expired: | |
66 | raise ExtractorError('%s said: %s' % (self.IE_NAME, expired), expected=True) | |
17a64763 YCH |
67 | raise ExtractorError('Unable to extract video urls') |
68 | ||
69 | urls_info = self._parse_json( | |
70 | mobj.group('json_data'), video_id, transform_source=js_to_json) | |
71 | ||
72 | if not isinstance(urls_info, list): | |
73 | urls_info = [urls_info] | |
74 | ||
75 | if mobj.group('type') == 'YouTube': | |
76 | return self.playlist_result([ | |
77 | self.url_result(url_info['url']) for url_info in urls_info]) | |
78 | ||
64ce58db JMF |
79 | formats = [{ |
80 | 'url': url_info['url'], | |
7687b354 | 81 | 'vcodec': url_info.get('codec') if mobj.group('type') == 'Video' else 'none', |
c0a65687 YCH |
82 | 'width': int_or_none(url_info.get('width')), |
83 | 'height': int_or_none(url_info.get('height')), | |
84 | 'tbr': int_or_none(url_info.get('bitrate')), | |
85 | 'filesize': int_or_none(url_info.get('filesize')), | |
64ce58db | 86 | } for url_info in urls_info] |
7687b354 | 87 | |
64ce58db JMF |
88 | self._sort_formats(formats) |
89 | ||
90 | return { | |
91 | 'id': video_id, | |
92 | 'title': self._og_search_title(webpage), | |
93 | 'formats': formats, | |
94 | 'description': self._og_search_description(webpage), | |
95 | 'thumbnail': self._og_search_thumbnail(webpage), | |
96 | } | |
55d119e2 RA |
97 | |
98 | ||
99 | class ABCIViewIE(InfoExtractor): | |
100 | IE_NAME = 'abc.net.au:iview' | |
101 | _VALID_URL = r'https?://iview\.abc\.net\.au/programs/[^/]+/(?P<id>[^/?#]+)' | |
102 | ||
bfcda07a | 103 | # ABC iview programs are normally available for 14 days only. |
55d119e2 | 104 | _TESTS = [{ |
f165ca70 YCH |
105 | 'url': 'http://iview.abc.net.au/programs/diaries-of-a-broken-mind/ZX9735A001S00', |
106 | 'md5': 'cde42d728b3b7c2b32b1b94b4a548afc', | |
55d119e2 | 107 | 'info_dict': { |
f165ca70 | 108 | 'id': 'ZX9735A001S00', |
55d119e2 | 109 | 'ext': 'mp4', |
f165ca70 YCH |
110 | 'title': 'Diaries Of A Broken Mind', |
111 | 'description': 'md5:7de3903874b7a1be279fe6b68718fc9e', | |
112 | 'upload_date': '20161010', | |
113 | 'uploader_id': 'abc2', | |
114 | 'timestamp': 1476064920, | |
55d119e2 | 115 | }, |
bfcda07a | 116 | 'skip': 'Video gone', |
55d119e2 RA |
117 | }] |
118 | ||
119 | def _real_extract(self, url): | |
120 | video_id = self._match_id(url) | |
121 | webpage = self._download_webpage(url, video_id) | |
122 | video_params = self._parse_json(self._search_regex( | |
123 | r'videoParams\s*=\s*({.+?});', webpage, 'video params'), video_id) | |
f165ca70 | 124 | title = video_params.get('title') or video_params['seriesTitle'] |
55d119e2 RA |
125 | stream = next(s for s in video_params['playlist'] if s.get('type') == 'program') |
126 | ||
ad316425 | 127 | formats = self._extract_akamai_formats(stream['hds-unmetered'], video_id) |
55d119e2 RA |
128 | self._sort_formats(formats) |
129 | ||
130 | subtitles = {} | |
131 | src_vtt = stream.get('captions', {}).get('src-vtt') | |
132 | if src_vtt: | |
133 | subtitles['en'] = [{ | |
134 | 'url': src_vtt, | |
135 | 'ext': 'vtt', | |
136 | }] | |
137 | ||
138 | return { | |
139 | 'id': video_id, | |
140 | 'title': title, | |
141 | 'description': self._html_search_meta(['og:description', 'twitter:description'], webpage), | |
142 | 'thumbnail': self._html_search_meta(['og:image', 'twitter:image:src'], webpage), | |
143 | 'duration': int_or_none(video_params.get('eventDuration')), | |
144 | 'timestamp': parse_iso8601(video_params.get('pubDate'), ' '), | |
145 | 'series': video_params.get('seriesTitle'), | |
146 | 'series_id': video_params.get('seriesHouseNumber') or video_id[:7], | |
f165ca70 YCH |
147 | 'episode_number': int_or_none(self._html_search_meta('episodeNumber', webpage, default=None)), |
148 | 'episode': self._html_search_meta('episode_title', webpage, default=None), | |
55d119e2 RA |
149 | 'uploader_id': video_params.get('channel'), |
150 | 'formats': formats, | |
151 | 'subtitles': subtitles, | |
152 | } |