mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
[mastodon] add 'following' extractor (#1891)
This commit is contained in:
parent
2c2932973c
commit
9377543162
@ -115,6 +115,29 @@ class MastodonUserExtractor(MastodonExtractor):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MastodonFollowingExtractor(MastodonExtractor):
|
||||||
|
"""Extractor for followed mastodon users"""
|
||||||
|
subcategory = "following"
|
||||||
|
pattern = BASE_PATTERN + r"/users/([^/?#]+)/following"
|
||||||
|
test = (
|
||||||
|
("https://mastodon.social/users/0x4f/following", {
|
||||||
|
"extractor": False,
|
||||||
|
"count": ">= 20",
|
||||||
|
}),
|
||||||
|
("https://mastodon.social/users/id:10843/following"),
|
||||||
|
("https://pawoo.net/users/yoru_nine/following"),
|
||||||
|
("https://baraag.net/users/pumpkinnsfw/following"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
api = MastodonAPI(self)
|
||||||
|
account_id = api.account_id_by_username(self.item)
|
||||||
|
|
||||||
|
for account in api.account_following(account_id):
|
||||||
|
account["_extractor"] = MastodonUserExtractor
|
||||||
|
yield Message.Queue, account["url"], account
|
||||||
|
|
||||||
|
|
||||||
class MastodonStatusExtractor(MastodonExtractor):
|
class MastodonStatusExtractor(MastodonExtractor):
|
||||||
"""Extractor for images from a status"""
|
"""Extractor for images from a status"""
|
||||||
subcategory = "status"
|
subcategory = "status"
|
||||||
@ -170,6 +193,10 @@ class MastodonAPI():
|
|||||||
return account["id"]
|
return account["id"]
|
||||||
raise exception.NotFoundError("account")
|
raise exception.NotFoundError("account")
|
||||||
|
|
||||||
|
def account_following(self, account_id):
|
||||||
|
endpoint = "/v1/accounts/{}/following".format(account_id)
|
||||||
|
return self._pagination(endpoint, None)
|
||||||
|
|
||||||
def account_search(self, query, limit=40):
|
def account_search(self, query, limit=40):
|
||||||
"""Search for accounts"""
|
"""Search for accounts"""
|
||||||
endpoint = "/v1/accounts/search"
|
endpoint = "/v1/accounts/search"
|
||||||
|
@ -91,6 +91,8 @@ class TestExtractorResults(unittest.TestCase):
|
|||||||
for url, kwdict in zip(tjob.url_list, tjob.kwdict_list):
|
for url, kwdict in zip(tjob.url_list, tjob.kwdict_list):
|
||||||
if "_extractor" in kwdict:
|
if "_extractor" in kwdict:
|
||||||
extr = kwdict["_extractor"].from_url(url)
|
extr = kwdict["_extractor"].from_url(url)
|
||||||
|
if extr is None and not result.get("extractor", True):
|
||||||
|
continue
|
||||||
self.assertIsInstance(extr, kwdict["_extractor"])
|
self.assertIsInstance(extr, kwdict["_extractor"])
|
||||||
self.assertEqual(extr.url, url)
|
self.assertEqual(extr.url, url)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user