From 0e44673dc6511272682f6e3f58f23eb34462e170 Mon Sep 17 00:00:00 2001 From: metalune Date: Thu, 21 Jan 2021 10:30:26 +0100 Subject: [PATCH] Only send get_comments requests if comments are enabled --- main.py | 8 ++++++- templates/video.html | 54 ++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index ebd8530..0925405 100644 --- a/main.py +++ b/main.py @@ -28,6 +28,7 @@ class VideoWrapper: self.dislikes = a["dislikes"] self.embedPath = a["embedPath"] + self.commentsEnabled = a["commentsEnabled"] self.resolutions = [] self.video = None @@ -92,11 +93,16 @@ async def video(domain, id): quality = "best" vid = VideoWrapper(data, quality) + # only make a request for the comments if commentsEnabled + comments = "" + if data["commentsEnabled"]: + comments = peertube.get_comments(domain, id) + return await render_template( "video.html", domain=domain, video=vid, - comments=peertube.get_comments(domain, id), + comments=comments, quality=quality, embed=embed, commit=commit, diff --git a/templates/video.html b/templates/video.html index e10bc09..bb85b50 100644 --- a/templates/video.html +++ b/templates/video.html @@ -65,32 +65,36 @@ Views: {{ video.views }} Likes: {{ video.likes }} Dislikes: {{


-{{ comments.total }} Comments -
-
-{% for comment in comments.data %} +{% if video.commentsEnabled %} + {{ comments.total }} Comments +
+
+ {% for comment in comments.data %} - {% if not comment.isDeleted %} - {{ comment.account.displayName }} -
- {{ comment.text }} -
- {% else %} -
- Unknown + {% if not comment.isDeleted %} + {{ comment.account.displayName }}
- Deleted Comment -
- {% endif %} - - {% if comment.totalReplies == 1 %} - 1 Reply - {% else %} - {{ comment.totalReplies }} Replies - {% endif %} - -
-
-{% endfor %} + {{ comment.text }} +
+ {% else %} +
+ Unknown +
+ Deleted Comment +
+ {% endif %} + + {% if comment.totalReplies == 1 %} + 1 Reply + {% else %} + {{ comment.totalReplies }} Replies + {% endif %} + +
+
+ {% endfor %} +{% else %} +Comments disabled. +{% endif %} {% endblock %}