Browse Source

[feat] engines: add openclipart.org

Bnyro 2 months ago
parent
commit
a51416c7c3
2 changed files with 54 additions and 0 deletions
  1. 47 0
      searx/engines/openclipart.py
  2. 7 0
      searx/settings.yml

+ 47 - 0
searx/engines/openclipart.py

@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+"""OpenClipArt (images)"""
+
+from urllib.parse import urlencode
+from lxml import html
+from searx.utils import extract_text, eval_xpath, eval_xpath_list
+
+about = {
+    "website": 'https://openclipart.org/',
+    "wikidata_id": 'Q979593',
+    "official_api_documentation": None,
+    "use_official_api": False,
+    "require_api_key": False,
+    "results": 'HTML',
+}
+
+categories = ['images']
+paging = True
+
+base_url = "https://openclipart.org"
+
+
+def request(query, params):
+    args = {
+        'query': query,
+        'p': params['pageno'],
+    }
+    params['url'] = f"{base_url}/search/?{urlencode(args)}"
+    return params
+
+
+def response(resp):
+    results = []
+
+    dom = html.fromstring(resp.text)
+
+    for result in eval_xpath_list(dom, "//div[contains(@class, 'gallery')]/div[contains(@class, 'artwork')]"):
+        results.append(
+            {
+                'template': 'images.html',
+                'url': base_url + extract_text(eval_xpath(result, "./a/@href")),
+                'title': extract_text(eval_xpath(result, "./a/img/@alt")),
+                'img_src': base_url + extract_text(eval_xpath(result, "./a/img/@src")),
+            }
+        )
+
+    return results

+ 7 - 0
searx/settings.yml

@@ -1361,6 +1361,13 @@ engines:
       require_api_key: false
       require_api_key: false
       results: JSON
       results: JSON
 
 
+  - name: openclipart
+    engine: openclipart
+    shortcut: ocl
+    inactive: true
+    disabled: true
+    timeout: 30
+
   - name: openlibrary
   - name: openlibrary
     engine: openlibrary
     engine: openlibrary
     shortcut: ol
     shortcut: ol