Update, improved style and fix comments showing raw HTML

This commit is contained in:
metalune 2021-03-24 18:43:50 +01:00
parent 21df015a3a
commit 3692b57942
4 changed files with 18 additions and 3 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
__pycache__/

15
main.py
View file

@ -2,6 +2,10 @@ from quart import Quart, request, render_template, redirect
from datetime import datetime from datetime import datetime
from math import ceil from math import ceil
import peertube import peertube
import html2text
h2t = html2text.HTML2Text()
h2t.ignore_links = True
commit = "not found" commit = "not found"
with open(".git/refs/heads/main") as file: with open(".git/refs/heads/main") as file:
@ -241,7 +245,6 @@ async def search(domain, term, page):
pages_total=(results["total"] / 10) pages_total=(results["total"] / 10)
) )
@app.route("/<string:domain>/videos/watch/<string:id>/") @app.route("/<string:domain>/videos/watch/<string:id>/")
async def video(domain, id): async def video(domain, id):
data = peertube.video(domain, id) data = peertube.video(domain, id)
@ -256,6 +259,16 @@ async def video(domain, id):
if data["commentsEnabled"]: if data["commentsEnabled"]:
comments = peertube.get_comments(domain, id) comments = peertube.get_comments(domain, id)
# Strip the HTML from the comments and convert them to plain text
new_comments = {"total": comments["total"], "data": []}
for comment in comments["data"]:
text = h2t.handle(comment["text"]).strip().strip("\n")
comment["text"] = text
new_comments["data"].append(comment)
comments = new_comments
return await render_template( return await render_template(
"video.html", "video.html",
domain=domain, domain=domain,

View file

@ -7,7 +7,8 @@
{% endblock %} {% endblock %}
</head> </head>
<body> <!-- I know that inline CSS is not .. the best, but I'll move it to an external file for sure! definitely! -->
<body style="max-width: 800px; margin: 10px auto; padding-left: 5px; padding-right: 5px">
<form action="/{{ domain }}/search" method="POST"> <form action="/{{ domain }}/search" method="POST">
<label for="query"><b>{{ instance_name }}</b></label> <label for="query"><b>{{ instance_name }}</b></label>
<input type="text" name="query" id="query" placeholder="Search" value="{{ search_term }}"/> <input type="text" name="query" id="query" placeholder="Search" value="{{ search_term }}"/>

View file

@ -22,7 +22,7 @@ By:
<b>Resolutions:</b> <b>Resolutions:</b>
{% else %} {% else %}
<video height="300" controls> <video height="300" controls>
<source src="{{ video.video }}"> <source src="{{ video.video }}">
</video> </video>
<br> <br>
<b>Resolutions:</b> <b>Resolutions:</b>