diff --git a/strolchguru/templates/strolchguru_home.html b/strolchguru/templates/strolchguru_home.html index a29f6303dda22addc867ca2b20c168ef2ff58cec..e3ce41b2bc63d1e87322be380878e457f7d312f8 100644 --- a/strolchguru/templates/strolchguru_home.html +++ b/strolchguru/templates/strolchguru_home.html @@ -37,12 +37,14 @@ <body style="background: black;"> <video id="clip" autoplay - controls + {% if controls %}controls{% endif %} + {% if mode == "loop" %} loop {% else %} onended="window.location.reload(true)" {% endif %} + src="/media/clips/{{ clip.clip_id }}.mp4"> </video> <div id="caption"> diff --git a/strolchguru/views.py b/strolchguru/views.py index 43923208876bb4adab83c9536bb5292897b40b8c..da48f9d9c717f38450cd6c0fadd5d79bdf6f88d7 100644 --- a/strolchguru/views.py +++ b/strolchguru/views.py @@ -1,21 +1,28 @@ import random from django.forms.models import model_to_dict -from django.http import HttpResponse, JsonResponse +from django.http import HttpResponse, JsonResponse, Http404 from django.shortcuts import render, get_object_or_404 from .models import Clip def home(request) -> HttpResponse: + controls = True if request.GET.get("controls") == "1" else False clips = list(Clip.objects.filter(is_published=True, is_downloaded=True)) clip = random.choice(clips) - return render(request, 'strolchguru_home.html', context={'clip': clip, 'mode': "random_clips"}) + return render(request, 'strolchguru_home.html', + context={'clip': clip, 'mode': "random_clips", 'controls': controls}) def clip(request, id) -> HttpResponse: + controls = True if request.GET.get("controls") == "1" else False clip = get_object_or_404(Clip, pk=id) - return render(request, 'strolchguru_home.html', context={'clip': clip, 'mode': "loop"}) + + if not clip.is_published: + raise Http404() + + return render(request, 'strolchguru_home.html', context={'clip': clip, 'mode': "loop", 'controls': controls}) def clip_json(request, id) -> JsonResponse: @@ -25,7 +32,3 @@ def clip_json(request, id) -> JsonResponse: return JsonResponse(json) except Clip.DoesNotExist: return JsonResponse({"error": "Clip with this id does not exist"}) - -# def clips_today(request) -> HttpResponse: -# clips = twitch_api.get_clips(today=True) -# return render(request, 'strolchguru_home.html', context={'clip': clip, 'url_name': "clips_today"})