This project is a FastAPI-based service that fetches song lyrics from the web. It combines multiple sources including Genius API, Spotify, Musixmatch, and Google search to find and scrape lyrics. The lyrics are cached in a local SQLite database to improve performance and reduce redundant requests.
- Fetch lyrics for a given song title and artist
- Fetch lyrics directly from Spotify track URLs
- Works with or without Genius API key (falls back to web scraping)
- Smart caching system using SQLite database
- Multiple lyrics sources (Genius API, Spotify, Musixmatch, Google Search)
- Support for different languages, including English translations
- Automatic alternate language lyrics detection and caching
- Modern web frontend
-
Clone the repository:
git clone https://github.com/vwkyc/lyriclocate.git cd lyriclocate
-
Create a virtual environment and activate it:
python -m venv venv venv\Scripts\activate # On Windows source venv/bin/activate # On Unix/MacOS
-
Install the required packages:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the project root:GENIUS_CLIENT_ACCESS_TOKEN=your_genius_api_key SPOTIFY_CLIENT_ID=your_spotify_client_id SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
Note: The service can work without API keys by using web scraping methods.
-
Start the server:
cd src && python main.py
-
Access the service:
- Web Interface: http://localhost:19999
- API Endpoints:
# Using title and artist curl -X GET "http://localhost:19999/api/get_lyrics?title=Sleepless&artist=deadmau5" # Using Spotify URL curl -X GET "http://localhost:19999/api/get_lyrics_from_spotify?spotify_url=https://open.spotify.com/track/781KGu6ckiXdOYmgkzRJ42"
Fetch lyrics using song title and artist.
Query Parameters:
title
(required): Song titleartist
(required): Artist namelanguage
(optional): Target language code (e.g., 'en' for English)
Fetch lyrics using a Spotify track URL.
Query Parameters:
spotify_url
(required): Full Spotify track URLlanguage
(optional): Target language code (e.g., 'en' for English)
Responses:
200 OK
: Returns lyrics JSON object404 Not Found
: Lyrics not found
The SQLite database (lyriclocate/cache/lyrics.db
) uses the following schemas:
CREATE TABLE IF NOT EXISTS lyrics (
id INTEGER PRIMARY KEY AUTOINCREMENT,
cache_key TEXT UNIQUE,
title TEXT,
artist TEXT,
language TEXT,
lyrics TEXT,
timestamp DATETIME,
UNIQUE(title, artist, language)
);
CREATE TABLE IF NOT EXISTS spotify_cache (
id INTEGER PRIMARY KEY AUTOINCREMENT,
spotify_url TEXT UNIQUE,
title TEXT,
artist TEXT,
timestamp DATETIME
);
GENIUS_CLIENT_ACCESS_TOKEN
: (Optional) Your Genius API keySPOTIFY_CLIENT_ID
: (Optional) Your Spotify API client IDSPOTIFY_CLIENT_SECRET
: (Optional) Your Spotify API client secret
The service will use web scraping as a fallback if API keys are not provided.
Run in development mode with auto-reload:
uvicorn main:app --reload --host 0.0.0.0 --port 19999