summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2023-07-18 08:14:26 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2023-08-03 16:23:36 +0200
commit636bfdac68320bbaf86d7153f35af85d050c9d60 (patch)
treeef51e2b142cf797d916b74e37ea4a65871ecf133 /searx
parent8b4ba204b7e6469181a29c9152cc7ec880005b05 (diff)
downloadsearxng-636bfdac68320bbaf86d7153f35af85d050c9d60.tar.gz
searxng-636bfdac68320bbaf86d7153f35af85d050c9d60.zip
[feat] engine: implementation of Piped
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/piped.py65
-rw-r--r--searx/settings.yml13
2 files changed, 78 insertions, 0 deletions
diff --git a/searx/engines/piped.py b/searx/engines/piped.py
new file mode 100644
index 000000000..3a721f9db
--- /dev/null
+++ b/searx/engines/piped.py
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""Piped (Videos)
+"""
+
+import time
+import random
+from urllib.parse import urlencode
+from dateutil import parser
+
+# about
+about = {
+ "website": 'https://github.com/TeamPiped/Piped/',
+ "wikidata_id": 'Q107565255',
+ "official_api_documentation": 'https://docs.piped.video/docs/api-documentation/',
+ "use_official_api": True,
+ "require_api_key": False,
+ "results": 'JSON',
+}
+
+# engine dependent config
+categories = ["videos", "music"]
+paging = False
+
+# search-url
+backend_url = "https://pipedapi.kavin.rocks"
+frontend_url = "https://piped.video"
+
+
+# do search-request
+def request(query, params):
+ if isinstance(backend_url, list):
+ base_url = random.choice(backend_url)
+ else:
+ base_url = backend_url
+
+ search_url = base_url + "/search?{query}&filter=videos"
+ params["url"] = search_url.format(query=urlencode({'q': query}))
+
+ return params
+
+
+# get response from search-request
+def response(resp):
+ results = []
+
+ search_results = resp.json()["items"]
+
+ for result in search_results:
+ publishedDate = parser.parse(time.ctime(result.get("uploaded", 0) / 1000))
+
+ results.append(
+ {
+ # the api url differs from the frontend, hence use piped.video as default
+ "url": frontend_url + result.get("url", ""),
+ "title": result.get("title", ""),
+ "content": result.get("shortDescription", ""),
+ "template": "videos.html",
+ "publishedDate": publishedDate,
+ "iframe_src": frontend_url + '/embed' + result.get("url", ""),
+ "thumbnail": result.get("thumbnail", ""),
+ }
+ )
+
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index 4dd499a36..d2847343a 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -1135,6 +1135,19 @@ engines:
engine: photon
shortcut: ph
+ - name: piped
+ engine: piped
+ # Instance will be selected randomly, for more see https://piped-instances.kavin.rocks/
+ backend_url:
+ - https://pipedapi.kavin.rocks
+ - https://pipedapi-libre.kavin.rocks
+ - https://pipedapi.adminforge.de
+ # Url to use as link, and for embeds
+ frontend_url: https://srv.piped.video
+ shortcut: ppd
+ timeout: 3.0
+ disabled: true
+
- name: piratebay
engine: piratebay
shortcut: tpb