diff --git a/docs/supportedsites.rst b/docs/supportedsites.rst index 7ac2363b..10a381d5 100644 --- a/docs/supportedsites.rst +++ b/docs/supportedsites.rst @@ -151,7 +151,7 @@ Twitter https://twitter.com/ |twitter-C| Unsplash https://unsplash.com/ |unsplash-C| Vipr https://vipr.im/ individual Images VSCO https://vsco.co/ Collections, individual Images, User Profiles -Wallhaven https://wallhaven.cc/ individual Images, Search Results `API Key `__ +Wallhaven https://wallhaven.cc/ Collections, individual Images, Search Results `API Key `__ Warosu https://warosu.org/ Threads Weasyl https://www.weasyl.com/ Favorites, Folders, Journals, Submissions `API Key `__ Webtoon https://www.webtoons.com/ Comics, Episodes diff --git a/gallery_dl/extractor/wallhaven.py b/gallery_dl/extractor/wallhaven.py index 150ed5d6..ed201b44 100644 --- a/gallery_dl/extractor/wallhaven.py +++ b/gallery_dl/extractor/wallhaven.py @@ -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)