Add simple global search

This commit is contained in:
metalune 2021-01-22 05:08:04 +01:00
parent 109da9e9a4
commit 7c4c121ddb
4 changed files with 79 additions and 1 deletions

20
main.py
View file

@ -105,7 +105,25 @@ app = Quart(__name__)
@app.route("/") @app.route("/")
async def main(): async def main():
return await render_template("index.html") return await render_template(
"index.html",
commit=commit,
)
@app.route("/search", methods = ["POST"])
async def simpleer_search_redirect():
query = (await request.form)["query"]
return redirect("/search/" + query)
@app.route("/search/<string:query>")
async def simpleer_search(query):
return await render_template(
"simpleer_search_results.html",
commit=commit,
results=peertube.sepia_search(query)
)
@app.route("/<string:domain>/") @app.route("/<string:domain>/")

View file

@ -2,6 +2,14 @@ from bs4 import BeautifulSoup
import requests import requests
import json import json
# --- Sepiasearch ---
def sepia_search(query):
url = "https://search.joinpeertube.org/api/v1/search/videos?search=" + query
return json.loads(requests.get(url).text)
# --- ----
def get_instance_name(domain): def get_instance_name(domain):
soup = BeautifulSoup(requests.get("https://" + domain).text, "lxml") soup = BeautifulSoup(requests.get("https://" + domain).text, "lxml")
title = soup.find('title') title = soup.find('title')

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<title>SimpleerTube - Search</title>
</head>
<body>
<form action="/search" method="POST">
<label for="query"><b>SimpleerTube</b></label>
<input type="text" name="query" id="query" placeholder="Search"/>
<button type="submit">Search</button>
</form>
<footer>
<a href="https://codeberg.org/simple-web/peertube/src/commit/{{ commit }}">Commit: {{ commit }}</a>
</footer>
</body>
</html>

View file

@ -0,0 +1,36 @@
<!doctype html>
<html>
<head>
<title>SimpleerTube - Search Results</title>
</head>
<body>
<form action="/search" method="POST">
<label for="query"><b>SimpleerTube</b></label>
<input type="text" name="query" id="query" placeholder="Search"/>
<button type="submit">Search</button>
</form>
<br>
<br>
{{ results.total }} Results
<table>
{% for result in results.data %}
<tr>
<td>
<img src="{{ result.thumbnailUrl }}" height="150"/>
</td>
<td>
<a href="/{{ result.channel.host }}/videos/watch/{{ result.uuid }}">
{{ result.name }}
</a>
<br>
{{ result.views }} Views
<br>
</td>
</tr>
{% endfor %}
</table>
<footer>
<a href="https://codeberg.org/simple-web/peertube/src/commit/{{ commit }}">Commit: {{ commit }}</a>
</footer>
</body>
</html>