rewrite pending; for now, additional support for multi-station
This commit is contained in:
@@ -378,8 +378,13 @@ class RadioUtil:
|
||||
continue
|
||||
if station not in self.active_playlist:
|
||||
self.active_playlist[station] = []
|
||||
time_start = time.time()
|
||||
logging.info("[%s] Running query: %s",
|
||||
time_start, db_query)
|
||||
db_cursor = db_conn.execute(db_query)
|
||||
results: list[sqlite3.Row] = db_cursor.fetchall()
|
||||
time_end = time.time()
|
||||
logging.info("[%s] Query completed; Time taken: %s", time_end, (time_end - time_start))
|
||||
self.active_playlist[station] = [
|
||||
{
|
||||
"uuid": str(uuid().hex),
|
||||
@@ -402,7 +407,8 @@ class RadioUtil:
|
||||
station, len(self.active_playlist[station]),
|
||||
)
|
||||
|
||||
random.shuffle(self.active_playlist[station])
|
||||
if not station == "rock":# REMOVE ME, AFI RELATED
|
||||
random.shuffle(self.active_playlist[station])
|
||||
|
||||
"""Dedupe"""
|
||||
logging.info("Removing duplicate tracks...")
|
||||
@@ -441,7 +447,7 @@ class RadioUtil:
|
||||
station, len(self.active_playlist[station]),
|
||||
)
|
||||
self.playlists_loaded = True
|
||||
self.loop.run_until_complete(self._ls_skip())
|
||||
# self.loop.run_until_complete(self._ls_skip())
|
||||
except Exception as e:
|
||||
logging.info("Playlist load failed: %s", str(e))
|
||||
traceback.print_exc()
|
||||
@@ -521,22 +527,24 @@ class RadioUtil:
|
||||
return (x, item)
|
||||
return None
|
||||
|
||||
async def _ls_skip(self) -> bool:
|
||||
async def _ls_skip(self, station: str = "main") -> bool:
|
||||
"""
|
||||
Ask LiquidSoap server to skip to the next track
|
||||
Args:
|
||||
None
|
||||
station (str): default "main"
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
try:
|
||||
async with ClientSession() as session:
|
||||
async with session.get(
|
||||
f"{self.ls_uri}/next", timeout=ClientTimeout(connect=2, sock_read=2)
|
||||
async with session.post(
|
||||
f"{self.ls_uri}/next",
|
||||
data=station,
|
||||
timeout=ClientTimeout(connect=2, sock_read=2)
|
||||
) as request:
|
||||
request.raise_for_status()
|
||||
text: Optional[str] = await request.text()
|
||||
return text == "OK"
|
||||
return isinstance(text, str) and text.startswith("OK")
|
||||
except Exception as e:
|
||||
logging.debug("Skip failed: %s", str(e))
|
||||
|
||||
@@ -558,15 +566,17 @@ class RadioUtil:
|
||||
return None
|
||||
return response
|
||||
|
||||
async def webhook_song_change(self, track: dict) -> None:
|
||||
async def webhook_song_change(self, track: dict, station: str = "main") -> None:
|
||||
"""
|
||||
Handles Song Change Outbounds (Webhooks)
|
||||
Args:
|
||||
track (dict)
|
||||
station (str): default "main"
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
try:
|
||||
return None # disabled temporarily (needs rate limiting)
|
||||
# First, send track info
|
||||
"""
|
||||
TODO:
|
||||
@@ -582,7 +592,7 @@ class RadioUtil:
|
||||
"username": "serious.FM",
|
||||
"embeds": [
|
||||
{
|
||||
"title": "Now Playing",
|
||||
"title": f"Now Playing on {station.title()}",
|
||||
"description": f"## {track['song']}\nby\n## {track['artist']}",
|
||||
"color": 0x30C56F,
|
||||
"thumbnail": {
|
||||
@@ -636,36 +646,37 @@ class RadioUtil:
|
||||
) as request:
|
||||
request.raise_for_status()
|
||||
|
||||
# Next, AI feedback
|
||||
# Next, AI feedback (for main stream only)
|
||||
|
||||
ai_response: Optional[str] = await self.get_ai_song_info(
|
||||
track["artist"], track["song"]
|
||||
)
|
||||
if not ai_response:
|
||||
return
|
||||
if station == "main":
|
||||
ai_response: Optional[str] = await self.get_ai_song_info(
|
||||
track["artist"], track["song"]
|
||||
)
|
||||
if not ai_response:
|
||||
return
|
||||
|
||||
hook_data = {
|
||||
"username": "GPT",
|
||||
"embeds": [
|
||||
{
|
||||
"title": "AI Feedback",
|
||||
"color": 0x35D0FF,
|
||||
"description": ai_response.strip(),
|
||||
}
|
||||
],
|
||||
}
|
||||
hook_data = {
|
||||
"username": "GPT",
|
||||
"embeds": [
|
||||
{
|
||||
"title": "AI Feedback",
|
||||
"color": 0x35D0FF,
|
||||
"description": ai_response.strip(),
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
ai_hook: str = self.webhooks["gpt"].get("hook")
|
||||
async with ClientSession() as session:
|
||||
async with await session.post(
|
||||
ai_hook,
|
||||
json=hook_data,
|
||||
timeout=ClientTimeout(connect=5, sock_read=5),
|
||||
headers={
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
},
|
||||
) as request:
|
||||
request.raise_for_status()
|
||||
ai_hook: str = self.webhooks["gpt"].get("hook")
|
||||
async with ClientSession() as session:
|
||||
async with await session.post(
|
||||
ai_hook,
|
||||
json=hook_data,
|
||||
timeout=ClientTimeout(connect=5, sock_read=5),
|
||||
headers={
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
},
|
||||
) as request:
|
||||
request.raise_for_status()
|
||||
except Exception as e:
|
||||
logging.info("Webhook error occurred: %s", str(e))
|
||||
traceback.print_exc()
|
||||
|
Reference in New Issue
Block a user