2 from __future__
import unicode_literals
7 from .brightcove
import BrightcoveNewIE
19 class SevenPlusIE(BrightcoveNewIE
):
21 _VALID_URL
= r
'https?://(?:www\.)?7plus\.com\.au/(?P<path>[^?]+\?.*?\bepisode-id=(?P<id>[^&#]+))'
23 'url': 'https://7plus.com.au/MTYS?episode-id=MTYS7-003',
27 'title': 'S7 E3 - Wind Surf',
28 'description': 'md5:29c6a69f21accda7601278f81b46483d',
29 'uploader_id': '5303576322001',
30 'upload_date': '20171201',
31 'timestamp': 1512106377,
32 'series': 'Mighty Ships',
35 'episode': 'Wind Surf',
38 'format': 'bestvideo',
39 'skip_download': True,
42 'url': 'https://7plus.com.au/UUUU?episode-id=AUMS43-001',
43 'only_matching': True,
46 def _real_initialize(self
):
49 cookies
= self
._get
_cookies
('https://7plus.com.au')
50 api_key
= next((x
for x
in cookies
if x
.startswith('glt_')), '')[4:]
51 if not api_key
: # Cookies are signed out, skip login
54 login_resp
= self
._download
_json
(
55 'https://login.7plus.com.au/accounts.getJWT', None, 'Logging in', fatal
=False,
59 'login_token': cookies
[f
'glt_{api_key}'].value
,
61 'pageURL': 'https://7plus.com.au/',
66 if 'errorMessage' in login_resp
:
67 self
.report_warning(f
'Unable to login: 7plus said: {login_resp["errorMessage"]}')
69 id_token
= login_resp
.get('id_token')
71 self
.report_warning('Unable to login: Could not extract id token')
74 token_resp
= self
._download
_json
(
75 'https://7plus.com.au/auth/token', None, 'Getting auth token', fatal
=False,
76 headers
={'Content-Type': 'application/json'}
, data
=json
.dumps({
80 }).encode('utf-8')) or {}
81 self
.token
= token_resp
.get('token')
83 self
.report_warning('Unable to log in: Could not extract auth token')
85 def _real_extract(self
, url
):
86 path
, episode_id
= self
._match
_valid
_url
(url
).groups()
90 headers
['Authorization'] = f
'Bearer {self.token}'
93 media
= self
._download
_json
(
94 'https://videoservice.swm.digital/playback', episode_id
, query
={
97 'platformType': 'web',
98 'accountId': 5303576322001,
99 'referenceId': 'ref:' + episode_id
,
100 'deliveryId': 'csai',
102 }, headers
=headers
)['media']
103 except ExtractorError
as e
:
104 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
105 raise ExtractorError(self
._parse
_json
(
106 e
.cause
.read().decode(), episode_id
)[0]['error_code'], expected
=True)
109 for source
in media
.get('sources', {}):
110 src
= source
.get('src')
113 source
['src'] = update_url_query(src
, {'rule': ''}
)
115 info
= self
._parse
_brightcove
_metadata
(media
, episode_id
)
117 content
= self
._download
_json
(
118 'https://component-cdn.swm.digital/content/' + path
,
119 episode_id
, headers
={
121 }, fatal
=False) or {}
122 for item
in content
.get('items', {}):
123 if item
.get('componentData', {}).get('componentType') == 'infoPanel':
124 for src_key
, dst_key
in [('title', 'title'), ('shortSynopsis', 'description')]:
125 value
= item
.get(src_key
)
127 info
[dst_key
] = value
128 info
['series'] = try_get(
129 item
, lambda x
: x
['seriesLogo']['name'], compat_str
)
130 mobj
= re
.search(r
'^S(\d+)\s+E(\d+)\s+-\s+(.+)$', info
['title'])
133 'season_number': int(mobj
.group(1)),
134 'episode_number': int(mobj
.group(2)),
135 'episode': mobj
.group(3),