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

This commit is contained in:
Mike Fährmann
2021-03-01 17:12:11 +01:00
parent 5d3d94ba14
commit faf561b6ca
2 changed files with 29 additions and 1 deletions

View File

@@ -73,6 +73,26 @@ class WallhavenSearchExtractor(WallhavenExtractor):
return {"search": self.params}
class WallhavenCollectionExtractor(WallhavenExtractor):
"""Extractor for a collection on wallhaven.cc"""
subcategory = "collection"
directory_fmt = ("{category}", "{username}", "{collection_id}")
pattern = r"(?:https?://)?wallhaven\.cc/user/([^/?#]+)/favorites/(\d+)"
test = ("https://wallhaven.cc/user/AksumkA/favorites/74", {
"count": ">= 50",
})
def __init__(self, match):
WallhavenExtractor.__init__(self, match)
self.username, self.collection_id = match.groups()
def wallpapers(self):
return WallhavenAPI(self).collection(self.username, self.collection_id)
def metadata(self):
return {"username": self.username, "collection_id": self.collection_id}
class WallhavenImageExtractor(WallhavenExtractor):
"""Extractor for individual wallpaper on wallhaven.cc"""
subcategory = "image"
@@ -142,6 +162,14 @@ class WallhavenAPI():
endpoint = "/v1/w/" + wallpaper_id
return self._call(endpoint)["data"]
def collection(self, username, collection_id):
endpoint = "/v1/collections/{}/{}".format(username, collection_id)
return self._pagination(endpoint)
def collections(self, username):
endpoint = "/v1/collections/" + username
return self._pagination(endpoint)
def search(self, params):
endpoint = "/v1/search"
return self._pagination(endpoint, params)