mirror of
https://codeberg.org/SimpleWeb/SimpleerTube.git
synced 2024-11-22 00:21:30 +00:00
Add simple global search
This commit is contained in:
parent
109da9e9a4
commit
7c4c121ddb
20
main.py
20
main.py
|
@ -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>/")
|
||||||
|
|
|
@ -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')
|
||||||
|
|
|
@ -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>
|
36
templates/simpleer_search_results.html
Normal file
36
templates/simpleer_search_results.html
Normal 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>
|
Loading…
Reference in a new issue