summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-12-15 12:25:56 +0100
committerMarkus Heiser <markus.heiser@darmarIT.de>2025-01-20 17:22:32 +0100
commitf766faca3fa48a8c2fe65d4a72f318857a01dbd5 (patch)
treefc4788f182c59304196d3d111dce968a7ee3aafc
parentc020a964e4bcbe1c9a543f45ba40ae549b5b5373 (diff)
[feat] engines: add ipernity (images)
-rw-r--r--searx/engines/ipernity.py76
-rw-r--r--searx/settings.yml5
2 files changed, 81 insertions, 0 deletions
diff --git a/searx/engines/ipernity.py b/searx/engines/ipernity.py
new file mode 100644
index 000000000..6e5eb7872
--- /dev/null
+++ b/searx/engines/ipernity.py
@@ -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
diff --git a/searx/settings.yml b/searx/settings.yml
index da9c8174f..46de5d855 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -1072,6 +1072,11 @@ engines:
timeout: 3.0
disabled: true
+ - name: ipernity
+ engine: ipernity
+ shortcut: ip
+ disabled: true
+
- name: jisho
engine: jisho
shortcut: js