[feat] engine: implementation of Piped

This commit is contained in:
Bnyro 2023-07-18 08:14:26 +02:00 committed by Markus Heiser
parent 8b4ba204b7
commit 636bfdac68
2 changed files with 78 additions and 0 deletions

65
searx/engines/piped.py Normal file
View file

@ -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

View file

@ -1135,6 +1135,19 @@ engines:
engine: photon engine: photon
shortcut: ph 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 - name: piratebay
engine: piratebay engine: piratebay
shortcut: tpb shortcut: tpb