rewrite pending; for now, additional support for multi-station

This commit is contained in:
2025-07-19 21:57:21 -04:00
parent 85182b7d8c
commit 9ce16ba923
5 changed files with 76 additions and 57 deletions

View File

@@ -76,6 +76,7 @@ class Radio(FastAPI):
Skip to the next track in the queue, or to uuid specified in skipTo if provided
- **key**: API key
- **skipTo**: Optional UUID to skip to
- **station**: default "main"
"""
try:
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
@@ -93,9 +94,7 @@ class Radio(FastAPI):
self.radio_util.active_playlist[data.station] = self.radio_util.active_playlist[data.station][
queue_item[0] :
]
# if not self.radio_util.active_playlist:
# self.radio_util.load_playlist()
skip_result: bool = await self.radio_util._ls_skip()
skip_result: bool = await self.radio_util._ls_skip(data.station)
status_code = 200 if skip_result else 500
return JSONResponse(
status_code=status_code,
@@ -122,6 +121,7 @@ class Radio(FastAPI):
"""
Reshuffle the play queue
- **key**: API key
- **station**: default "main"
"""
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
raise HTTPException(status_code=403, detail="Unauthorized")
@@ -187,6 +187,7 @@ class Radio(FastAPI):
- **key**: API key
- **uuid**: UUID to shift
- **next**: Play track next? If False, skips to the track
- **station**: default "main"
"""
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
raise HTTPException(status_code=403, detail="Unauthorized")
@@ -204,7 +205,7 @@ class Radio(FastAPI):
self.radio_util.active_playlist[data.station].pop(x)
self.radio_util.active_playlist[data.station].insert(0, item)
if not data.next:
await self.radio_util._ls_skip()
await self.radio_util._ls_skip(data.station)
return JSONResponse(
content={
"ok": True,
@@ -218,6 +219,7 @@ class Radio(FastAPI):
Remove an item from the current play queue
- **key**: API key
- **uuid**: UUID of queue item to remove
- **station**: default "main"
"""
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
raise HTTPException(status_code=403, detail="Unauthorized")
@@ -246,6 +248,7 @@ class Radio(FastAPI):
Get album art, optional parameter track_id may be specified.
Otherwise, current track album art will be pulled.
- **track_id**: Optional, if provided, will attempt to retrieve the album art of this track_id. Current track used otherwise.
- **station**: default "main"
"""
try:
if not track_id:
@@ -271,6 +274,7 @@ class Radio(FastAPI):
station: Optional[str] = "main") -> JSONResponse:
"""
Get currently playing track info
- **station**: default "main"
"""
ret_obj: dict = {**self.radio_util.now_playing[station]}
ret_obj["station"] = station
@@ -293,7 +297,7 @@ class Radio(FastAPI):
(Track will be removed from the queue in the process.)
- **key**: API key
- **skipTo**: Optional UUID to skip to
- **station**: Station (default: "main")
- **station**: default: "main"
"""
logging.info("Radio get next")
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
@@ -337,8 +341,7 @@ class Radio(FastAPI):
next["start"] = time_started
next["end"] = time_ends
try:
if data.station == "main":
background_tasks.add_task(self.radio_util.webhook_song_change, next)
background_tasks.add_task(self.radio_util.webhook_song_change, next, data.station)
except Exception as e:
logging.info("radio_get_next Exception: %s", str(e))
traceback.print_exc()
@@ -361,6 +364,7 @@ class Radio(FastAPI):
- **song**: Song to search
- **artistsong**: Optional "Artist - Song" pair to search, in place of artist/song
- **alsoSkip**: If True, skips to the track; otherwise, track will be placed next up in queue
- **station**: default "main"
"""
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
raise HTTPException(status_code=403, detail="Unauthorized")
@@ -385,10 +389,10 @@ class Radio(FastAPI):
)
search: bool = self.radio_util.search_db(
artistsong=artistsong, artist=artist, song=song
artistsong=artistsong, artist=artist, song=song, station=data.station
)
if data.alsoSkip:
await self.radio_util._ls_skip()
await self.radio_util._ls_skip(data.station)
return JSONResponse(content={"result": search})
def radio_typeahead(