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 'skip_download': True,
41 'url': 'https://7plus.com.au/UUUU?episode-id=AUMS43-001',
42 'only_matching': True,
45 def _real_initialize(self
):
48 cookies
= self
._get
_cookies
('https://7plus.com.au')
49 api_key
= next((x
for x
in cookies
if x
.startswith('glt_')), '')[4:]
50 if not api_key
: # Cookies are signed out, skip login
53 login_resp
= self
._download
_json
(
54 'https://login.7plus.com.au/accounts.getJWT', None, 'Logging in', fatal
=False,
58 'login_token': cookies
[f
'glt_{api_key}'].value
,
60 'pageURL': 'https://7plus.com.au/',
65 if 'errorMessage' in login_resp
:
66 self
.report_warning(f
'Unable to login: 7plus said: {login_resp["errorMessage"]}')
68 id_token
= login_resp
.get('id_token')
70 self
.report_warning('Unable to login: Could not extract id token')
73 token_resp
= self
._download
_json
(
74 'https://7plus.com.au/auth/token', None, 'Getting auth token', fatal
=False,
75 headers
={'Content-Type': 'application/json'}
, data
=json
.dumps({
79 }).encode('utf-8')) or {}
80 self
.token
= token_resp
.get('token')
82 self
.report_warning('Unable to log in: Could not extract auth token')
84 def _real_extract(self
, url
):
85 path
, episode_id
= self
._match
_valid
_url
(url
).groups()
89 headers
['Authorization'] = f
'Bearer {self.token}'
92 media
= self
._download
_json
(
93 'https://videoservice.swm.digital/playback', episode_id
, query
={
96 'platformType': 'web',
97 'accountId': 5303576322001,
98 'referenceId': 'ref:' + episode_id
,
101 }, headers
=headers
)['media']
102 except ExtractorError
as e
:
103 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
104 raise ExtractorError(self
._parse
_json
(
105 e
.cause
.read().decode(), episode_id
)[0]['error_code'], expected
=True)
108 for source
in media
.get('sources', {}):
109 src
= source
.get('src')
112 source
['src'] = update_url_query(src
, {'rule': ''}
)
114 info
= self
._parse
_brightcove
_metadata
(media
, episode_id
)
116 content
= self
._download
_json
(
117 'https://component-cdn.swm.digital/content/' + path
,
118 episode_id
, headers
={
120 }, fatal
=False) or {}
121 for item
in content
.get('items', {}):
122 if item
.get('componentData', {}).get('componentType') == 'infoPanel':
123 for src_key
, dst_key
in [('title', 'title'), ('shortSynopsis', 'description')]:
124 value
= item
.get(src_key
)
126 info
[dst_key
] = value
127 info
['series'] = try_get(
128 item
, lambda x
: x
['seriesLogo']['name'], compat_str
)
129 mobj
= re
.search(r
'^S(\d+)\s+E(\d+)\s+-\s+(.+)$', info
['title'])
132 'season_number': int(mobj
.group(1)),
133 'episode_number': int(mobj
.group(2)),
134 'episode': mobj
.group(3),