[wallhaven] add 'user' extractor (#3213)

This commit is contained in:
enduser420
2022-11-15 16:55:12 +05:30
committed by GitHub
parent 442b03f7c3
commit 5a68b5cb3c
2 changed files with 38 additions and 7 deletions

View File

@@ -868,7 +868,7 @@ Consider all sites to be NSFW unless otherwise known.
<tr> <tr>
<td>Wallhaven</td> <td>Wallhaven</td>
<td>https://wallhaven.cc/</td> <td>https://wallhaven.cc/</td>
<td>Collections, individual Images, Search Results</td> <td>Collections, individual Images, Search Results, User Profiles</td>
<td><a href="configuration.rst#extractorwallhavenapi-key">API Key</a></td> <td><a href="configuration.rst#extractorwallhavenapi-key">API Key</a></td>
</tr> </tr>
<tr> <tr>

View File

@@ -19,6 +19,10 @@ class WallhavenExtractor(Extractor):
archive_fmt = "{id}" archive_fmt = "{id}"
root = "https://wallhaven.cc" root = "https://wallhaven.cc"
def __init__(self, match):
Extractor.__init__(self, match)
self.api = WallhavenAPI(self)
def items(self): def items(self):
metadata = self.metadata() metadata = self.metadata()
for wp in self.wallpapers(): for wp in self.wallpapers():
@@ -57,7 +61,8 @@ class WallhavenSearchExtractor(WallhavenExtractor):
("https://wallhaven.cc/search?q=touhou"), ("https://wallhaven.cc/search?q=touhou"),
(("https://wallhaven.cc/search?q=id%3A87" (("https://wallhaven.cc/search?q=id%3A87"
"&categories=111&purity=100&sorting=date_added&order=asc&page=3"), { "&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", "count": "<= 30",
}), }),
) )
@@ -67,7 +72,7 @@ class WallhavenSearchExtractor(WallhavenExtractor):
self.params = text.parse_query(match.group(1)) self.params = text.parse_query(match.group(1))
def wallpapers(self): def wallpapers(self):
return WallhavenAPI(self).search(self.params.copy()) return self.api.search(self.params.copy())
def metadata(self): def metadata(self):
return {"search": self.params} return {"search": self.params}
@@ -87,7 +92,7 @@ class WallhavenCollectionExtractor(WallhavenExtractor):
self.username, self.collection_id = match.groups() self.username, self.collection_id = match.groups()
def wallpapers(self): def wallpapers(self):
return WallhavenAPI(self).collection(self.username, self.collection_id) return self.api.collection(self.username, self.collection_id)
def metadata(self): def metadata(self):
return {"username": self.username, "collection_id": self.collection_id} return {"username": self.username, "collection_id": self.collection_id}
@@ -107,13 +112,38 @@ class WallhavenCollectionsExtractor(WallhavenExtractor):
self.username = match.group(1) self.username = match.group(1)
def items(self): def items(self):
for collection in WallhavenAPI(self).collections(self.username): for collection in self.api.collections(self.username):
collection["_extractor"] = WallhavenCollectionExtractor collection["_extractor"] = WallhavenCollectionExtractor
url = "https://wallhaven.cc/user/{}/favorites/{}".format( url = "https://wallhaven.cc/user/{}/favorites/{}".format(
self.username, collection["id"]) self.username, collection["id"])
yield Message.Queue, url, collection yield Message.Queue, url, collection
class WallhavenUserExtractor(WallhavenExtractor):
"""Extractor for all uploads of a wallhaven user"""
subcategory = "user"
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): class WallhavenImageExtractor(WallhavenExtractor):
"""Extractor for individual wallpaper on wallhaven.cc""" """Extractor for individual wallpaper on wallhaven.cc"""
subcategory = "image" subcategory = "image"
@@ -121,7 +151,8 @@ class WallhavenImageExtractor(WallhavenExtractor):
r"|w\.wallhaven\.cc/[a-z]+/\w\w/wallhaven-)(\w+)") r"|w\.wallhaven\.cc/[a-z]+/\w\w/wallhaven-)(\w+)")
test = ( test = (
("https://wallhaven.cc/w/01w334", { ("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", "content": "497212679383a465da1e35bd75873240435085a2",
"keyword": { "keyword": {
"id" : "01w334", "id" : "01w334",
@@ -159,7 +190,7 @@ class WallhavenImageExtractor(WallhavenExtractor):
self.wallpaper_id = match.group(1) self.wallpaper_id = match.group(1)
def wallpapers(self): def wallpapers(self):
return (WallhavenAPI(self).info(self.wallpaper_id),) return (self.api.info(self.wallpaper_id),)
class WallhavenAPI(): class WallhavenAPI():