mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 19:52:20 +01:00
71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
from django.utils import timezone
|
|
|
|
from django.http import JsonResponse
|
|
from django.shortcuts import get_object_or_404
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from marietje.utils import playlist_song_to_dict
|
|
from queues.models import Queue
|
|
from songs.models import Song
|
|
|
|
from .decorators import token_required
|
|
|
|
|
|
@csrf_exempt
|
|
@token_required
|
|
def queue(request):
|
|
current_queue = get_object_or_404(Queue, id=request.POST.get("queue"))
|
|
commands = current_queue.queuecommand_set.all()
|
|
response = JsonResponse(
|
|
{
|
|
"current_song": playlist_song_to_dict(
|
|
current_queue.current_song(), include_hash=True, include_replaygain=True
|
|
),
|
|
"queue": [
|
|
playlist_song_to_dict(playlist_song, include_hash=True, include_replaygain=True)
|
|
for playlist_song in current_queue.queue()[:1]
|
|
],
|
|
"commands": [command.command for command in commands],
|
|
}
|
|
)
|
|
for command in commands:
|
|
command.delete()
|
|
|
|
return response
|
|
|
|
|
|
@csrf_exempt
|
|
@token_required
|
|
def play(request):
|
|
current_queue = get_object_or_404(Queue, id=request.POST.get("queue"))
|
|
current_queue.started_at = timezone.now()
|
|
current_queue.save()
|
|
current_song = current_queue.current_song()
|
|
current_song.played_at = current_queue.started_at
|
|
current_song.save()
|
|
|
|
return JsonResponse({})
|
|
|
|
|
|
# pylint: disable=redefined-builtin
|
|
@csrf_exempt
|
|
@token_required
|
|
def next(request):
|
|
current_queue = get_object_or_404(Queue, id=request.POST.get("queue"))
|
|
player_song = current_queue.current_song()
|
|
player_song.state = 2
|
|
player_song.save()
|
|
return JsonResponse({})
|
|
|
|
|
|
@csrf_exempt
|
|
@token_required
|
|
def analysed(request):
|
|
song = get_object_or_404(Song, id=request.POST.get("song"))
|
|
if "gain" in request.POST:
|
|
song.rg_gain = request.POST.get("gain")
|
|
if "peak" in request.POST:
|
|
song.rg_peak = request.POST.get("peak")
|
|
song.save()
|
|
return JsonResponse({})
|