from conf.settings import AZURACAST_URL, AZURACAST_API_KEY import requests def authorize_url(method, url): file_url = url API_KEY = AZURACAST_API_KEY headers = { "Authorization": f"Bearer {API_KEY}" } return requests.request(method, file_url, headers=headers) class AzuraCastRequests: api_key = AZURACAST_API_KEY url = AZURACAST_URL @staticmethod def get_song_history(start_time, end_time): file_url = F"{AZURACAST_URL}api/station/it-radio/history?start={start_time}&end={end_time}" response = authorize_url("get", file_url) return response.json() @staticmethod def get_nowplaying(): file_url = F"{AZURACAST_URL}api/nowplaying/it-radio" response = authorize_url("get", file_url) return response.json() @staticmethod def get_all_songs(): file_url = F"{AZURACAST_URL}api/station/it-radio/files" response = authorize_url("get", file_url) return response @staticmethod def get_song(azura_id): file_url = f"{AZURACAST_URL}api/station/it-radio/file/{azura_id}" response = authorize_url("get", file_url) return response @staticmethod def get_blob(unique_id): file_play = f"{AZURACAST_URL}api/station/it-radio/file/{unique_id}/play" response = authorize_url("get", file_play) return response @staticmethod def delete_song(azura_id): file_url = f"{AZURACAST_URL}api/station/it-radio/file/{azura_id}" response = authorize_url("delete", file_url) return response