From 11d67bf7c886e62bf0400dca2715ebb62b01de9c Mon Sep 17 00:00:00 2001 From: Lukas Schauer <lukas@schauer.so> Date: Thu, 16 Apr 2020 20:02:26 +0200 Subject: [PATCH] easier embedding, fixed embedded video thumbnails --- videos/templates/embed.html | 13 +------------ videos/templates/parts/embed-video.html | 2 +- videos/templates/parts/player.html | 10 +++++++--- videos/views.py | 5 +++-- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/videos/templates/embed.html b/videos/templates/embed.html index f79de8a..84eb1b8 100755 --- a/videos/templates/embed.html +++ b/videos/templates/embed.html @@ -12,17 +12,6 @@ </style> </head> <body> - <div id="player"></div> - <script> - var player = new Clappr.Player({ - source: "{{ MEDIA_URL }}{{ path }}?key={{ key }}×tamp={{ timestamp }}", - {% if video.thumbnail %}poster: "{{ MEDIA_URL }}{{ video.thumbnail }}?key={{ video.key }}×tamp={{ video.updated_at|date:'U' }}",{% endif %} - parentId: "#player", - autoPlay: {% if autoplay %}true{% else %}false{% endif %}, - width: '100%', - height: '100%', - plugins: [], - }); - </script> + {% include "parts/player.html" with embed=1 %} </body> </html> diff --git a/videos/templates/parts/embed-video.html b/videos/templates/parts/embed-video.html index bb15ce2..14b68eb 100644 --- a/videos/templates/parts/embed-video.html +++ b/videos/templates/parts/embed-video.html @@ -4,7 +4,7 @@ </div> <div class="w3-container"> <p>Use for embedding on your own website (set autoplay=1 to enable automatic playback)</p> - <p class="w3-input w3-light-grey w3-code"><iframe src="https://lectures.fslab.de/embed?path={{ video.masterfile }}&key={{ video.key }}&timestamp={{ video.created_at|date:'U' }}&autoplay=0" allowfullscreen style="width:1024px;height:576px;"></iframe></p> + <p class="w3-input w3-light-grey w3-code"><iframe src="https://lectures.fslab.de/embed?key={{ video.key }}&autoplay=0" allowfullscreen style="width:1024px;height:576px;"></iframe></p> </div> </div> diff --git a/videos/templates/parts/player.html b/videos/templates/parts/player.html index e4f0a4d..97e7891 100644 --- a/videos/templates/parts/player.html +++ b/videos/templates/parts/player.html @@ -1,21 +1,25 @@ +{% if not embed %} <div class="w3-card-4"> <div class="w3-container w3-hochschulblau"> <h2>{{ video.name }}</h2> </div> <div class="w3-container" style="padding-top:10px"> +{% endif %} <div id="player"></div> <script> var player = new Clappr.Player({ source: "{{ MEDIA_URL }}{{ video.masterfile }}?key={{ video.key }}×tamp={{ video.created_at|date:'U' }}", {% if video.thumbnail %}poster: "{{ MEDIA_URL }}{{ video.thumbnail }}?key={{ video.key }}×tamp={{ video.updated_at|date:'U' }}",{% endif %} parentId: "#player", - autoPlay: true, - width: 1024, - height: 576, + autoPlay: {% if autoplay %}true{% else %}false{% endif %}, + width: {% if embed %}'100%'{% else %}1024{% endif %}, + height: {% if embed %}'100%'{% else %}576{% endif %}, plugins: [], playback: {{ "{" }}crossOrigin: 'anonymous'{% if video.subtitles %}, externalTracks: [{'lang': 'en-US', 'label': 'Subtitles', 'src': '{{ MEDIA_URL }}{{ video.subtitles }}?key={{ video.key }}×tamp={{ video.updated_at|date:'U' }}', 'kind': 'subtitles'}],{% endif %}{{ "}" }}, }); </script> +{% if not embed %} <p>{{ video.description|linebreaksbr }}</p> </div> </div> +{% endif %} diff --git a/videos/views.py b/videos/views.py index 04f05c0..b4c44f4 100755 --- a/videos/views.py +++ b/videos/views.py @@ -152,11 +152,12 @@ def video(request, course_id, video_id): is_lecturer = False is_admin = False - return render(request, "video.html", context={'course': course, 'video': video, 'attachments': attachments, 'is_admin': is_admin, 'is_lecturer': is_lecturer, 'preview': preview, 'updated': request.GET.get("updated") is not None}) + return render(request, "video.html", context={'course': course, 'video': video, 'attachments': attachments, 'is_admin': is_admin, 'is_lecturer': is_lecturer, 'preview': preview, 'updated': request.GET.get("updated") is not None, 'autoplay': True}) @xframe_options_exempt def embed(request): - return render(request, "embed.html", context={'path': request.GET.get('path'), 'key': request.GET.get('key'), 'timestamp': request.GET.get('timestamp'), 'autoplay': request.GET.get("autoplay") == "1"}) + video = get_object_or_404(Video, key=request.GET.get('key')) + return render(request, "embed.html", context={'video': video, 'autoplay': request.GET.get("autoplay") == "1"}) def cdn(request, path): hosts = CDNHost.objects.filter(enabled=True, healthy=True) -- GitLab