From 7dc316c39e76197477b03a694aa096bb983b743b Mon Sep 17 00:00:00 2001 From: metalune Date: Sun, 18 Jul 2021 11:13:45 +0200 Subject: [PATCH] Pick a resolution by default --- main.py | 19 +++++++++++++++++-- templates/video.html | 14 +++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index fe7b43c..be65f29 100644 --- a/main.py +++ b/main.py @@ -35,13 +35,29 @@ class VideoWrapper: if len(self.files) == 0: self.files = ((a["streamingPlaylists"])[0])["files"] + self.default_res = None + for entry in self.files: resolution = (entry["resolution"])["id"] self.resolutions.append(entry["resolution"]) + # chose the default quality + if resolution != 0 and quality == None: + if self.default_res == None: + self.default_res = resolution + self.video = entry["fileUrl"] + elif abs(720 - resolution) < abs(720 - self.default_res): + self.default_res = resolution + self.video = entry["fileUrl"] + if str(resolution) == str(quality): self.video = entry["fileUrl"] + if quality == None: + self.quality = self.default_res + else: + self.quality = quality + self.no_quality_selected = not self.video @@ -236,9 +252,8 @@ async def video(domain, id): data = peertube.video(domain, id) quality = request.args.get("quality") embed = request.args.get("embed") - if quality == None: - quality = "best" vid = VideoWrapper(data, quality) + quality = int(vid.quality) # only make a request for the comments if commentsEnabled comments = "" diff --git a/templates/video.html b/templates/video.html index 563b01a..80c6b90 100644 --- a/templates/video.html +++ b/templates/video.html @@ -29,10 +29,18 @@ By: {% endif %} {% for resolution in video.resolutions %} - {% if resolution.label == "0p" %} - Audio Only + {% if resolution.id == quality %} + {% if resolution.label == "0p" %} + [Audio Only] + {% else %} + [{{ resolution.label }}] + {% endif %} {% else %} - {{ resolution.label }} + {% if resolution.label == "0p" %} + Audio Only + {% else %} + {{ resolution.label }} + {% endif %} {% endif %} {% endfor %} Embedded