import socket, struct, binascii from django.conf import settings from queues.models import Queue, Playlist from django.http import StreamingHttpResponse def song_to_dict(song, hash=False, user=False, replaygain=False): data = { 'id': song.id, 'artist': song.artist, 'title': song.title, 'duration': song.duration, } if hash: data['hash'] = song.hash 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, **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, **options), 'can_move_down': playlist_song.user is not None and playlist_song.user == user } # Send a file to bertha file storage. def send_to_bertha(file): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(settings.BERTHA_HOST) sock.sendall(struct.pack("