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: if len(self.files) == 0:
self.files = ((a["streamingPlaylists"])[0])["files"] self.files = ((a["streamingPlaylists"])[0])["files"]
self.default_res = None
for entry in self.files: for entry in self.files:
resolution = (entry["resolution"])["id"] resolution = (entry["resolution"])["id"]
self.resolutions.append(entry["resolution"]) 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): if str(resolution) == str(quality):
self.video = entry["fileUrl"] self.video = entry["fileUrl"]
if quality == None:
self.quality = self.default_res
else:
self.quality = quality
self.no_quality_selected = not self.video self.no_quality_selected = not self.video
@ -236,9 +252,8 @@ async def video(domain, id):
data = peertube.video(domain, id) data = peertube.video(domain, id)
quality = request.args.get("quality") quality = request.args.get("quality")
embed = request.args.get("embed") embed = request.args.get("embed")
if quality == None:
quality = "best"
vid = VideoWrapper(data, quality) vid = VideoWrapper(data, quality)
quality = int(vid.quality)
# only make a request for the comments if commentsEnabled # only make a request for the comments if commentsEnabled
comments = "" comments = ""

View file

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