on master help sign in
Improve peertube searching
fbbd4ccThorben Günther
searx/engines/peertube.py+10−8
@@ -21,14 +21,15 @@ about = {
21# engine dependent config
21# engine dependent config
22categories = ["videos"]
22categories = ["videos"]
23paging = True
23paging = True
24−base_url = "https://peer.tube/"
24+base_url = "https://peer.tube"
25−supported_languages_url = base_url + "api/v1/videos/languages"
25+supported_languages_url = base_url + "/api/v1/videos/languages"
26
26
27
27
28# do search-request
28# do search-request
29def request(query, params):
29def request(query, params):
30+ sanitized_url = base_url.rstrip("/")
30 pageno = (params["pageno"] - 1) * 15
31 pageno = (params["pageno"] - 1) * 15
31− search_url = base_url + "api/v1/search/videos/?pageno={pageno}&{query}"
32+ search_url = sanitized_url + "/api/v1/search/videos/?pageno={pageno}&{query}"
32 query_dict = {"search": query}
33 query_dict = {"search": query}
33 language = params["language"].split("-")[0]
34 language = params["language"].split("-")[0]
34 # pylint: disable=undefined-variable
35 # pylint: disable=undefined-variable
@@ -46,6 +47,7 @@ def _get_offset_from_pageno(pageno):
46
47
47# get response from search-request
48# get response from search-request
48def response(resp):
49def response(resp):
50+ sanitized_url = base_url.rstrip("/")
49 results = []
51 results = []
50
52
51 search_res = loads(resp.text)
53 search_res = loads(resp.text)
@@ -53,7 +55,7 @@ def response(resp):
53 embedded_url = (
55 embedded_url = (
54 '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" '
56 '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" '
55 + 'src="'
57 + 'src="'
56− + base_url
58+ + sanitized_url
57 + '{embed_path}" frameborder="0" allowfullscreen></iframe>'
59 + '{embed_path}" frameborder="0" allowfullscreen></iframe>'
58 )
60 )
59 # return empty array if there are no results
61 # return empty array if there are no results
@@ -63,15 +65,15 @@ def response(resp):
63 # parse results
65 # parse results
64 for res in search_res["data"]:
66 for res in search_res["data"]:
65 title = res["name"]
67 title = res["name"]
66− url = base_url + "/videos/watch/" + res["uuid"]
68+ url = sanitized_url + "/videos/watch/" + res["uuid"]
67 description = res["description"]
69 description = res["description"]
68 if description:
70 if description:
69 content = html_to_text(res["description"])
71 content = html_to_text(res["description"])
70 else:
72 else:
71− content = None
73+ content = ""
72− thumbnail = base_url + res["thumbnailPath"]
74+ thumbnail = sanitized_url + res["thumbnailPath"]
73 publishedDate = datetime.strptime(res["publishedAt"], "%Y-%m-%dT%H:%M:%S.%fZ")
75 publishedDate = datetime.strptime(res["publishedAt"], "%Y-%m-%dT%H:%M:%S.%fZ")
74− embedded = embedded_url.format(embed_path=res["embedPath"][1:])
76+ embedded = embedded_url.format(embed_path=res["embedPath"])
75
77
76 results.append(
78 results.append(
77 {
79 {