[mastodon] allow downloading without access token (#2782)

Most mastodon instances allow accessing /api/v1/accounts/XXXX/statuses and api/v1/statuses/XXXX without an API access token.
This commit allows users to download at least some links from such a mastodon instance that does not already have access tokens hard-coded into the extractor.
User extractor only works on links that include the user id such as https://mastodon.tld/@id:12345. Status links work as-is.
pull/2806/head
Marius Kaufmann 2 years ago committed by GitHub
parent ea5ffb19a6
commit 0aa8345a13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -179,12 +179,11 @@ class MastodonAPI():
try: try:
access_token = INSTANCES[extractor.category]["access-token"] access_token = INSTANCES[extractor.category]["access-token"]
except (KeyError, TypeError): except (KeyError, TypeError):
raise exception.StopExtraction( pass
"Missing access token.\n" if access_token:
"Run 'gallery-dl oauth:mastodon:%s' to obtain one.", self.headers = {"Authorization": "Bearer " + access_token}
extractor.instance) else:
self.headers = None
self.headers = {"Authorization": "Bearer " + access_token}
def account_id_by_username(self, username): def account_id_by_username(self, username):
if username.startswith("id:"): if username.startswith("id:"):
@ -232,6 +231,11 @@ class MastodonAPI():
if code < 400: if code < 400:
return response return response
if code == 401:
raise exception.StopExtraction(
"Invalid or missing access token.\n"
"Run 'gallery-dl oauth:mastodon:%s' to obtain one.",
self.extractor.instance)
if code == 404: if code == 404:
raise exception.NotFoundError() raise exception.NotFoundError()
if code == 429: if code == 429:

Loading…
Cancel
Save