From 636bfdac68320bbaf86d7153f35af85d050c9d60 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 18 Jul 2023 08:14:26 +0200 Subject: [PATCH] [feat] engine: implementation of Piped --- searx/engines/piped.py | 65 ++++++++++++++++++++++++++++++++++++++++++ searx/settings.yml | 13 +++++++++ 2 files changed, 78 insertions(+) create mode 100644 searx/engines/piped.py 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