A TypeScript CLI tool that fetches lyrics for Spotify songs using OAuth authentication and multiple lyrics APIs (lyrics.ovh, MusixMatch, Genius).
A Node.js TypeScript command-line application for fetching lyrics for your currently playing Spotify songs.
This skill helps you build and maintain a CLI tool that:
The application follows a service-based architecture with clear separation of concerns:
1. **SpotifyService**: Handles all Spotify-related operations
- OAuth 2.0 authentication flow
- Token management and refresh
- Fetching currently playing track information
2. **LyricsService**: Manages lyrics retrieval
- Primary source: lyrics.ovh (free, no API key required)
- Secondary source: MusixMatch (requires API key for enhanced features)
- Fallback: Genius search suggestions
Set up a TypeScript Node.js project with the following structure:
```
src/
services/
SpotifyService.ts # Spotify API integration
LyricsService.ts # Lyrics fetching logic
commands/
auth.ts # Authentication command
current.ts # Current song command
search.ts # Search command
status.ts # Status command
index.ts # CLI entry point
types.ts # TypeScript type definitions
```
Install the following packages:
Create a `.env` file with required variables:
```
SPOTIFY_CLIENT_ID=<from Spotify Developer Dashboard>
SPOTIFY_CLIENT_SECRET=<from Spotify Developer Dashboard>
SPOTIFY_REDIRECT_URI=http://localhost:8888/callback
LYRICS_API_KEY=<optional MusixMatch API key>
```
Users must register an application at [Spotify Developer Dashboard](https://developer.spotify.com/dashboard) to obtain client credentials.
Implement OAuth 2.0 Authorization Code Flow:
1. Generate authorization URL with required scopes (`user-read-currently-playing`, `user-read-playback-state`)
2. Launch local callback server on port 8888
3. Exchange authorization code for access token
4. Store tokens securely (consider using system keychain or encrypted file)
5. Implement token refresh logic before expiration
Implement a waterfall approach for lyrics retrieval:
1. **Primary**: Query lyrics.ovh API (free, no authentication)
- Endpoint: `https://api.lyrics.ovh/v1/{artist}/{song}`
- No rate limiting concerns
2. **Secondary**: Query MusixMatch API if API key is provided
- More accurate and feature-rich
- Requires API key from MusixMatch developer portal
3. **Fallback**: Provide Genius search URL
- When no lyrics are found, generate a search link
- Format: `https://genius.com/search?q={song}+{artist}`
Implement comprehensive error handling for:
Provide clear, actionable error messages to users.
Define interfaces for:
Use Commander.js to create an intuitive CLI:
While not required, consider:
```bash
spotify-lyrics auth
spotify-lyrics current
spotify-lyrics search "Bohemian Rhapsody" "Queen"
spotify-lyrics status
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/spotify-cli-lyrics-fetcher/raw