]>
Commit | Line | Data |
---|---|---|
38e0f16a RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..compat import compat_str | |
6 | from ..utils import ( | |
7 | int_or_none, | |
8 | float_or_none, | |
9 | ExtractorError, | |
10 | ) | |
11 | ||
12 | ||
13 | class NineNowIE(InfoExtractor): | |
14 | IE_NAME = '9now.com.au' | |
15 | _VALID_URL = r'https?://(?:www\.)?9now\.com\.au/(?:[^/]+/){2}(?P<id>[^/?#]+)' | |
16 | _TESTS = [{ | |
17 | # clip | |
18 | 'url': 'https://www.9now.com.au/afl-footy-show/2016/clip-ciql02091000g0hp5oktrnytc', | |
19 | 'md5': '17cf47d63ec9323e562c9957a968b565', | |
20 | 'info_dict': { | |
21 | 'id': '16801', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'St. Kilda\'s Joey Montagna on the potential for a player\'s strike', | |
24 | 'description': 'Is a boycott of the NAB Cup "on the table"?', | |
25 | 'uploader_id': '4460760524001', | |
26 | 'upload_date': '20160713', | |
27 | 'timestamp': 1468421266, | |
28 | }, | |
29 | 'skip': 'Only available in Australia', | |
30 | }, { | |
31 | # episode | |
32 | 'url': 'https://www.9now.com.au/afl-footy-show/2016/episode-19', | |
33 | 'only_matching': True, | |
34 | }, { | |
35 | # DRM protected | |
342f0c36 | 36 | 'url': 'https://www.9now.com.au/andrew-marrs-history-of-the-world/season-1/episode-1', |
38e0f16a RA |
37 | 'only_matching': True, |
38 | }] | |
39 | BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/4460760524001/default_default/index.html?videoId=%s' | |
40 | ||
41 | def _real_extract(self, url): | |
42 | display_id = self._match_id(url) | |
43 | webpage = self._download_webpage(url, display_id) | |
44 | page_data = self._parse_json(self._search_regex( | |
45 | r'window\.__data\s*=\s*({.*?});', webpage, | |
46 | 'page data'), display_id) | |
47 | common_data = page_data.get('episode', {}).get('episode') or page_data.get('clip', {}).get('clip') | |
48 | video_data = common_data['video'] | |
49 | ||
50 | if video_data.get('drm'): | |
51 | raise ExtractorError('This video is DRM protected.', expected=True) | |
52 | ||
53 | brightcove_id = video_data.get('brightcoveId') or 'ref:' + video_data['referenceId'] | |
54 | video_id = compat_str(video_data.get('id') or brightcove_id) | |
55 | title = common_data['name'] | |
56 | ||
57 | thumbnails = [{ | |
58 | 'id': thumbnail_id, | |
59 | 'url': thumbnail_url, | |
60 | 'width': int_or_none(thumbnail_id[1:]) | |
61 | } for thumbnail_id, thumbnail_url in common_data.get('image', {}).get('sizes', {}).items()] | |
62 | ||
63 | return { | |
64 | '_type': 'url_transparent', | |
65 | 'url': self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id, | |
66 | 'id': video_id, | |
67 | 'title': title, | |
68 | 'description': common_data.get('description'), | |
69 | 'duration': float_or_none(video_data.get('duration'), 1000), | |
70 | 'thumbnails': thumbnails, | |
71 | 'ie_key': 'BrightcoveNew', | |
72 | } |