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