diff --git a/frontend/templatetags/playlists.py b/frontend/templatetags/playlists.py
index 61d6742..995b752 100644
--- a/frontend/templatetags/playlists.py
+++ b/frontend/templatetags/playlists.py
@@ -21,3 +21,10 @@ def other_videos(playlist, video, count=4):
older_out = older[-count+len(newer_out):]
return sorted(older_out + newer_out, key=lambda x: x.published)
+
+@register.simple_tag
+def next_video(playlist, video):
+ try:
+ return playlist.videos.filter(published__gt=video.published).order_by('published').first()
+ except:
+ return None
\ No newline at end of file
diff --git a/frontend/views.py b/frontend/views.py
index f1d03b3..4a126ed 100644
--- a/frontend/views.py
+++ b/frontend/views.py
@@ -14,6 +14,7 @@ class PlaylistView(ListView):
context = super().get_context_data(**kwargs)
context["title"] = "All Videos"
context["playlists"] = Playlist.objects.all()
+ context["playlist"] = self.get_playlist()
return context
def get_playlist(self):
@@ -31,7 +32,8 @@ class PlaylistView(ListView):
return queryset
def get_ordering(self):
- return self.request.GET.get('sort', '-published')
+ ordering = "published" if self.get_playlist() else "-published"
+ return self.request.GET.get('sort', ordering)
class VideoView(DetailView):
@@ -41,4 +43,9 @@ class VideoView(DetailView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = self.object.title
+ context["playlist"] = self.get_playlist()
return context
+
+ def get_playlist(self):
+ if (pid := self.request.GET.get("playlist")):
+ return get_object_or_404(Playlist, id=pid)
diff --git a/static/js/nextvideo.js b/static/js/nextvideo.js
new file mode 100644
index 0000000..dcd048a
--- /dev/null
+++ b/static/js/nextvideo.js
@@ -0,0 +1,8 @@
+var player = document.getElementById("videoplayer");
+
+var current = player.getAttribute("data-current");
+var next = player.getAttribute("data-next");
+
+if (next) {
+ player.onended = function () { document.location.href = document.location.href.replace(current, next); };
+};
\ No newline at end of file
diff --git a/templates/frontend/base.html b/templates/frontend/base.html
index a688365..5d5a8c8 100644
--- a/templates/frontend/base.html
+++ b/templates/frontend/base.html
@@ -32,6 +32,8 @@
+{% block scripts %}
+{% endblock %}