Pick a resolution by default

This commit is contained in:
metalune 2021-07-18 11:13:45 +02:00
parent 3794cf09a2
commit 7dc316c39e
2 changed files with 28 additions and 5 deletions

19
main.py
View File

@ -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 = ""

View File

@ -29,11 +29,19 @@ By:
{% endif %}
{% for resolution in video.resolutions %}
{% if resolution.id == quality %}
{% if resolution.label == "0p" %}
[<a href="?quality={{ resolution.id }}">Audio Only</a>]
{% else %}
[<a href="?quality={{ resolution.id }}">{{ resolution.label }}</a>]
{% endif %}
{% else %}
{% if resolution.label == "0p" %}
<a href="?quality={{ resolution.id }}">Audio Only</a>
{% else %}
<a href="?quality={{ resolution.id }}">{{ resolution.label }}</a>
{% endif %}
{% endif %}
{% endfor %}
<a href="?embed=1">Embedded</a>