46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from django.http import HttpResponse
|
|
from audio.services import service_azura
|
|
|
|
class AzuraCast:
|
|
azura_requests = service_azura.AzuraCastRequests()
|
|
|
|
def get_song_history(self, start, end):
|
|
print(start, end)
|
|
response = self.azura_requests.get_song_history(start, end)
|
|
return response
|
|
|
|
def get_nowplaying(self):
|
|
response = self.azura_requests.get_nowplaying()
|
|
return response
|
|
|
|
def get_all_songs(self):
|
|
response = self.azura_requests.get_all_songs()
|
|
data = []
|
|
for i in response.json():
|
|
i['azura_id'] = i.pop('song_id')
|
|
data.append(i)
|
|
return data
|
|
|
|
def add_to_playlist(self, data):
|
|
response = self.azura_requests.get_song(data['azura_id'])
|
|
file_play = response.json()['unique_id']
|
|
data.update(unique_id=file_play)
|
|
return data
|
|
|
|
def delete_song(self, azura_id):
|
|
response = self.azura_requests.delete_song(azura_id)
|
|
return response
|
|
|
|
def get_audio(self, song_obj):
|
|
response = self.azura_requests.get_blob(song_obj.unique_id)
|
|
file_response = HttpResponse(response.content, content_type='audio/mpeg')
|
|
file = f'{song_obj.title}-{song_obj.artist}.mp3'
|
|
file_response['Content-Disposition'] = f'attachment; filename={file}'
|
|
return file_response
|
|
|
|
def get_unique_id(self, azura_id):
|
|
response = self.azura_requests.get_song(azura_id)
|
|
|
|
return response.json()['unique_id']
|
|
|