REST API service for streaming Spotify tracks using go-librespot.
This service provides a REST API for downloading and streaming Spotify tracks as OGG Vorbis audio. It uses go-librespot as a library to interact with Spotify's API and handle audio streaming.
- 🎵 Stream Spotify tracks as WAV (PCM audio)
- 📊 Get track metadata (title, artist, album, duration, artwork) via Spotify Web API
- 🔍 Search for tracks (coming soon)
- 💿 Get album and playlist information (coming soon)
- 💾 In-memory caching for frequently played tracks
- 🔐 Interactive authentication with Spotify
- 🎛️ Configurable audio quality (96, 160, 320 kbps)
- Go 1.25 or higher
- Spotify Premium account (required for audio streaming)
- Native libraries (automatically handled by go-librespot):
- libogg
- libvorbis
- libflac
git clone https://github.com/nezuchan/spotify-streamer.git
cd spotify-streamer
go build -o spotify-streamer ./cmd/serverdocker pull ghcr.io/nezuchan/spotify-streamer:latestOr with docker-compose:
# Create config.yaml from example
cp config.example.yaml config.yaml
# Edit config.yaml with your settings
# Start the service
docker-compose up -dDownload pre-built binaries from the Releases page.
Create a config.yaml file in the same directory as the binary:
server:
port: "8080"
host: "0.0.0.0"
librespot:
device_name: "Spotify-Streamer"
device_type: "computer"
credentials:
type: "interactive"
audio:
bitrate: 320
normalisation: true
normalisation_pregain: 0
state_path: "./state.json"
cache:
enabled: true
max_tracks: 100
ttl: 3600
log_level: "info"port: HTTP server port (default: "8080")host: HTTP server host (default: "0.0.0.0")
device_name: Name of the Spotify device (default: "Spotify-Streamer")device_type: Device type (default: "computer")credentials.type: Authentication method ("interactive" or "stored")audio.bitrate: Audio quality in kbps (96, 160, or 320)audio.normalisation: Enable audio normalization (default: true)audio.normalisation_pregain: Pregain in dB (-5 for quiet, 0 for normal, +3 for loud)state_path: Path to store authentication state (default: "./state.json")
enabled: Enable in-memory track caching (default: true)max_tracks: Maximum number of tracks to cache (default: 100)ttl: Time-to-live for cached tracks in seconds (default: 3600)
log_level: Log level (trace, debug, info, warn, error)
./spotify-streamer -config config.yamlOn first run with interactive authentication, you'll need to:
- Open the provided URL in your browser
- Log in to your Spotify account
- Authorize the application
- The service will save your credentials to
state.jsonfor future use
GET /healthResponse:
{
"status": "ok",
"authenticated": true,
"username": "your_spotify_username"
}GET /track/{track_id}Example:
curl http://localhost:8080/track/3n3Ppam7vgaVa1iaRUc9LpResponse:
{
"id": "3n3Ppam7vgaVa1iaRUc9Lp",
"title": "Mr. Brightside",
"artist": "The Killers",
"artists": ["The Killers"],
"album": "Hot Fuss",
"duration": 222000,
"uri": "spotify:track:3n3Ppam7vgaVa1iaRUc9Lp",
"url": "https://open.spotify.com/track/3n3Ppam7vgaVa1iaRUc9Lp",
"artwork": "..."
}GET /stream/{track_id}Example:
curl http://localhost:8080/stream/3n3Ppam7vgaVa1iaRUc9Lp -o track.wavReturns WAV audio stream (16-bit PCM, 44.1kHz, stereo).
GET /search?q={query}Example:
curl "http://localhost:8080/search?q=mr+brightside"(Coming soon)
GET /album/{album_id}(Coming soon)
GET /playlist/{playlist_id}(Coming soon)
This service is designed to work with Nezulity, a Discord music bot. Nezulity can use this service as a source for Spotify tracks:
- Start the spotify-streamer service
- Configure Nezulity with
LIBRESPOT_URL=http://localhost:8080 - Nezulity will use the
/trackand/streamendpoints to play Spotify tracks
go build -o spotify-streamer ./cmd/servergo test ./...spotify-streamer/
├── cmd/
│ └── server/ # Main application entry point
├── config/ # Configuration management
│ ├── config.go # Config loading and parsing
│ ├── state.go # State persistence
│ └── logger.go # Logger adapter for go-librespot
├── server/ # HTTP server and handlers
│ ├── server.go # HTTP server and routes
│ ├── librespot.go # go-librespot integration
│ └── stream_manager.go # Track download and caching
├── internal/
│ └── models/ # Data models and responses
└── config.yaml # Configuration file
- Audio is streamed as WAV (PCM) format instead of OGG Vorbis (future enhancement)
- Search, album, and playlist endpoints are not yet implemented
- No support for seeking within tracks
- Requires Spotify Premium account
- Tracks are fully downloaded before streaming begins (no progressive streaming yet)
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- go-librespot - Open source Spotify client library
- Nezulity - Discord music bot
This project is for educational purposes only. Please respect Spotify's Terms of Service and only use this with a valid Spotify Premium subscription.