Add embed and fix some videos not playing

This commit is contained in:
metalune 2021-01-19 15:24:28 +01:00
parent 104a36deea
commit c778a9147d
2 changed files with 24 additions and 4 deletions

12
main.py
View file

@ -19,10 +19,17 @@ class VideoWrapper:
self.likes = a["likes"] self.likes = a["likes"]
self.dislikes = a["dislikes"] self.dislikes = a["dislikes"]
self.embedPath = a["embedPath"]
self.resolutions = [] self.resolutions = []
self.video = None self.video = None
for entry in a["files"]: self.files = a["files"]
if len(self.files) == 0:
self.files = ((a["streamingPlaylists"])[0])["files"]
for entry in self.files:
resolution = (entry["resolution"])["id"] resolution = (entry["resolution"])["id"]
self.resolutions.append(entry["resolution"]) self.resolutions.append(entry["resolution"])
@ -67,11 +74,12 @@ async def search(domain, term):
async def video(domain, id): 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")
if quality == None: if quality == None:
quality = "best" quality = "best"
vid = VideoWrapper(data, quality) vid = VideoWrapper(data, quality)
return await render_template("video.html", video=vid, quality=quality) return await render_template("video.html", video=vid, quality=quality, embed=embed)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -5,9 +5,12 @@
By: By:
<b>{{ video.channel.displayName }}</b> ({{ video.channel.name }}@{{ video.channel.host }}) <b>{{ video.channel.displayName }}</b> ({{ video.channel.name }}@{{ video.channel.host }})
<br> <br>
{% if video.no_quality_selected %} {% if video.no_quality_selected and not embed %}
<img height="300" src="https://{{ video.channel.host }}{{ video.thumbnailPath }}"> <img height="300" src="https://{{ video.channel.host }}{{ video.thumbnailPath }}">
<p style="color: red">Please select a resolution:</p> <p style="color: red">Please select a resolution:</p>
{% elif embed %}
<embed height="300" src="https://{{ video.channel.host }}{{ video.embedPath }}">
<br>
{% else %} {% else %}
<video height="300" controls> <video height="300" controls>
<source src="{{ video.video }}"> <source src="{{ video.video }}">
@ -19,6 +22,7 @@
{% for resolution in video.resolutions %} {% for resolution in video.resolutions %}
<a href="?quality={{ resolution.id }}">{{ resolution.label }}</a> <a href="?quality={{ resolution.id }}">{{ resolution.label }}</a>
{% endfor %} {% endfor %}
<a href="?embed=1">Embedded</a>
<br> <br>
Views: <b>{{ video.views }}</b> Likes: <b>{{ video.likes }}</b> Dislikes: <b>{{ video.dislikes }}</b> Views: <b>{{ video.views }}</b> Likes: <b>{{ video.likes }}</b> Dislikes: <b>{{ video.dislikes }}</b>
@ -46,6 +50,14 @@
<td><b>Privacy</b></td> <td><b>Privacy</b></td>
<td>{{ video.privacy.label }}</td> <td>{{ video.privacy.label }}</td>
</tr> </tr>
<tr>
<td><b>Tags</b></td>
<td>
{% for tag in video.tags %}
{{ tag }}
{% endfor %}
</td>
</tr>
</table> </table>
</body> </body>
</html> </html>