Skip to content

Repository files navigation

Spicetify WebSocket Client Extension

GitHub License GitHub Release GitHub Release Downloads

A lightweight, feature-rich JavaScript extension for Spicetify that acts as a real-time bi-directional bridge between the Spotify Desktop Client and a WebSocket server (e.g., Python).


✨ Features

  • Native Settings UI: Access configuration settings directly inside Spotify by clicking your Profile Picture.
  • API Key Authentication: Optional security token support to protect incoming commands and authenticate outgoing push events.
  • WSS / Secure Connections: Full support for encrypted wss:// connections for remote setups or local SSL environments.
  • Automatic Reconnection: Safely attempts auto-reconnecting if the server drops or restarts.
  • Real-Time Push Events: Emits instant WebSocket events on player state changes:
    • InitialState: Dispatched immediately upon WebSocket connection (includes live-patched progress timestamp).
    • SongChanged: Triggered on track changes.
    • PlayPauseChanged: Triggered when playback is paused or resumed.
    • VolumeChanged: Triggered on volume adjustments (uses trailing debounce to avoid network spam).
    • RepeatChanged: Triggered when repeat mode is changed.
    • ShuffleChanged: Triggered when shuffle mode is toggled.
    • SeekChanged: Triggered only when manually seeking or scrubbing through a track.
    • Ping: Triggered periodically every 30 seconds as a heartbeat.
  • Full Control Commands: Supports incoming JSON requests to control playback, volume, shuffle, repeat, seeking, and status queries.

⚙️ Configuration & Settings

You can configure the extension directly within Spotify:

  1. Click on your Profile Picture in the top-right corner of Spotify.
  2. Click Connect API Settings.
  3. Adjust your settings in the popup modal:
    • WebSocket Server URL: Default is ws://127.0.0.1:9090. Use wss://IP:PORT:9090 for encrypted connections or wss://DOMAIN:PORT for remote connections.
    • API Key / Secret Token (Optional): Set a custom secret token matching your server configuration for authenticated setups.
    • Reconnect Interval (ms): Set how fast the extension attempts to reconnect on disconnect (Minimum 1000ms).

📥 Installation

Manual Installation

  1. Download spicetify-connect-api.js.

  2. Place the file in the appropriate path for your operating system:

    • Windows: C:\Users\%username%\AppData\Roaming\spicetify\Extensions\ (Paste in Win + R)
    • Linux / macOS: ~/.config/spicetify/Extensions/
  3. Enable the extension in your terminal:

spicetify config extensions spicetify-connect-api.js
  1. Apply the changes:
spicetify apply

🐍 Recommended Python Library

If you are building a Python application to interact with this extension, use the companion Python package:

👉 tobfd/spicetify-websocket

It handles the WebSocket server setup, SSL/WSS contexts, API Key verification, event listeners, response matching, and typed command execution out of the box!


📡 WebSocket API Specification

By default, the extension connects to ws://127.0.0.1:9090.

Incoming Requests (Server -> Spotify Client)

Send JSON messages in the following structure (include "token" if API Key is set in settings):

{
  "requestName": "SetVolume",
  "requestId": "unique-id-123",
  "token": "your-optional-api-key",
  "payload": {
    "level": 0.8
  }
}

Available Commands

Request Name Payload Parameters Description
Ping None Responds with { "message": "Pong", "timestamp": ... }.
Play None Resumes playback.
Pause None Pauses playback.
TogglePlay None Toggles play/pause state.
NextSong None Skips to the next track.
PreviousSong / Back None Standard Spotify back action (resets to 00:00 if playing > 2s).
ForcePreviousSong / ForceBack None Forces skip to the actual previous track regardless of elapsed time.
SetVolume level (float 0.0 - 1.0) Sets the volume level.
SetRepeat mode (0: Off, 1: All, 2: One) Sets repeat mode.
SetShuffle state (boolean) Enables/disables shuffle.
SetMute state (boolean) Mutes/unmutes audio.
PlayUri uri or url (string) Plays an item via URI (spotify:track:...) or URL (https://open.spotify.com/...).
Seek position (number in ms) Seeks to a specific track position in milliseconds.
GetPlayerState None Returns full player state snapshot (with patched live position_as_of_timestamp).
GetCurrentTrack None Returns active track object.
GetVolume None Returns current volume level.
GetPlayPause None Returns current play/pause status.

Outbound Event / Response Format (Spotify Client -> Server)

Event Push Notification

Emitted event types include: InitialState, SongChanged, PlayPauseChanged, VolumeChanged, RepeatChanged, ShuffleChanged, SeekChanged, Ping.

{
  "eventName": "SongChanged",
  "token": "your-optional-api-key",
  "payload": { ... }
}

Command Response

{
  "eventName": "Response",
  "requestId": "unique-id-123",
  "token": "your-optional-api-key",
  "success": true,
  "payload": { ... }
}

About

A lightweight, standalone JavaScript extension for Spicetify that acts as a real-time bi-directional bridge between the Spotify Desktop Client and a WebSocket server.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Used by

Contributors

Languages