2025-02-14 07:10:09 -05:00
|
|
|
#!/usr/bin/env python3.12
|
|
|
|
|
|
|
|
import logging
|
2025-02-16 13:16:53 -05:00
|
|
|
from typing import Optional
|
2025-02-14 07:10:09 -05:00
|
|
|
from aiohttp import ClientSession, ClientTimeout
|
|
|
|
|
|
|
|
"""Radio Utils"""
|
|
|
|
|
2025-02-16 13:16:53 -05:00
|
|
|
async def get_now_playing() -> Optional[str]:
|
2025-02-14 07:10:09 -05:00
|
|
|
np_url: str = "https://api.codey.lol/radio/np"
|
|
|
|
try:
|
|
|
|
async with ClientSession() as session:
|
|
|
|
async with await session.post(np_url, headers={
|
|
|
|
'content-type': 'application/json; charset=utf-8',
|
|
|
|
}, timeout=ClientTimeout(connect=1.5, sock_read=1.5)) as request:
|
|
|
|
request.raise_for_status()
|
|
|
|
response_json = await request.json()
|
|
|
|
artistsong = response_json.get('artistsong')
|
|
|
|
return artistsong
|
|
|
|
except Exception as e:
|
|
|
|
logging.critical("Now playing retrieval failed: %s",
|
2025-02-16 13:16:53 -05:00
|
|
|
str(e))
|
|
|
|
return None
|