mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 18:52:23 +01:00
Refactor {,playlist_}song_to_dict
This commit is contained in:
@ -4,29 +4,34 @@ from queues.models import Queue, Playlist
|
||||
from django.http import StreamingHttpResponse
|
||||
|
||||
|
||||
def song_to_dict(song, hash=False, user=False):
|
||||
def song_to_dict(song, hash=False, user=False, replaygain=False):
|
||||
data = {
|
||||
'id': song.id,
|
||||
'artist': song.artist,
|
||||
'title': song.title,
|
||||
'duration': song.duration,
|
||||
'rg_gain': song.rg_gain,
|
||||
'rg_peak': song.rg_peak,
|
||||
}
|
||||
|
||||
if hash:
|
||||
data['hash'] = song.hash
|
||||
|
||||
if user and song.user is not None and len(song.user.name) > 1:
|
||||
if user is not None and song.user is not None and song.user.name:
|
||||
data['uploader_name'] = song.user.name
|
||||
|
||||
if replaygain:
|
||||
data['rg_gain'] = song.rg_gain,
|
||||
data['rg_peak'] = song.rg_peak,
|
||||
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def playlist_song_to_dict(playlist_song, hash=False, user=None):
|
||||
def playlist_song_to_dict(playlist_song, **options):
|
||||
user = options.get('user')
|
||||
return {
|
||||
'id': playlist_song.id,
|
||||
'requested_by': 'Marietje' if playlist_song.user is None else playlist_song.user.name,
|
||||
'song': song_to_dict(playlist_song.song, hash=hash),
|
||||
'song': song_to_dict(playlist_song.song, **options),
|
||||
'can_move_down': playlist_song.user is not None and playlist_song.user == user
|
||||
}
|
||||
|
||||
|
||||
@ -22,8 +22,8 @@ def queue(request):
|
||||
command.save()
|
||||
|
||||
return JsonResponse({
|
||||
'current_song': playlist_song_to_dict(queue.current_song(), True),
|
||||
'queue': [playlist_song_to_dict(playlist_song, True) for playlist_song in queue.queue()[:1]],
|
||||
'current_song': playlist_song_to_dict(queue.current_song(), hash=True, replaygain=True),
|
||||
'queue': [playlist_song_to_dict(playlist_song, hash=True, replaygain=True) for playlist_song in queue.queue()[:1]],
|
||||
'commands': [command.command for command in commands]
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user