4 from .brightcove
import BrightcoveNewIE
16 class SevenPlusIE(BrightcoveNewIE
):
18 _VALID_URL
= r
'https?://(?:www\.)?7plus\.com\.au/(?P<path>[^?]+\?.*?\bepisode-id=(?P<id>[^&#]+))'
20 'url': 'https://7plus.com.au/MTYS?episode-id=MTYS7-003',
24 'title': 'S7 E3 - Wind Surf',
25 'description': 'md5:29c6a69f21accda7601278f81b46483d',
26 'uploader_id': '5303576322001',
27 'upload_date': '20171201',
28 'timestamp': 1512106377,
29 'series': 'Mighty Ships',
32 'episode': 'Wind Surf',
35 'skip_download': True,
38 'url': 'https://7plus.com.au/UUUU?episode-id=AUMS43-001',
39 'only_matching': True,
42 def _real_initialize(self
):
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
50 login_resp
= self
._download
_json
(
51 'https://login.7plus.com.au/accounts.getJWT', None, 'Logging in', fatal
=False,
55 'login_token': cookies
[f
'glt_{api_key}'].value
,
57 'pageURL': 'https://7plus.com.au/',
62 if 'errorMessage' in login_resp
:
63 self
.report_warning(f
'Unable to login: 7plus said: {login_resp["errorMessage"]}')
65 id_token
= login_resp
.get('id_token')
67 self
.report_warning('Unable to login: Could not extract id token')
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({
76 }).encode('utf-8')) or {}
77 self
.token
= token_resp
.get('token')
79 self
.report_warning('Unable to log in: Could not extract auth token')
81 def _real_extract(self
, url
):
82 path
, episode_id
= self
._match
_valid
_url
(url
).groups()
86 headers
['Authorization'] = f
'Bearer {self.token}'
89 media
= self
._download
_json
(
90 'https://videoservice.swm.digital/playback', episode_id
, query
={
93 'platformType': 'web',
94 'accountId': 5303576322001,
95 'referenceId': 'ref:' + episode_id
,
98 }, headers
=headers
)['media']
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)
105 for source
in media
.get('sources', {}):
106 src
= source
.get('src')
109 source
['src'] = update_url_query(src
, {'rule': ''}
)
111 info
= self
._parse
_brightcove
_metadata
(media
, episode_id
)
113 content
= self
._download
_json
(
114 'https://component-cdn.swm.digital/content/' + path
,
115 episode_id
, headers
={
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
)
123 info
[dst_key
] = value
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'])
129 'season_number': int(mobj
.group(1)),
130 'episode_number': int(mobj
.group(2)),
131 'episode': mobj
.group(3),