mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
[feat] engines: add ipernity (images)
This commit is contained in:
parent
3742d558ac
commit
5ec900141e
2 changed files with 81 additions and 0 deletions
76
searx/engines/ipernity.py
Normal file
76
searx/engines/ipernity.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Ipernity (images)"""
|
||||
|
||||
from datetime import datetime
|
||||
from json import loads, JSONDecodeError
|
||||
|
||||
from urllib.parse import quote_plus
|
||||
from lxml import html
|
||||
|
||||
from searx.utils import extr, extract_text, eval_xpath, eval_xpath_list
|
||||
|
||||
about = {
|
||||
'website': 'https://www.ipernity.com',
|
||||
'official_api_documentation': 'https://www.ipernity.com/help/api',
|
||||
'use_official_api': False,
|
||||
'require_api_key': False,
|
||||
'results': 'HTML',
|
||||
}
|
||||
|
||||
paging = True
|
||||
categories = ['images']
|
||||
|
||||
|
||||
base_url = 'https://www.ipernity.com'
|
||||
page_size = 10
|
||||
|
||||
|
||||
def request(query, params):
|
||||
params['url'] = f"{base_url}/search/photo/@/page:{params['pageno']}:{page_size}?q={quote_plus(query)}"
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
results = []
|
||||
|
||||
doc = html.fromstring(resp.text)
|
||||
|
||||
images = eval_xpath_list(doc, '//a[starts-with(@href, "/doc")]//img')
|
||||
|
||||
result_index = 0
|
||||
for result in eval_xpath_list(doc, '//script[@type="text/javascript"]'):
|
||||
info_js = extr(extract_text(result), '] = ', '};') + '}'
|
||||
|
||||
if not info_js:
|
||||
continue
|
||||
|
||||
try:
|
||||
info_item = loads(info_js)
|
||||
|
||||
if not info_item.get('mediakey'):
|
||||
continue
|
||||
|
||||
thumbnail_src = extract_text(eval_xpath(images[result_index], './@src'))
|
||||
img_src = thumbnail_src.replace('240.jpg', '640.jpg')
|
||||
|
||||
resolution = None
|
||||
if info_item.get("width") and info_item.get("height"):
|
||||
resolution = f'{info_item["width"]}x{info_item["height"]}'
|
||||
|
||||
item = {
|
||||
'template': 'images.html',
|
||||
'url': f"{base_url}/doc/{info_item['user_id']}/{info_item['doc_id']}",
|
||||
'title': info_item.get('title'),
|
||||
'content': info_item.get('content', ''),
|
||||
'resolution': resolution,
|
||||
'publishedDate': datetime.fromtimestamp(int(info_item['posted_at'])),
|
||||
'thumbnail_src': thumbnail_src,
|
||||
'img_src': img_src,
|
||||
}
|
||||
results.append(item)
|
||||
|
||||
result_index += 1
|
||||
except JSONDecodeError:
|
||||
continue
|
||||
|
||||
return results
|
|
@ -1045,6 +1045,11 @@ engines:
|
|||
timeout: 3.0
|
||||
disabled: true
|
||||
|
||||
- name: ipernity
|
||||
engine: ipernity
|
||||
shortcut: ip
|
||||
disabled: true
|
||||
|
||||
- name: jisho
|
||||
engine: jisho
|
||||
shortcut: js
|
||||
|
|
Loading…
Add table
Reference in a new issue