Enhance LRC fetching logic by adding source tracking and improving type hints for artist, title, and duration
This commit is contained in:
@@ -625,27 +625,30 @@ class Radio(FastAPI):
|
||||
logging.info(f"Sending LRC to client for station {station}")
|
||||
logging.info(f"Track data: {track_data}")
|
||||
try:
|
||||
artist = track_data.get("artist")
|
||||
title = track_data.get("song") # Changed from "title" to "song"
|
||||
duration = track_data.get("duration")
|
||||
artist: Optional[str] = track_data.get("artist")
|
||||
title: Optional[str] = track_data.get("song") # Changed from "title" to "song"
|
||||
duration: Optional[int] = track_data.get("duration")
|
||||
|
||||
if artist and title:
|
||||
logging.info(f"Fetching LRC for {artist} - {title} (duration: {duration})")
|
||||
lrc = await self.sr_util.get_lrc_by_artist_song(
|
||||
lrc: Optional[str] = await self.sr_util.get_lrc_by_artist_song(
|
||||
artist, title, duration=duration
|
||||
)
|
||||
source: str = "SR"
|
||||
if not lrc:
|
||||
logging.info(f"No LRC from SR, trying LRCLib for {artist} - {title}")
|
||||
lrclib_result = await self.lrclib.search(artist, title, plain=False)
|
||||
if lrclib_result and lrclib_result.lyrics and isinstance(lrclib_result.lyrics, str):
|
||||
lrc = lrclib_result.lyrics
|
||||
source = "LRCLib"
|
||||
logging.info("LRC found via LRCLib fallback")
|
||||
self.lrc_cache[station] = lrc
|
||||
logging.info(f"LRC fetched: {lrc is not None}")
|
||||
if lrc:
|
||||
lrc_data = {
|
||||
lrc_data: dict = {
|
||||
"type": "lrc",
|
||||
"data": lrc
|
||||
"data": lrc,
|
||||
"source": source
|
||||
}
|
||||
await websocket.send_text(json.dumps(lrc_data))
|
||||
logging.info("LRC sent to client")
|
||||
@@ -658,27 +661,30 @@ class Radio(FastAPI):
|
||||
return
|
||||
|
||||
try:
|
||||
artist = track_data.get("artist")
|
||||
title = track_data.get("song") # Changed from "title" to "song"
|
||||
duration = track_data.get("duration")
|
||||
artist: Optional[str] = track_data.get("artist")
|
||||
title: Optional[str] = track_data.get("song") # Changed from "title" to "song"
|
||||
duration: Optional[int] = track_data.get("duration")
|
||||
|
||||
if artist and title:
|
||||
logging.info(f"Broadcasting LRC fetch for {artist} - {title} (duration: {duration})")
|
||||
lrc = await self.sr_util.get_lrc_by_artist_song(
|
||||
lrc: Optional[str] = await self.sr_util.get_lrc_by_artist_song(
|
||||
artist, title, duration=duration
|
||||
)
|
||||
source: str = "SR"
|
||||
if not lrc:
|
||||
logging.info(f"No LRC from SR, trying LRCLib for {artist} - {title}")
|
||||
lrclib_result = await self.lrclib.search(artist, title, plain=False)
|
||||
if lrclib_result and lrclib_result.lyrics and isinstance(lrclib_result.lyrics, str):
|
||||
lrc = lrclib_result.lyrics
|
||||
source = "LRCLib"
|
||||
logging.info("LRC found via LRCLib fallback")
|
||||
self.lrc_cache[station] = lrc
|
||||
logging.info(f"LRC fetched for broadcast: {lrc is not None}")
|
||||
if lrc:
|
||||
lrc_data = {
|
||||
lrc_data: dict = {
|
||||
"type": "lrc",
|
||||
"data": lrc
|
||||
"data": lrc,
|
||||
"source": source
|
||||
}
|
||||
|
||||
# Send to all connected clients
|
||||
|
Reference in New Issue
Block a user