A small PHP API for adding Spotify tracks to a playlist – including OAuth login, automatic removal of played songs, and simple integration with Streamer.bot (Channel Points / Bits) via an included Node script.
- 🎧 Add track via Spotify URL or
spotify:track:URI - ⭐ Favorite current track or link: Save the currently playing song or a provided Spotify track to a separate favorites playlist (duplicates prevented)
- 🎵 Now Playing (read-only): Query the currently playing Spotify track without modifying any playlist (ideal for OBS overlays)
- 🔐 OAuth login (stores login & refresh token automatically — now supports MAIN & AUTOCLEAR)
- 🧹 Auto-clean: Removes already played songs from the playlist (with a 20-second buffer and state tracking)
- 🗑️ Clear playlist via endpoint
- ⚙️ .env configuration (Client ID/Secret, Redirect URI, Playlist ID, Favorites Playlist ID, Refresh Tokens for MAIN & AUTOCLEAR)
- 🤝 Streamer.bot compatible:
fetch.jsreads%rawInput%/%message%and returns a single-line response for%output1%
- PHP ≥ 8.1 with cURL
- Web server (local or public)
- Node.js (only for
fetch.js/fetch_nowplaying.js) - Spotify Developer Account + two apps
- MAIN → For song requests
- AUTOCLEAR → For automatic cleanup
- Add Redirect URI in both apps (must match
.env) - Required scopes:
playlist-modify-private,playlist-modify-public,user-read-playback-state
git clone <YOUR-REPO>.git
cd Songrequest
cp .env.example .envhttps:///login.php?app=main
https:///login.php?app=autoclear
POST /add.php
POST /fav.php
- Without input → saves currently playing track
- With Spotify link → saves provided track
- Duplicates are prevented
POST /song.php
- No input required
- Returns the currently playing Spotify track
- Read-only (no playlist or favorites modification)
Example response:
{
"ok": true,
"message": "🎵 Aktueller Song: Artist — Title",
"track_id": "xxxxxxxxxxxxxxxxxxxxxx"
}If nothing is playing:
{
"ok": false,
"error": "Kein aktiver Spotify-Track"
}SPOTIFY_CLIENT_ID_MAIN=
SPOTIFY_CLIENT_SECRET_MAIN=
SPOTIFY_REFRESH_TOKEN_MAIN=
SPOTIFY_CLIENT_ID_AUTOCLEAR=
SPOTIFY_CLIENT_SECRET_AUTOCLEAR=
SPOTIFY_REFRESH_TOKEN_AUTOCLEAR=
SPOTIFY_REDIRECT_URI=https://your-host/callback.php
SPOTIFY_PLAYLIST_ID=PLAYLIST_ID
SPOTIFY_FAV_PLAYLIST_ID=FAVORITES_PLAYLIST_IDCommand:
!favsong
!favsong https://open.spotify.com/track/<ID>
Environment:
URL=https://your-host/fav.php
RAW=%rawInput%
MSG=%message%
NODE_TLS_REJECT_UNAUTHORIZED=0
Command:
!song
Environment:
URL=https://your-host/song.php
NODE_TLS_REJECT_UNAUTHORIZED=0
Note:
RAWandMSGmust not be set- Intended for read-only usage (e.g. OBS Now Playing overlay)