misc
This commit is contained in:
@@ -47,12 +47,12 @@ class Radio(FastAPI):
|
||||
self.sr_util = SRUtil()
|
||||
self.lrclib = LRCLib()
|
||||
self.lrc_cache: Dict[str, Optional[str]] = {}
|
||||
self.lrc_cache_locks = {}
|
||||
self.lrc_cache_locks: Dict[str, asyncio.Lock] = defaultdict(asyncio.Lock)
|
||||
self.playlists_loaded: bool = False
|
||||
# WebSocket connection management
|
||||
self.active_connections: Dict[str, Set[WebSocket]] = {}
|
||||
# Initialize broadcast locks to prevent duplicate events
|
||||
self.broadcast_locks = defaultdict(asyncio.Lock)
|
||||
self.broadcast_locks: Dict[str, asyncio.Lock] = defaultdict(asyncio.Lock)
|
||||
self.endpoints: dict = {
|
||||
"radio/np": self.radio_now_playing,
|
||||
"radio/request": self.radio_request,
|
||||
@@ -71,9 +71,9 @@ class Radio(FastAPI):
|
||||
if endpoint == "radio/album_art":
|
||||
methods = ["GET"]
|
||||
app.add_api_route(
|
||||
f"/{endpoint}", handler, methods=methods, include_in_schema=True,
|
||||
f"/{endpoint}", handler, methods=methods, include_in_schema=False,
|
||||
dependencies=[Depends(
|
||||
RateLimiter(times=25, seconds=2))] if not endpoint == "radio/np" else None,
|
||||
RateLimiter(times=25, seconds=2))],
|
||||
)
|
||||
|
||||
# Add WebSocket route
|
||||
@@ -83,12 +83,8 @@ class Radio(FastAPI):
|
||||
|
||||
app.add_websocket_route("/radio/ws/{station}", websocket_route_handler)
|
||||
|
||||
app.add_event_handler("startup", self.on_start)
|
||||
|
||||
async def on_start(self) -> None:
|
||||
# Initialize locks in the event loop
|
||||
self.lrc_cache_locks = defaultdict(asyncio.Lock)
|
||||
self.broadcast_locks = defaultdict(asyncio.Lock)
|
||||
# Load playlists for all stations
|
||||
stations = ", ".join(self.radio_util.db_queries.keys())
|
||||
logging.info("radio: Initializing stations:\n%s", stations)
|
||||
await self.radio_util.load_playlists()
|
||||
|
||||
Reference in New Issue
Block a user