Overview
TheLyricsFetcher class provides an interface to search and retrieve song lyrics from the LRCLIB API. It supports both synced (timestamped) and plain text lyrics.
Constructor
Instantiate the fetcher before making requests:Methods
search_lyrics()
Searches for lyrics matching the given artist and track title.Artist name to search for
Track title to search for
Album name (currently not used in search but available for future filtering)
List of lyric results. Returns empty list on error or no results found.Each result dictionary contains:
id(int): LRCLIB lyric IDtrackName(str): Track titleartistName(str): Artist namealbumName(str): Album nameduration(float): Track duration in secondssyncedLyrics(str | None): Time-synced LRC format lyricsplainLyrics(str | None): Plain text lyrics without timestampsisSynced(bool): Whether synced lyrics are available
Response Format
Synced Lyrics (LRC Format)
Time-synced lyrics use the LRC format with timestamps:Plain Lyrics
Plain text lyrics without timestamps:Complete Example
Filtering Results
When multiple results are returned, you may want to filter them:Integration with MetadataHandler
TheLyricsFetcher works seamlessly with MetadataHandler:
Error Handling
The method handles network errors gracefully:- Network timeout (10 second timeout)
- Invalid response from API
- No matching lyrics in database
API Details
- Base URL: https://lrclib.net/api/search
- Request timeout: 10 seconds
- Rate limiting: No explicit rate limit enforced by client (respect LRCLIB’s fair use policy)
- Search method: Combined artist + title search query
Dependencies
Requires therequests Python package:
Best Practices
- Verify results: Always check if results list is non-empty before accessing
- Prefer synced lyrics: Check
isSyncedflag for better user experience - Handle multiple results: The API may return several matches; filter or present choices to user
- Metadata quality: Ensure artist and title metadata are accurate for better search results
- LRC file format: When using synced lyrics, they’re automatically saved as .lrc files by
MetadataHandler.save()
