[wallhaven] implement 'metadata' option (#2803)
This commit is contained in:
@@ -2538,6 +2538,18 @@ Description
|
||||
See https://wallhaven.cc/help/api for more information.
|
||||
|
||||
|
||||
extractor.wallhaven.metadata
|
||||
----------------------------
|
||||
Type
|
||||
``bool``
|
||||
Default
|
||||
``false``
|
||||
Description
|
||||
Extract additional metadata (tags, uploader)
|
||||
|
||||
Note: This requires 1 additional HTTP request for each post.
|
||||
|
||||
|
||||
extractor.weasyl.api-key
|
||||
------------------------
|
||||
Type
|
||||
|
||||
@@ -313,7 +313,8 @@
|
||||
},
|
||||
"wallhaven":
|
||||
{
|
||||
"api-key": null
|
||||
"api-key": null,
|
||||
"metadata": false
|
||||
},
|
||||
"weasyl":
|
||||
{
|
||||
|
||||
@@ -189,7 +189,7 @@ class WallhavenAPI():
|
||||
|
||||
def collections(self, username):
|
||||
endpoint = "/v1/collections/" + username
|
||||
return self._pagination(endpoint)
|
||||
return self._pagination(endpoint, metadata=False)
|
||||
|
||||
def search(self, params):
|
||||
endpoint = "/v1/search"
|
||||
@@ -200,13 +200,20 @@ class WallhavenAPI():
|
||||
return self.extractor.request(
|
||||
url, headers=self.headers, params=params).json()
|
||||
|
||||
def _pagination(self, endpoint, params=None):
|
||||
def _pagination(self, endpoint, params=None, metadata=None):
|
||||
if params is None:
|
||||
params = {}
|
||||
if metadata is None:
|
||||
metadata = self.extractor.config("metadata")
|
||||
|
||||
while True:
|
||||
data = self._call(endpoint, params)
|
||||
yield from data["data"]
|
||||
|
||||
if metadata:
|
||||
for wp in data["data"]:
|
||||
yield self.info(str(wp["id"]))
|
||||
else:
|
||||
yield from data["data"]
|
||||
|
||||
meta = data.get("meta")
|
||||
if not meta or meta["current_page"] >= meta["last_page"]:
|
||||
|
||||
Reference in New Issue
Block a user