summaryrefslogtreecommitdiff
path: root/searx/engines/pixiv.py
diff options
context:
space:
mode:
authorAustin-Olacsi <138650713+Austin-Olacsi@users.noreply.github.com>2024-02-08 18:04:45 -0700
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-02-25 16:29:57 +0100
commit9330a072eb91921d9eb5eeb8bc5414dc2c357978 (patch)
tree61bda713ec3b15a529d748dc41b9463a0d0e148d /searx/engines/pixiv.py
parentcf57914359fbe680fd29b770533f4c55f23d42a8 (diff)
downloadsearxng-9330a072eb91921d9eb5eeb8bc5414dc2c357978.tar.gz
searxng-9330a072eb91921d9eb5eeb8bc5414dc2c357978.zip
[feat] engine: implementation of pixiv
Diffstat (limited to 'searx/engines/pixiv.py')
-rw-r--r--searx/engines/pixiv.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/searx/engines/pixiv.py b/searx/engines/pixiv.py
new file mode 100644
index 000000000..fdb74e818
--- /dev/null
+++ b/searx/engines/pixiv.py
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""Pixiv (images)"""
+
+from urllib.parse import urlencode
+import random
+
+# Engine metadata
+about = {
+ "website": 'https://www.pixiv.net/',
+ "wikidata_id": 'Q306956',
+ "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"
+pixiv_image_proxies: list = []
+
+
+def request(query, params):
+ query_params = {
+ "word": query,
+ "order": "date_d",
+ "mode": "all",
+ "p": params["pageno"],
+ "s_mode": "s_tag_full",
+ "type": "illust_and_ugoira",
+ "lang": "en",
+ }
+
+ params["url"] = f"{base_url}/{query}?{urlencode(query_params)}"
+
+ return params
+
+
+def response(resp):
+ results = []
+ data = resp.json()
+
+ for item in data["body"]["illust"]["data"]:
+
+ image_url = item["url"]
+ pixiv_proxy = random.choice(pixiv_image_proxies)
+ proxy_image_url = image_url.replace("https://i.pximg.net", pixiv_proxy)
+ proxy_full_image_url = (
+ proxy_image_url.replace("/c/250x250_80_a2/", "/")
+ .replace("_square1200.jpg", "_master1200.jpg")
+ .replace("custom-thumb", "img-master")
+ .replace("_custom1200.jpg", "_master1200.jpg")
+ )
+
+ results.append(
+ {
+ "title": item.get("title"),
+ "url": proxy_full_image_url,
+ 'content': item.get('alt'),
+ "author": f"{item.get('userName')} (ID: {item.get('userId')})",
+ "img_src": proxy_full_image_url,
+ "thumbnail_src": proxy_image_url,
+ "source": 'pixiv.net',
+ "template": "images.html",
+ }
+ )
+
+ return results