mirror of
https://github.com/searxng/searxng.git
synced 2024-11-26 21:01:01 +00:00
Improve peertube searching
At the moment videos without a description are not shown - setting default content to "" fixes this. Another current bug is that thumbnails are not displayed. This is caused by a double slash in the url. For this every trailing slash is now stripped (for backwards compatibility) and the API response is correctly parsed.
This commit is contained in:
parent
aef1161633
commit
fbbd4cc21f
1 changed files with 10 additions and 8 deletions
|
@ -21,14 +21,15 @@ about = {
|
||||||
# engine dependent config
|
# engine dependent config
|
||||||
categories = ["videos"]
|
categories = ["videos"]
|
||||||
paging = True
|
paging = True
|
||||||
base_url = "https://peer.tube/"
|
base_url = "https://peer.tube"
|
||||||
supported_languages_url = base_url + "api/v1/videos/languages"
|
supported_languages_url = base_url + "/api/v1/videos/languages"
|
||||||
|
|
||||||
|
|
||||||
# do search-request
|
# do search-request
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
|
sanitized_url = base_url.rstrip("/")
|
||||||
pageno = (params["pageno"] - 1) * 15
|
pageno = (params["pageno"] - 1) * 15
|
||||||
search_url = base_url + "api/v1/search/videos/?pageno={pageno}&{query}"
|
search_url = sanitized_url + "/api/v1/search/videos/?pageno={pageno}&{query}"
|
||||||
query_dict = {"search": query}
|
query_dict = {"search": query}
|
||||||
language = params["language"].split("-")[0]
|
language = params["language"].split("-")[0]
|
||||||
# pylint: disable=undefined-variable
|
# pylint: disable=undefined-variable
|
||||||
|
@ -46,6 +47,7 @@ def _get_offset_from_pageno(pageno):
|
||||||
|
|
||||||
# get response from search-request
|
# get response from search-request
|
||||||
def response(resp):
|
def response(resp):
|
||||||
|
sanitized_url = base_url.rstrip("/")
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
search_res = loads(resp.text)
|
search_res = loads(resp.text)
|
||||||
|
@ -53,7 +55,7 @@ def response(resp):
|
||||||
embedded_url = (
|
embedded_url = (
|
||||||
'<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" '
|
'<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" '
|
||||||
+ 'src="'
|
+ 'src="'
|
||||||
+ base_url
|
+ sanitized_url
|
||||||
+ '{embed_path}" frameborder="0" allowfullscreen></iframe>'
|
+ '{embed_path}" frameborder="0" allowfullscreen></iframe>'
|
||||||
)
|
)
|
||||||
# return empty array if there are no results
|
# return empty array if there are no results
|
||||||
|
@ -63,15 +65,15 @@ def response(resp):
|
||||||
# parse results
|
# parse results
|
||||||
for res in search_res["data"]:
|
for res in search_res["data"]:
|
||||||
title = res["name"]
|
title = res["name"]
|
||||||
url = base_url + "/videos/watch/" + res["uuid"]
|
url = sanitized_url + "/videos/watch/" + res["uuid"]
|
||||||
description = res["description"]
|
description = res["description"]
|
||||||
if description:
|
if description:
|
||||||
content = html_to_text(res["description"])
|
content = html_to_text(res["description"])
|
||||||
else:
|
else:
|
||||||
content = None
|
content = ""
|
||||||
thumbnail = base_url + res["thumbnailPath"]
|
thumbnail = sanitized_url + res["thumbnailPath"]
|
||||||
publishedDate = datetime.strptime(res["publishedAt"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
publishedDate = datetime.strptime(res["publishedAt"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
embedded = embedded_url.format(embed_path=res["embedPath"][1:])
|
embedded = embedded_url.format(embed_path=res["embedPath"])
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue