cleanup
This commit is contained in:
@ -28,12 +28,11 @@ TODO:
|
||||
|
||||
class Radio(FastAPI):
|
||||
"""Radio Endpoints"""
|
||||
def __init__(self, app: FastAPI, my_util, constants, glob_state) -> None: # pylint: disable=super-init-not-called
|
||||
def __init__(self, app: FastAPI, my_util, constants) -> None: # pylint: disable=super-init-not-called
|
||||
self.app = app
|
||||
self.util = my_util
|
||||
self.constants = constants
|
||||
self.radio_util = radio_util.RadioUtil(self.constants)
|
||||
self.glob_state = glob_state
|
||||
|
||||
self.endpoints: dict = {
|
||||
"radio/np": self.radio_now_playing,
|
||||
@ -64,8 +63,10 @@ class Radio(FastAPI):
|
||||
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
|
||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||
if data.skipTo:
|
||||
(x, _) = self.radio_util.get_queue_item_by_uuid(data.skipTo)
|
||||
self.radio_util.active_playlist = self.radio_util.active_playlist[x:]
|
||||
queue_item = self.radio_util.get_queue_item_by_uuid(data.skipTo)
|
||||
if not queue_item:
|
||||
return False
|
||||
self.radio_util.active_playlist = self.radio_util.active_playlist[queue_item[0]:]
|
||||
if not self.radio_util.active_playlist:
|
||||
await self.radio_util.load_playlist()
|
||||
return await self.radio_util._ls_skip()
|
||||
@ -112,7 +113,13 @@ class Radio(FastAPI):
|
||||
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
|
||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||
|
||||
(x, item) = self.radio_util.get_queue_item_by_uuid(data.uuid)
|
||||
queue_item = self.radio_util.get_queue_item_by_uuid(data.uuid)
|
||||
if not queue_item:
|
||||
return {
|
||||
'err': True,
|
||||
'errorText': 'Queue item not found.',
|
||||
}
|
||||
(x, item) = queue_item
|
||||
self.radio_util.active_playlist.pop(x)
|
||||
self.radio_util.active_playlist.insert(0, item)
|
||||
if not data.next:
|
||||
@ -126,18 +133,18 @@ class Radio(FastAPI):
|
||||
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
|
||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||
|
||||
(x, found_item) = self.radio_util.get_queue_item_by_uuid(data.uuid)
|
||||
if not found_item:
|
||||
queue_item = self.radio_util.get_queue_item_by_uuid(data.uuid)
|
||||
if not queue_item:
|
||||
return {
|
||||
'ok': False,
|
||||
'err': 'UUID not found in play queue',
|
||||
'err': True,
|
||||
'errorText': 'Queue item not found.',
|
||||
}
|
||||
self.radio_util.active_playlist.pop(x)
|
||||
self.radio_util.active_playlist.pop(queue_item[0])
|
||||
return {
|
||||
'ok': True,
|
||||
}
|
||||
|
||||
async def album_art_handler(self, request: Request, track_id: Optional[int] = None) -> bytes:
|
||||
async def album_art_handler(self, request: Request, track_id: Optional[int] = None) -> Response:
|
||||
"""
|
||||
Get album art, optional parameter track_id may be specified.
|
||||
Otherwise, current track album art will be pulled.
|
||||
@ -182,13 +189,13 @@ class Radio(FastAPI):
|
||||
if not isinstance(self.radio_util.active_playlist, list) or not self.radio_util.active_playlist:
|
||||
await self.radio_util.load_playlist()
|
||||
await self.radio_util._ls_skip()
|
||||
return
|
||||
return None
|
||||
next = self.radio_util.active_playlist.pop(0)
|
||||
if not isinstance(next, dict):
|
||||
logging.critical("next is of type: %s, reloading playlist...", type(next))
|
||||
await self.radio_util.load_playlist()
|
||||
await self.radio_util._ls_skip()
|
||||
return
|
||||
return None
|
||||
|
||||
duration: int = next['duration']
|
||||
time_started: int = int(time.time())
|
||||
@ -209,19 +216,21 @@ class Radio(FastAPI):
|
||||
try:
|
||||
if not await self.radio_util.get_album_art(file_path=next['file_path']):
|
||||
album_art = await self.radio_util.get_album_art(file_path=next['file_path'])
|
||||
if not album_art:
|
||||
return None
|
||||
await self.radio_util.cache_album_art(next['id'], album_art)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
return next
|
||||
|
||||
|
||||
async def radio_request(self, data: ValidRadioSongRequest, request: Request) -> Response:
|
||||
async def radio_request(self, data: ValidRadioSongRequest, request: Request) -> dict:
|
||||
"""Song request handler"""
|
||||
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
|
||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||
artistsong: str = data.artistsong
|
||||
artist: str = data.artist
|
||||
song: str = data.song
|
||||
artistsong: Optional[str] = data.artistsong
|
||||
artist: Optional[str] = data.artist
|
||||
song: Optional[str] = data.song
|
||||
if artistsong and (artist or song):
|
||||
return {
|
||||
'err': True,
|
||||
|
Reference in New Issue
Block a user