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