[wallhaven] add 'collections' extractor (#1351)

This commit is contained in:
Mike Fährmann
2021-03-02 01:32:26 +01:00
parent faf561b6ca
commit e165e6c265
2 changed files with 28 additions and 4 deletions

View File

@@ -93,6 +93,27 @@ class WallhavenCollectionExtractor(WallhavenExtractor):
return {"username": self.username, "collection_id": self.collection_id} return {"username": self.username, "collection_id": self.collection_id}
class WallhavenCollectionsExtractor(WallhavenExtractor):
"""Extractor for all collections of a wallhaven user"""
subcategory = "collections"
pattern = r"(?:https?://)?wallhaven\.cc/user/([^/?#]+)/favorites/?$"
test = ("https://wallhaven.cc/user/AksumkA/favorites", {
"pattern": WallhavenCollectionExtractor.pattern,
"count": 4,
})
def __init__(self, match):
WallhavenExtractor.__init__(self, match)
self.username = match.group(1)
def items(self):
for collection in WallhavenAPI(self).collections(self.username):
collection["_extractor"] = WallhavenCollectionExtractor
url = "https://wallhaven.cc/user/{}/favorites/{}".format(
self.username, collection["id"])
yield Message.Queue, url, collection
class WallhavenImageExtractor(WallhavenExtractor): class WallhavenImageExtractor(WallhavenExtractor):
"""Extractor for individual wallpaper on wallhaven.cc""" """Extractor for individual wallpaper on wallhaven.cc"""
subcategory = "image" subcategory = "image"
@@ -187,7 +208,7 @@ class WallhavenAPI():
data = self._call(endpoint, params) data = self._call(endpoint, params)
yield from data["data"] yield from data["data"]
meta = data["meta"] meta = data.get("meta")
if meta["current_page"] >= meta["last_page"]: if not meta or meta["current_page"] >= meta["last_page"]:
return return
params["page"] = meta["current_page"] + 1 params["page"] = meta["current_page"] + 1

View File

@@ -152,13 +152,16 @@ SUBCATEGORY_MAP = {
"media": "Media Timelines", "media": "Media Timelines",
"list-members": "List Members", "list-members": "List Members",
}, },
"wikiart": { "wallhaven": {
"artists": "Artist Listings", "collections": "",
}, },
"weasyl": { "weasyl": {
"journals" : "", "journals" : "",
"submissions": "", "submissions": "",
}, },
"wikiart": {
"artists": "Artist Listings",
},
} }
_OAUTH = "`OAuth <https://github.com/mikf/gallery-dl#oauth>`__" _OAUTH = "`OAuth <https://github.com/mikf/gallery-dl#oauth>`__"