Initial commit.

This commit is contained in:
Jim Driessen
2017-01-20 17:45:58 +01:00
commit 47e7b5b59c
85 changed files with 12276 additions and 0 deletions

View File

@ -0,0 +1,40 @@
import socket, struct, binascii
from django.conf import settings
def song_to_dict(song, hash=False):
data = {
'id': song.id,
'artist': song.artist,
'title': song.title,
'duration': song.duration
}
if hash:
data['hash'] = song.hash
if hasattr(song, 'uploader_name') and song.uploader_name is not None and len(song.uploader_name) > 1:
data['uploader_name'] = song.uploader_name
return data
def playlist_song_to_dict(playlist_song, hash=False):
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)
}
# 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("<BQ", 4, file.size))
for chunk in file.chunks():
sock.sendall(chunk)
sock.shutdown(socket.SHUT_WR)
hash = binascii.hexlify(sock.recv(64))
sock.close()
return hash