diff options
| author | 2025-07-31 01:22:01 -0400 | |
|---|---|---|
| committer | 2025-07-31 01:22:01 -0400 | |
| commit | a6e995c093de8aae2e91a0787281bb34c0b871eb (patch) | |
| tree | 2d79821b05300d34d8871eb6c9662b359a2de85d /gallery_dl/extractor/mastodon.py | |
| parent | 7672a750cb74bf31e21d76aad2776367fd476155 (diff) | |
New upstream version 1.30.2.upstream/1.30.2
Diffstat (limited to 'gallery_dl/extractor/mastodon.py')
| -rw-r--r-- | gallery_dl/extractor/mastodon.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/gallery_dl/extractor/mastodon.py b/gallery_dl/extractor/mastodon.py index 8b38474..1bab63a 100644 --- a/gallery_dl/extractor/mastodon.py +++ b/gallery_dl/extractor/mastodon.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2019-2023 Mike Fährmann +# Copyright 2019-2025 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -22,7 +22,7 @@ class MastodonExtractor(BaseExtractor): def __init__(self, match): BaseExtractor.__init__(self, match) - self.item = match.group(match.lastindex) + self.item = self.groups[-1] def _init(self): self.instance = self.root.partition("://")[2] @@ -49,10 +49,8 @@ class MastodonExtractor(BaseExtractor): attachments.extend(status["reblog"]["media_attachments"]) if self.cards: - card = status.get("card") - if card: - url = card.get("image") - if url: + if card := status.get("card"): + if url := card.get("image"): card["weburl"] = card.get("url") card["url"] = url card["id"] = "card" + "".join( @@ -202,7 +200,7 @@ class MastodonStatusExtractor(MastodonExtractor): def statuses(self): if self.groups[-2] is not None: - url = "{}/objects/{}".format(self.root, self.item) + url = f"{self.root}/objects/{self.item}" location = self.request_location(url) self.item = location.rpartition("/")[2] return (MastodonAPI(self).status(self.item),) @@ -243,7 +241,7 @@ class MastodonAPI(): if "@" in username: handle = "@" + username else: - handle = "@{}@{}".format(username, self.extractor.instance) + handle = f"@{username}@{self.extractor.instance}" for account in self.account_search(handle, 1): if account["acct"] == username: @@ -263,7 +261,7 @@ class MastodonAPI(): def account_following(self, account_id): """Accounts which the given account is following""" - endpoint = "/v1/accounts/{}/following".format(account_id) + endpoint = f"/v1/accounts/{account_id}/following" return self._pagination(endpoint, None) def account_lookup(self, username): @@ -281,7 +279,7 @@ class MastodonAPI(): def account_statuses(self, account_id, only_media=True, exclude_replies=False): """Statuses posted to the given account""" - endpoint = "/v1/accounts/{}/statuses".format(account_id) + endpoint = f"/v1/accounts/{account_id}/statuses" params = {"only_media" : "true" if only_media else "false", "exclude_replies": "true" if exclude_replies else "false"} return self._pagination(endpoint, params) @@ -315,10 +313,9 @@ class MastodonAPI(): if code < 400: 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) + raise exception.AbortExtraction( + f"Invalid or missing access token.\nRun 'gallery-dl oauth:" + f"mastodon:{self.extractor.instance}' to obtain one.") if code == 404: raise exception.NotFoundError() if code == 429: @@ -327,7 +324,7 @@ class MastodonAPI(): "%Y-%m-%dT%H:%M:%S.%fZ", )) continue - raise exception.StopExtraction(response.json().get("error")) + raise exception.AbortExtraction(response.json().get("error")) def _pagination(self, endpoint, params): url = endpoint |
