From 3692b57942960b5901729fb441b81ed878f12a7f Mon Sep 17 00:00:00 2001 From: metalune Date: Wed, 24 Mar 2021 18:43:50 +0100 Subject: [PATCH] Update, improved style and fix comments showing raw HTML --- .gitignore | 1 + main.py | 15 ++++++++++++++- templates/base.html | 3 ++- templates/video.html | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/main.py b/main.py index f071caa..f524213 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,10 @@ from quart import Quart, request, render_template, redirect from datetime import datetime from math import ceil import peertube +import html2text + +h2t = html2text.HTML2Text() +h2t.ignore_links = True commit = "not found" with open(".git/refs/heads/main") as file: @@ -241,7 +245,6 @@ async def search(domain, term, page): pages_total=(results["total"] / 10) ) - @app.route("//videos/watch//") async def video(domain, id): data = peertube.video(domain, id) @@ -256,6 +259,16 @@ async def video(domain, id): if data["commentsEnabled"]: 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( "video.html", domain=domain, diff --git a/templates/base.html b/templates/base.html index cfdfa79..92432bd 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,7 +7,8 @@ {% endblock %} - + +
diff --git a/templates/video.html b/templates/video.html index fc33e46..5f14dca 100644 --- a/templates/video.html +++ b/templates/video.html @@ -22,7 +22,7 @@ By: Resolutions: {% else %}
Resolutions: