minor: formatting

This commit is contained in:
2025-09-27 09:29:53 -04:00
parent 0bd2b6b4f3
commit 6f016c7917
5 changed files with 42 additions and 22 deletions

View File

@@ -1 +1 @@
# Radio endpoints package
# Radio endpoints package

View File

@@ -29,7 +29,11 @@ class LRCLib:
@retry(stop=stop_after_attempt(2), wait=wait_fixed(0.5))
async def search(
self, artist: str, song: str, plain: Optional[bool] = True, duration: Optional[int] = None
self,
artist: str,
song: str,
plain: Optional[bool] = True,
duration: Optional[int] = None,
) -> Optional[LyricsResult]:
"""
LRCLib Search
@@ -81,7 +85,11 @@ class LRCLib:
# Filter by duration if provided
if duration:
search_data = [r for r in search_data if abs(r.get("duration", 0) - duration) <= 10]
search_data = [
r
for r in search_data
if abs(r.get("duration", 0) - duration) <= 10
]
if plain:
possible_matches = [
@@ -107,7 +115,8 @@ class LRCLib:
best_match = None
try:
match_result = self.matcher.find_best_match(
input_track, possible_matches # type: ignore
input_track,
possible_matches, # type: ignore
)
if match_result:
best_match = match_result[0]

View File

@@ -1 +1 @@
# Utils package
# Utils package

View File

@@ -479,7 +479,9 @@ def bulk_download(track_list: list, quality: str = "FLAC"):
except Exception as e:
tb = traceback.format_exc()
is_no_stream_url = isinstance(e, RuntimeError) and str(e) == "No stream URL"
is_no_stream_url = (
isinstance(e, RuntimeError) and str(e) == "No stream URL"
)
if is_no_stream_url:
if attempt == 1 or attempt == MAX_RETRIES:
msg = f"Track {track_id} attempt {attempt} failed: {e}\n{tb}"
@@ -492,9 +494,13 @@ def bulk_download(track_list: list, quality: str = "FLAC"):
"ERROR",
target,
)
await asyncio.sleep(random.uniform(THROTTLE_MIN, THROTTLE_MAX))
await asyncio.sleep(
random.uniform(THROTTLE_MIN, THROTTLE_MAX)
)
else:
msg = f"Track {track_id} attempt {attempt} failed: {e}\n{tb}"
msg = (
f"Track {track_id} attempt {attempt} failed: {e}\n{tb}"
)
send_log_to_discord(msg, "ERROR", target)
track_info["error"] = str(e)
if attempt >= MAX_RETRIES:
@@ -504,7 +510,9 @@ def bulk_download(track_list: list, quality: str = "FLAC"):
"ERROR",
target,
)
await asyncio.sleep(random.uniform(THROTTLE_MIN, THROTTLE_MAX))
await asyncio.sleep(
random.uniform(THROTTLE_MIN, THROTTLE_MAX)
)
finally:
try:

View File

@@ -751,14 +751,16 @@ class SRUtil:
"""Get LRC lyrics by track ID."""
logging.info(f"SR: Fetching metadata for track ID {track_id}")
metadata = await self.get_metadata_by_track_id(track_id)
lrc = metadata.get('lyrics') if metadata else None
lrc = metadata.get("lyrics") if metadata else None
logging.info(f"SR: LRC {'found' if lrc else 'not found'}")
return lrc
async def get_lrc_by_artist_song(
self, artist: str, song: str, album: Optional[str] = None, duration: Optional[int] = None
self,
artist: str,
song: str,
album: Optional[str] = None,
duration: Optional[int] = None,
) -> Optional[str]:
"""Get LRC lyrics by artist and song, optionally filtering by album and duration."""
logging.info(f"SR: Searching tracks for {artist} - {song}")
@@ -766,21 +768,22 @@ class SRUtil:
logging.info(f"SR: Found {len(tracks) if tracks else 0} tracks")
if not tracks:
return None
# Filter by album if provided
if album:
tracks = [
t for t in tracks
if t.get('album', {}).get('title', '').lower() == album.lower()
t
for t in tracks
if t.get("album", {}).get("title", "").lower() == album.lower()
]
if not tracks:
return None
# If duration provided, select the track with closest duration match
if duration is not None:
tracks_with_diff = [
(t, abs(t.get('duration', 0) - duration)) for t in tracks
(t, abs(t.get("duration", 0) - duration)) for t in tracks
]
tracks_with_diff.sort(key=lambda x: x[1])
best_track, min_diff = tracks_with_diff[0]
@@ -791,10 +794,10 @@ class SRUtil:
return None
else:
best_track = tracks[0]
track_id = best_track.get('id')
track_id = best_track.get("id")
logging.info(f"SR: Using track ID {track_id}")
if not track_id:
return None
return await self.get_lrc_by_track_id(track_id)