[wallhaven] implement 'metadata' option (#2803)

This commit is contained in:
Mike Fährmann
2022-08-08 21:46:36 +02:00
parent c0051d7d4c
commit a69f198ac9
3 changed files with 24 additions and 4 deletions

View File

@@ -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

View File

@@ -313,7 +313,8 @@
},
"wallhaven":
{
"api-key": null
"api-key": null,
"metadata": false
},
"weasyl":
{

View File

@@ -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"]: