4 from .brightcove
import BrightcoveNewBaseIE
5 from ..networking
.exceptions
import HTTPError
13 class SevenPlusIE(BrightcoveNewBaseIE
):
15 _VALID_URL
= r
'https?://(?:www\.)?7plus\.com\.au/(?P<path>[^?]+\?.*?\bepisode-id=(?P<id>[^&#]+))'
17 'url': 'https://7plus.com.au/MTYS?episode-id=MTYS7-003',
21 'title': 'S7 E3 - Wind Surf',
22 'description': 'md5:29c6a69f21accda7601278f81b46483d',
23 'uploader_id': '5303576322001',
24 'upload_date': '20171201',
25 'timestamp': 1512106377,
26 'series': 'Mighty Ships',
29 'episode': 'Wind Surf',
32 'skip_download': True,
35 'url': 'https://7plus.com.au/UUUU?episode-id=AUMS43-001',
36 'only_matching': True,
39 def _real_initialize(self
):
42 cookies
= self
._get
_cookies
('https://7plus.com.au')
43 api_key
= next((x
for x
in cookies
if x
.startswith('glt_')), '')[4:]
44 if not api_key
: # Cookies are signed out, skip login
47 login_resp
= self
._download
_json
(
48 'https://login.7plus.com.au/accounts.getJWT', None, 'Logging in', fatal
=False,
52 'login_token': cookies
[f
'glt_{api_key}'].value
,
54 'pageURL': 'https://7plus.com.au/',
59 if 'errorMessage' in login_resp
:
60 self
.report_warning(f
'Unable to login: 7plus said: {login_resp["errorMessage"]}')
62 id_token
= login_resp
.get('id_token')
64 self
.report_warning('Unable to login: Could not extract id token')
67 token_resp
= self
._download
_json
(
68 'https://7plus.com.au/auth/token', None, 'Getting auth token', fatal
=False,
69 headers
={'Content-Type': 'application/json'}, data
=json
.dumps({
74 self
.token
= token_resp
.get('token')
76 self
.report_warning('Unable to log in: Could not extract auth token')
78 def _real_extract(self
, url
):
79 path
, episode_id
= self
._match
_valid
_url
(url
).groups()
83 headers
['Authorization'] = f
'Bearer {self.token}'
86 media
= self
._download
_json
(
87 'https://videoservice.swm.digital/playback', episode_id
, query
={
90 'platformType': 'web',
91 'accountId': 5303576322001,
92 'referenceId': 'ref:' + episode_id
,
95 }, headers
=headers
)['media']
96 except ExtractorError
as e
:
97 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
== 403:
98 raise ExtractorError(self
._parse
_json
(
99 e
.cause
.response
.read().decode(), episode_id
)[0]['error_code'], expected
=True)
102 for source
in media
.get('sources', {}):
103 src
= source
.get('src')
106 source
['src'] = update_url_query(src
, {'rule': ''})
108 info
= self
._parse
_brightcove
_metadata
(media
, episode_id
)
110 content
= self
._download
_json
(
111 'https://component-cdn.swm.digital/content/' + path
,
112 episode_id
, headers
={
114 }, fatal
=False) or {}
115 for item
in content
.get('items', {}):
116 if item
.get('componentData', {}).get('componentType') == 'infoPanel':
117 for src_key
, dst_key
in [('title', 'title'), ('shortSynopsis', 'description')]:
118 value
= item
.get(src_key
)
120 info
[dst_key
] = value
121 info
['series'] = try_get(
122 item
, lambda x
: x
['seriesLogo']['name'], str)
123 mobj
= re
.search(r
'^S(\d+)\s+E(\d+)\s+-\s+(.+)$', info
['title'])
126 'season_number': int(mobj
.group(1)),
127 'episode_number': int(mobj
.group(2)),
128 'episode': mobj
.group(3),