4 from .brightcove
import BrightcoveNewBaseIE
5 from ..compat
import compat_str
6 from ..networking
.exceptions
import HTTPError
14 class SevenPlusIE(BrightcoveNewBaseIE
):
16 _VALID_URL
= r
'https?://(?:www\.)?7plus\.com\.au/(?P<path>[^?]+\?.*?\bepisode-id=(?P<id>[^&#]+))'
18 'url': 'https://7plus.com.au/MTYS?episode-id=MTYS7-003',
22 'title': 'S7 E3 - Wind Surf',
23 'description': 'md5:29c6a69f21accda7601278f81b46483d',
24 'uploader_id': '5303576322001',
25 'upload_date': '20171201',
26 'timestamp': 1512106377,
27 'series': 'Mighty Ships',
30 'episode': 'Wind Surf',
33 'skip_download': True,
36 'url': 'https://7plus.com.au/UUUU?episode-id=AUMS43-001',
37 'only_matching': True,
40 def _real_initialize(self
):
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
48 login_resp
= self
._download
_json
(
49 'https://login.7plus.com.au/accounts.getJWT', None, 'Logging in', fatal
=False,
53 'login_token': cookies
[f
'glt_{api_key}'].value
,
55 'pageURL': 'https://7plus.com.au/',
60 if 'errorMessage' in login_resp
:
61 self
.report_warning(f
'Unable to login: 7plus said: {login_resp["errorMessage"]}')
63 id_token
= login_resp
.get('id_token')
65 self
.report_warning('Unable to login: Could not extract id token')
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({
74 }).encode('utf-8')) or {}
75 self
.token
= token_resp
.get('token')
77 self
.report_warning('Unable to log in: Could not extract auth token')
79 def _real_extract(self
, url
):
80 path
, episode_id
= self
._match
_valid
_url
(url
).groups()
84 headers
['Authorization'] = f
'Bearer {self.token}'
87 media
= self
._download
_json
(
88 'https://videoservice.swm.digital/playback', episode_id
, query
={
91 'platformType': 'web',
92 'accountId': 5303576322001,
93 'referenceId': 'ref:' + episode_id
,
96 }, headers
=headers
)['media']
97 except ExtractorError
as e
:
98 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
== 403:
99 raise ExtractorError(self
._parse
_json
(
100 e
.cause
.response
.read().decode(), episode_id
)[0]['error_code'], expected
=True)
103 for source
in media
.get('sources', {}):
104 src
= source
.get('src')
107 source
['src'] = update_url_query(src
, {'rule': ''})
109 info
= self
._parse
_brightcove
_metadata
(media
, episode_id
)
111 content
= self
._download
_json
(
112 'https://component-cdn.swm.digital/content/' + path
,
113 episode_id
, headers
={
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
)
121 info
[dst_key
] = value
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'])
127 'season_number': int(mobj
.group(1)),
128 'episode_number': int(mobj
.group(2)),
129 'episode': mobj
.group(3),