2021-10-18 03:34:56 +02:00
|
|
|
import json
|
2017-12-23 13:21:33 +01:00
|
|
|
import re
|
|
|
|
|
2022-11-17 20:11:35 +01:00
|
|
|
from .brightcove import BrightcoveNewBaseIE
|
2023-07-09 09:53:02 +02:00
|
|
|
from ..networking.exceptions import HTTPError
|
2018-03-19 19:40:53 +01:00
|
|
|
from ..utils import (
|
2021-01-01 13:26:37 +01:00
|
|
|
ExtractorError,
|
2018-03-19 19:40:53 +01:00
|
|
|
try_get,
|
|
|
|
update_url_query,
|
|
|
|
)
|
2017-12-23 13:21:33 +01:00
|
|
|
|
|
|
|
|
2022-11-17 20:11:35 +01:00
|
|
|
class SevenPlusIE(BrightcoveNewBaseIE):
|
2017-12-23 13:21:33 +01:00
|
|
|
IE_NAME = '7plus'
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?7plus\.com\.au/(?P<path>[^?]+\?.*?\bepisode-id=(?P<id>[^&#]+))'
|
|
|
|
_TESTS = [{
|
2018-03-19 19:40:53 +01:00
|
|
|
'url': 'https://7plus.com.au/MTYS?episode-id=MTYS7-003',
|
2017-12-23 13:21:33 +01:00
|
|
|
'info_dict': {
|
2018-03-19 19:40:53 +01:00
|
|
|
'id': 'MTYS7-003',
|
2017-12-23 13:21:33 +01:00
|
|
|
'ext': 'mp4',
|
2018-03-19 19:40:53 +01:00
|
|
|
'title': 'S7 E3 - Wind Surf',
|
|
|
|
'description': 'md5:29c6a69f21accda7601278f81b46483d',
|
2017-12-23 13:21:33 +01:00
|
|
|
'uploader_id': '5303576322001',
|
2018-03-19 19:40:53 +01:00
|
|
|
'upload_date': '20171201',
|
|
|
|
'timestamp': 1512106377,
|
|
|
|
'series': 'Mighty Ships',
|
|
|
|
'season_number': 7,
|
|
|
|
'episode_number': 3,
|
|
|
|
'episode': 'Wind Surf',
|
2017-12-23 13:21:33 +01:00
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'skip_download': True,
|
2024-06-12 01:09:58 +02:00
|
|
|
},
|
2017-12-23 13:21:33 +01:00
|
|
|
}, {
|
|
|
|
'url': 'https://7plus.com.au/UUUU?episode-id=AUMS43-001',
|
|
|
|
'only_matching': True,
|
|
|
|
}]
|
|
|
|
|
2021-10-18 03:34:56 +02:00
|
|
|
def _real_initialize(self):
|
|
|
|
self.token = None
|
|
|
|
|
|
|
|
cookies = self._get_cookies('https://7plus.com.au')
|
|
|
|
api_key = next((x for x in cookies if x.startswith('glt_')), '')[4:]
|
|
|
|
if not api_key: # Cookies are signed out, skip login
|
|
|
|
return
|
|
|
|
|
|
|
|
login_resp = self._download_json(
|
|
|
|
'https://login.7plus.com.au/accounts.getJWT', None, 'Logging in', fatal=False,
|
|
|
|
query={
|
|
|
|
'APIKey': api_key,
|
|
|
|
'sdk': 'js_latest',
|
|
|
|
'login_token': cookies[f'glt_{api_key}'].value,
|
|
|
|
'authMode': 'cookie',
|
|
|
|
'pageURL': 'https://7plus.com.au/',
|
|
|
|
'sdkBuild': '12471',
|
|
|
|
'format': 'json',
|
|
|
|
}) or {}
|
|
|
|
|
|
|
|
if 'errorMessage' in login_resp:
|
|
|
|
self.report_warning(f'Unable to login: 7plus said: {login_resp["errorMessage"]}')
|
|
|
|
return
|
|
|
|
id_token = login_resp.get('id_token')
|
|
|
|
if not id_token:
|
|
|
|
self.report_warning('Unable to login: Could not extract id token')
|
|
|
|
return
|
|
|
|
|
|
|
|
token_resp = self._download_json(
|
|
|
|
'https://7plus.com.au/auth/token', None, 'Getting auth token', fatal=False,
|
|
|
|
headers={'Content-Type': 'application/json'}, data=json.dumps({
|
|
|
|
'idToken': id_token,
|
|
|
|
'platformId': 'web',
|
|
|
|
'regSource': '7plus',
|
2024-06-12 01:09:58 +02:00
|
|
|
}).encode()) or {}
|
2021-10-18 03:34:56 +02:00
|
|
|
self.token = token_resp.get('token')
|
|
|
|
if not self.token:
|
|
|
|
self.report_warning('Unable to log in: Could not extract auth token')
|
|
|
|
|
2017-12-23 13:21:33 +01:00
|
|
|
def _real_extract(self, url):
|
2021-08-19 03:41:24 +02:00
|
|
|
path, episode_id = self._match_valid_url(url).groups()
|
2017-12-23 13:21:33 +01:00
|
|
|
|
2021-10-18 03:34:56 +02:00
|
|
|
headers = {}
|
|
|
|
if self.token:
|
|
|
|
headers['Authorization'] = f'Bearer {self.token}'
|
|
|
|
|
2021-01-01 13:26:37 +01:00
|
|
|
try:
|
|
|
|
media = self._download_json(
|
|
|
|
'https://videoservice.swm.digital/playback', episode_id, query={
|
|
|
|
'appId': '7plus',
|
|
|
|
'deviceType': 'web',
|
|
|
|
'platformType': 'web',
|
|
|
|
'accountId': 5303576322001,
|
|
|
|
'referenceId': 'ref:' + episode_id,
|
|
|
|
'deliveryId': 'csai',
|
|
|
|
'videoType': 'vod',
|
2021-10-18 03:34:56 +02:00
|
|
|
}, headers=headers)['media']
|
2021-01-01 13:26:37 +01:00
|
|
|
except ExtractorError as e:
|
2023-07-09 09:53:02 +02:00
|
|
|
if isinstance(e.cause, HTTPError) and e.cause.status == 403:
|
2021-01-01 13:26:37 +01:00
|
|
|
raise ExtractorError(self._parse_json(
|
2023-07-09 09:53:02 +02:00
|
|
|
e.cause.response.read().decode(), episode_id)[0]['error_code'], expected=True)
|
2021-01-01 13:26:37 +01:00
|
|
|
raise
|
2017-12-23 13:21:33 +01:00
|
|
|
|
|
|
|
for source in media.get('sources', {}):
|
|
|
|
src = source.get('src')
|
|
|
|
if not src:
|
|
|
|
continue
|
|
|
|
source['src'] = update_url_query(src, {'rule': ''})
|
|
|
|
|
|
|
|
info = self._parse_brightcove_metadata(media, episode_id)
|
|
|
|
|
|
|
|
content = self._download_json(
|
|
|
|
'https://component-cdn.swm.digital/content/' + path,
|
|
|
|
episode_id, headers={
|
|
|
|
'market-id': 4,
|
|
|
|
}, fatal=False) or {}
|
|
|
|
for item in content.get('items', {}):
|
|
|
|
if item.get('componentData', {}).get('componentType') == 'infoPanel':
|
|
|
|
for src_key, dst_key in [('title', 'title'), ('shortSynopsis', 'description')]:
|
|
|
|
value = item.get(src_key)
|
|
|
|
if value:
|
|
|
|
info[dst_key] = value
|
2018-03-19 19:40:53 +01:00
|
|
|
info['series'] = try_get(
|
2024-06-12 01:09:58 +02:00
|
|
|
item, lambda x: x['seriesLogo']['name'], str)
|
2018-03-19 19:40:53 +01:00
|
|
|
mobj = re.search(r'^S(\d+)\s+E(\d+)\s+-\s+(.+)$', info['title'])
|
|
|
|
if mobj:
|
|
|
|
info.update({
|
|
|
|
'season_number': int(mobj.group(1)),
|
|
|
|
'episode_number': int(mobj.group(2)),
|
|
|
|
'episode': mobj.group(3),
|
|
|
|
})
|
2017-12-23 13:21:33 +01:00
|
|
|
|
|
|
|
return info
|