radio: minor/misc_util: add coffee 'Kopi luwak'

This commit is contained in:
2025-03-24 09:06:56 -04:00
parent cf688b88af
commit 55f8f29a31
3 changed files with 42 additions and 4 deletions

View File

@ -7,7 +7,8 @@ from aiohttp import ClientSession, ClientTimeout
async def get_now_playing() -> Optional[str]:
"""
Get radio now playing
Args:
None
Returns:
str
"""
@ -24,4 +25,26 @@ async def get_now_playing() -> Optional[str]:
except Exception as e:
logging.critical("Now playing retrieval failed: %s",
str(e))
return None
return None
async def skip() -> bool:
"""
Ask LiquidSoap server to skip to the next track
Args:
None
Returns:
bool
"""
try:
ls_uri: str = "http://127.0.0.1:29000"
async with ClientSession() as session:
async with session.get(f"{ls_uri}/next",
timeout=ClientTimeout(connect=2, sock_read=2)) as request:
request.raise_for_status()
text: Optional[str] = await request.text()
return text == "OK"
except Exception as e:
logging.debug("Skip failed: %s", str(e))
return False # failsafe