[mastodon] cache apps on logging in
This commit is contained in:
parent
224aaf6089
commit
46e0bbdd3f
|
@ -149,15 +149,18 @@ class MastodonSHIE(SelfhostedInfoExtractor):
|
||||||
'Invalid login format - must be in format [username or email]@[instance]')
|
'Invalid login format - must be in format [username or email]@[instance]')
|
||||||
username, instance = mobj.group('username', 'instance')
|
username, instance = mobj.group('username', 'instance')
|
||||||
|
|
||||||
app_info = self._download_json(
|
app_info = self._downloader.cache.load('mastodon-apps', instance)
|
||||||
f'https://{instance}/api/v1/apps', None, 'Creating an app', headers={
|
if not app_info:
|
||||||
'Content-Type': 'application/json',
|
app_info = self._download_json(
|
||||||
}, data=bytes(json.dumps({
|
f'https://{instance}/api/v1/apps', None, 'Creating an app', headers={
|
||||||
'client_name': 'haruhi-dl',
|
'Content-Type': 'application/json',
|
||||||
'redirect_uris': 'urn:ietf:wg:oauth:2.0:oob',
|
}, data=bytes(json.dumps({
|
||||||
'scopes': 'read',
|
'client_name': 'haruhi-dl',
|
||||||
'website': 'https://haruhi.download',
|
'redirect_uris': 'urn:ietf:wg:oauth:2.0:oob',
|
||||||
}).encode('utf-8')))
|
'scopes': 'read',
|
||||||
|
'website': 'https://haruhi.download',
|
||||||
|
}).encode('utf-8')))
|
||||||
|
self._downloader.cache.store('mastodon-apps', instance, app_info)
|
||||||
|
|
||||||
login_webpage = self._download_webpage(
|
login_webpage = self._download_webpage(
|
||||||
f'https://{instance}/oauth/authorize', None, 'Downloading login page', query={
|
f'https://{instance}/oauth/authorize', None, 'Downloading login page', query={
|
||||||
|
@ -176,21 +179,25 @@ class MastodonSHIE(SelfhostedInfoExtractor):
|
||||||
login_form = self._hidden_inputs(login_webpage)
|
login_form = self._hidden_inputs(login_webpage)
|
||||||
login_form['user[email]'] = username
|
login_form['user[email]'] = username
|
||||||
login_form['user[password]'] = password
|
login_form['user[password]'] = password
|
||||||
login_req = self._download_webpage(
|
login_req, urlh = self._download_webpage_handle(
|
||||||
f'https://{instance}/auth/sign_in', None, 'Sending login details',
|
f'https://{instance}/auth/sign_in', None, 'Sending login details',
|
||||||
headers={
|
headers={
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
}, data=bytes(urlencode(login_form).encode('utf-8')))
|
}, data=bytes(urlencode(login_form).encode('utf-8')))
|
||||||
auth_form = self._hidden_inputs(
|
# cached apps may already be authorized
|
||||||
self._search_regex(
|
if '/oauth/authorize/native' in urlh.url:
|
||||||
r'(?s)(<form\b[^>]+>.+?>Authorize</.+?</form>)',
|
oauth_token = parse_qs(urlparse(urlh.url).query)['code'][0]
|
||||||
login_req, 'authorization form'))
|
else:
|
||||||
_, urlh = self._download_webpage_handle(
|
auth_form = self._hidden_inputs(
|
||||||
f'https://{instance}/oauth/authorize', None, 'Confirming authorization',
|
self._search_regex(
|
||||||
headers={
|
r'(?s)(<form\b[^>]+>.+?>Authorize</.+?</form>)',
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
login_req, 'authorization form'))
|
||||||
}, data=bytes(urlencode(auth_form).encode('utf-8')))
|
_, urlh = self._download_webpage_handle(
|
||||||
oauth_token = parse_qs(urlparse(urlh.url).query)['code'][0]
|
f'https://{instance}/oauth/authorize', None, 'Confirming authorization',
|
||||||
|
headers={
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
}, data=bytes(urlencode(auth_form).encode('utf-8')))
|
||||||
|
oauth_token = parse_qs(urlparse(urlh.url).query)['code'][0]
|
||||||
elif 'content: "✔\\fe0e";' in login_webpage:
|
elif 'content: "✔\\fe0e";' in login_webpage:
|
||||||
# pleroma
|
# pleroma
|
||||||
login_form = self._hidden_inputs(login_webpage)
|
login_form = self._hidden_inputs(login_webpage)
|
||||||
|
|
Loading…
Reference in a new issue