.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
pixiv.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Pixiv (images)"""
3
4from urllib.parse import urlencode
5import random
6
7# Engine metadata
8about = {
9 "website": 'https://www.pixiv.net/',
10 "wikidata_id": 'Q306956',
11 "official_api_documentation": None,
12 "use_official_api": False,
13 "require_api_key": False,
14 "results": 'JSON',
15}
16
17# Engine configuration
18paging = True
19categories = ['images']
20
21# Search URL
22base_url = "https://www.pixiv.net/ajax/search/illustrations"
23pixiv_image_proxies: list = []
24
25
26def request(query, params):
27 query_params = {
28 "word": query,
29 "order": "date_d",
30 "mode": "all",
31 "p": params["pageno"],
32 "s_mode": "s_tag_full",
33 "type": "illust_and_ugoira",
34 "lang": "en",
35 }
36
37 params["url"] = f"{base_url}/{query}?{urlencode(query_params)}"
38
39 return params
40
41
42def response(resp):
43 results = []
44 data = resp.json()
45
46 for item in data["body"]["illust"]["data"]:
47
48 image_url = item["url"]
49 pixiv_proxy = random.choice(pixiv_image_proxies)
50 proxy_image_url = image_url.replace("https://i.pximg.net", pixiv_proxy)
51 proxy_full_image_url = (
52 proxy_image_url.replace("/c/250x250_80_a2/", "/")
53 .replace("_square1200.jpg", "_master1200.jpg")
54 .replace("custom-thumb", "img-master")
55 .replace("_custom1200.jpg", "_master1200.jpg")
56 )
57
58 results.append(
59 {
60 "title": item.get("title"),
61 "url": proxy_full_image_url,
62 'content': item.get('alt'),
63 "author": f"{item.get('userName')} (ID: {item.get('userId')})",
64 "img_src": proxy_full_image_url,
65 "thumbnail_src": proxy_image_url,
66 "source": 'pixiv.net',
67 "template": "images.html",
68 }
69 )
70
71 return results
request(query, params)
Definition pixiv.py:26