]>
Commit | Line | Data |
---|---|---|
4b7dd170 RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
e69585f8 | 4 | import json |
4b7dd170 RA |
5 | import re |
6 | ||
7 | from .brightcove import BrightcoveNewIE | |
29f7c58a | 8 | from ..compat import ( |
9 | compat_HTTPError, | |
10 | compat_str, | |
11 | ) | |
d9e2240f | 12 | from ..utils import ( |
29f7c58a | 13 | ExtractorError, |
d9e2240f S |
14 | try_get, |
15 | update_url_query, | |
16 | ) | |
4b7dd170 RA |
17 | |
18 | ||
19 | class SevenPlusIE(BrightcoveNewIE): | |
20 | IE_NAME = '7plus' | |
21 | _VALID_URL = r'https?://(?:www\.)?7plus\.com\.au/(?P<path>[^?]+\?.*?\bepisode-id=(?P<id>[^&#]+))' | |
22 | _TESTS = [{ | |
d9e2240f | 23 | 'url': 'https://7plus.com.au/MTYS?episode-id=MTYS7-003', |
4b7dd170 | 24 | 'info_dict': { |
d9e2240f | 25 | 'id': 'MTYS7-003', |
4b7dd170 | 26 | 'ext': 'mp4', |
d9e2240f S |
27 | 'title': 'S7 E3 - Wind Surf', |
28 | 'description': 'md5:29c6a69f21accda7601278f81b46483d', | |
4b7dd170 | 29 | 'uploader_id': '5303576322001', |
d9e2240f S |
30 | 'upload_date': '20171201', |
31 | 'timestamp': 1512106377, | |
32 | 'series': 'Mighty Ships', | |
33 | 'season_number': 7, | |
34 | 'episode_number': 3, | |
35 | 'episode': 'Wind Surf', | |
4b7dd170 RA |
36 | }, |
37 | 'params': { | |
4b7dd170 RA |
38 | 'skip_download': True, |
39 | } | |
40 | }, { | |
41 | 'url': 'https://7plus.com.au/UUUU?episode-id=AUMS43-001', | |
42 | 'only_matching': True, | |
43 | }] | |
44 | ||
e69585f8 | 45 | def _real_initialize(self): |
46 | self.token = None | |
47 | ||
48 | cookies = self._get_cookies('https://7plus.com.au') | |
49 | api_key = next((x for x in cookies if x.startswith('glt_')), '')[4:] | |
50 | if not api_key: # Cookies are signed out, skip login | |
51 | return | |
52 | ||
53 | login_resp = self._download_json( | |
54 | 'https://login.7plus.com.au/accounts.getJWT', None, 'Logging in', fatal=False, | |
55 | query={ | |
56 | 'APIKey': api_key, | |
57 | 'sdk': 'js_latest', | |
58 | 'login_token': cookies[f'glt_{api_key}'].value, | |
59 | 'authMode': 'cookie', | |
60 | 'pageURL': 'https://7plus.com.au/', | |
61 | 'sdkBuild': '12471', | |
62 | 'format': 'json', | |
63 | }) or {} | |
64 | ||
65 | if 'errorMessage' in login_resp: | |
66 | self.report_warning(f'Unable to login: 7plus said: {login_resp["errorMessage"]}') | |
67 | return | |
68 | id_token = login_resp.get('id_token') | |
69 | if not id_token: | |
70 | self.report_warning('Unable to login: Could not extract id token') | |
71 | return | |
72 | ||
73 | token_resp = self._download_json( | |
74 | 'https://7plus.com.au/auth/token', None, 'Getting auth token', fatal=False, | |
75 | headers={'Content-Type': 'application/json'}, data=json.dumps({ | |
76 | 'idToken': id_token, | |
77 | 'platformId': 'web', | |
78 | 'regSource': '7plus', | |
79 | }).encode('utf-8')) or {} | |
80 | self.token = token_resp.get('token') | |
81 | if not self.token: | |
82 | self.report_warning('Unable to log in: Could not extract auth token') | |
83 | ||
4b7dd170 | 84 | def _real_extract(self, url): |
5ad28e7f | 85 | path, episode_id = self._match_valid_url(url).groups() |
4b7dd170 | 86 | |
e69585f8 | 87 | headers = {} |
88 | if self.token: | |
89 | headers['Authorization'] = f'Bearer {self.token}' | |
90 | ||
29f7c58a | 91 | try: |
92 | media = self._download_json( | |
93 | 'https://videoservice.swm.digital/playback', episode_id, query={ | |
94 | 'appId': '7plus', | |
95 | 'deviceType': 'web', | |
96 | 'platformType': 'web', | |
97 | 'accountId': 5303576322001, | |
98 | 'referenceId': 'ref:' + episode_id, | |
99 | 'deliveryId': 'csai', | |
100 | 'videoType': 'vod', | |
e69585f8 | 101 | }, headers=headers)['media'] |
29f7c58a | 102 | except ExtractorError as e: |
103 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403: | |
104 | raise ExtractorError(self._parse_json( | |
105 | e.cause.read().decode(), episode_id)[0]['error_code'], expected=True) | |
106 | raise | |
4b7dd170 RA |
107 | |
108 | for source in media.get('sources', {}): | |
109 | src = source.get('src') | |
110 | if not src: | |
111 | continue | |
112 | source['src'] = update_url_query(src, {'rule': ''}) | |
113 | ||
114 | info = self._parse_brightcove_metadata(media, episode_id) | |
115 | ||
116 | content = self._download_json( | |
117 | 'https://component-cdn.swm.digital/content/' + path, | |
118 | episode_id, headers={ | |
119 | 'market-id': 4, | |
120 | }, fatal=False) or {} | |
121 | for item in content.get('items', {}): | |
122 | if item.get('componentData', {}).get('componentType') == 'infoPanel': | |
123 | for src_key, dst_key in [('title', 'title'), ('shortSynopsis', 'description')]: | |
124 | value = item.get(src_key) | |
125 | if value: | |
126 | info[dst_key] = value | |
d9e2240f S |
127 | info['series'] = try_get( |
128 | item, lambda x: x['seriesLogo']['name'], compat_str) | |
129 | mobj = re.search(r'^S(\d+)\s+E(\d+)\s+-\s+(.+)$', info['title']) | |
130 | if mobj: | |
131 | info.update({ | |
132 | 'season_number': int(mobj.group(1)), | |
133 | 'episode_number': int(mobj.group(2)), | |
134 | 'episode': mobj.group(3), | |
135 | }) | |
4b7dd170 RA |
136 | |
137 | return info |