diff options
| author | 2022-11-22 04:28:38 -0500 | |
|---|---|---|
| committer | 2022-11-22 04:28:38 -0500 | |
| commit | 7af5cc29d1c02d20a6890b7b7ba78ab41532a763 (patch) | |
| tree | 4f0366e5653074c7eb31ac7ca59a1ee55f2d736e /gallery_dl/extractor/wallhaven.py | |
| parent | e59d46ecda74190381b1d2725b0bd9df5c0be8d8 (diff) | |
New upstream version 1.24.0.upstream/1.24.0
Diffstat (limited to 'gallery_dl/extractor/wallhaven.py')
| -rw-r--r-- | gallery_dl/extractor/wallhaven.py | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/gallery_dl/extractor/wallhaven.py b/gallery_dl/extractor/wallhaven.py index 47451bd..06f1aab 100644 --- a/gallery_dl/extractor/wallhaven.py +++ b/gallery_dl/extractor/wallhaven.py @@ -19,6 +19,10 @@ class WallhavenExtractor(Extractor): archive_fmt = "{id}" root = "https://wallhaven.cc" + def __init__(self, match): + Extractor.__init__(self, match) + self.api = WallhavenAPI(self) + def items(self): metadata = self.metadata() for wp in self.wallpapers(): @@ -57,7 +61,8 @@ class WallhavenSearchExtractor(WallhavenExtractor): ("https://wallhaven.cc/search?q=touhou"), (("https://wallhaven.cc/search?q=id%3A87" "&categories=111&purity=100&sorting=date_added&order=asc&page=3"), { - "pattern": r"https://w.wallhaven.cc/full/\w\w/wallhaven-\w+\.\w+", + "pattern": (r"https://w\.wallhaven\.cc" + r"/full/\w\w/wallhaven-\w+\.\w+"), "count": "<= 30", }), ) @@ -67,7 +72,7 @@ class WallhavenSearchExtractor(WallhavenExtractor): self.params = text.parse_query(match.group(1)) def wallpapers(self): - return WallhavenAPI(self).search(self.params.copy()) + return self.api.search(self.params.copy()) def metadata(self): return {"search": self.params} @@ -87,12 +92,30 @@ class WallhavenCollectionExtractor(WallhavenExtractor): self.username, self.collection_id = match.groups() def wallpapers(self): - return WallhavenAPI(self).collection(self.username, self.collection_id) + return self.api.collection(self.username, self.collection_id) def metadata(self): return {"username": self.username, "collection_id": self.collection_id} +class WallhavenUserExtractor(WallhavenExtractor): + """Extractor for a wallhaven user""" + subcategory = "user" + pattern = r"(?:https?://)?wallhaven\.cc/user/([^/?#]+)/?$" + test = ("https://wallhaven.cc/user/AksumkA/",) + + def __init__(self, match): + WallhavenExtractor.__init__(self, match) + self.username = match.group(1) + + def items(self): + base = "{}/user/{}/".format(self.root, self.username) + return self._dispatch_extractors(( + (WallhavenUploadsExtractor , base + "uploads"), + (WallhavenCollectionsExtractor, base + "favorites"), + ), ("uploads",)) + + class WallhavenCollectionsExtractor(WallhavenExtractor): """Extractor for all collections of a wallhaven user""" subcategory = "collections" @@ -107,13 +130,38 @@ class WallhavenCollectionsExtractor(WallhavenExtractor): self.username = match.group(1) def items(self): - for collection in WallhavenAPI(self).collections(self.username): + for collection in self.api.collections(self.username): collection["_extractor"] = WallhavenCollectionExtractor url = "https://wallhaven.cc/user/{}/favorites/{}".format( self.username, collection["id"]) yield Message.Queue, url, collection +class WallhavenUploadsExtractor(WallhavenExtractor): + """Extractor for all uploads of a wallhaven user""" + subcategory = "uploads" + directory_fmt = ("{category}", "{username}") + archive_fmt = "u_{username}_{id}" + pattern = r"(?:https?://)?wallhaven\.cc/user/([^/?#]+)/uploads" + test = ("https://wallhaven.cc/user/AksumkA/uploads", { + "pattern": (r"https://[^.]+\.wallhaven\.cc" + r"/full/\w\w/wallhaven-\w+\.\w+"), + "range": "1-100", + "count": 100, + }) + + def __init__(self, match): + WallhavenExtractor.__init__(self, match) + self.username = match.group(1) + + def wallpapers(self): + params = {"q": "@" + self.username} + return self.api.search(params.copy()) + + def metadata(self): + return {"username": self.username} + + class WallhavenImageExtractor(WallhavenExtractor): """Extractor for individual wallpaper on wallhaven.cc""" subcategory = "image" @@ -121,7 +169,8 @@ class WallhavenImageExtractor(WallhavenExtractor): r"|w\.wallhaven\.cc/[a-z]+/\w\w/wallhaven-)(\w+)") test = ( ("https://wallhaven.cc/w/01w334", { - "pattern": "https://[^.]+.wallhaven.cc/full/01/[^-]+-01w334.jpg", + "pattern": (r"https://[^.]+\.wallhaven\.cc" + r"/full/01/wallhaven-01w334\.jpg"), "content": "497212679383a465da1e35bd75873240435085a2", "keyword": { "id" : "01w334", @@ -159,7 +208,7 @@ class WallhavenImageExtractor(WallhavenExtractor): self.wallpaper_id = match.group(1) def wallpapers(self): - return (WallhavenAPI(self).info(self.wallpaper_id),) + return (self.api.info(self.wallpaper_id),) class WallhavenAPI(): |
