From b348dc79b9923845cd9ffab4f0a29cb83750a926 Mon Sep 17 00:00:00 2001 From: Hackurei <138650713+Hackurei@users.noreply.github.com> Date: Thu, 14 Sep 2023 20:45:57 -0600 Subject: [PATCH] add pixiv engine --- searx/engines/pixiv.py | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 searx/engines/pixiv.py diff --git a/searx/engines/pixiv.py b/searx/engines/pixiv.py new file mode 100644 index 000000000..741c9c656 --- /dev/null +++ b/searx/engines/pixiv.py @@ -0,0 +1,65 @@ +import httpx +from urllib.parse import urlencode +from datetime import datetime + +# Engine metadata +about = { + "website": "https://www.pixiv.net/", + "wikidata_id": None, + "official_api_documentation": None, + "use_official_api": False, + "require_api_key": False, + "results": "JSON", +} + +# Engine configuration +paging = True +categories = ['images'] + +# Search URL +base_url = "https://www.pixiv.net/ajax/search/illustrations" + + +def request(query, params): + page_number = params.get("pageno", 1) + query_params = { + "word": query, + "order": "date_d", + "mode": "all", + "p": page_number, + "s_mode": "s_tag_full", + "type": "illust_and_ugoira", + "lang": "en", + } + + with httpx.Client() as client: + response = client.get(f"{base_url}/{query}?{urlencode(query_params)}") + params["url"] = response.url + + return params + + +def format_results(item): + title = item["title"] + url = item["url"] + user_id = item["userId"] + user_name = item["userName"] + image_url = item["url"] + + + return { + "title": title, + "url": image_url, + "author": f"{user_name} (ID: {user_id})", + "img_src": image_url, + "source": 'pixiv.net', + "template": "images.html", + } + + +def response(resp): + data = resp.json() + illustrations = data["body"]["illust"]["data"] + results = [format_results(item) for item in illustrations] + + return results \ No newline at end of file