- Published on
Your Spotify in Docker - Full Setup Guide
- Authors
- Name
- Caeden
- Github
- @0xfreak
Your Spotify is a self-hosted application designed to track your listening habits and provide a dashboard for exploring detailed statistics. It consists of a web server that periodically queries the Spotify API and a web application where you can view and analyze your listening data.
Click here for the Github repo
Prerequisites
- Obtain a Spotify application ID through the Spotify Developer Dashboard.
- Provide the Server environment with both the public and secret keys of the application.
- Specify an authorized redirect URL in the
docker-compose
file.
Installation Using Docker Compose
Follow the docker-compose-example.yml
file to host your application using Docker.
version: "3"
services:
server:
image: yooooomi/your_spotify_server
restart: always
ports:
- "8080:8080"
links:
- mongo
depends_on:
- mongo
environment:
API_ENDPOINT: http://localhost:8080 # This MUST be included as a valid URL in the Spotify dashboard!!!
CLIENT_ENDPOINT: http://localhost:3000
SPOTIFY_PUBLIC: __your_spotify_client_id__
SPOTIFY_SECRET: __your_spotify_secret__
mongo:
container_name: mongo
image: mongo:6
volumes:
- ./your_spotify_db:/data/db
web:
image: yooooomi/your_spotify_client
restart: always
ports:
- "3000:3000"
environment:
API_ENDPOINT: http://localhost:8080
Environment variables
Key | Default value (if any) | Description |
---|---|---|
CLIENT_ENDPOINT | REQUIRED | The endpoint of your web application |
API_ENDPOINT | REQUIRED | The endpoint of your server |
SPOTIFY_PUBLIC | REQUIRED | The public key of your Spotify application (cf Creating the Spotify Application) |
SPOTIFY_SECRET | REQUIRED | The secret key of your Spotify application (cf Creating the Spotify Application) |
TIMEZONE | Europe/Paris | The timezone of your stats, only affects read requests since data is saved with UTC time |
MONGO_ENDPOINT | mongodb://mongo:27017/your_spotify | The endpoint of the Mongo database, where mongo is the name of your service in the compose file |
LOG_LEVEL | info | The log level, debug is useful if you encounter any bugs |
CORS | not defined | List of comma-separated origin allowed |
COOKIE_VALIDITY_MS | 1h | Validity time of the authentication cookie, following this pattern |
MAX_IMPORT_CACHE_SIZE | Infinite | The maximum element in the cache when importing data from an outside source, more cache means less requests to Spotify, resulting in faster imports |
MONGO_NO_ADMIN_RIGHTS | false | Do not ask for admin rights on the Mongo database |
PORT | 8080 | The port of the server, do not modify if you're using Docker |
Spotify App Setup
Step 1
Open up the Spotify Developer Dashboard Click "Create app"
Step 2
Fill in all the required info set the redirect URI, corresponding to your server location on the internet (or your local network) adding the suffix /oauth/spotify/callback (/api/oauth/spotify/callback if using the linuxserver image)
.
example: http://localhost:8080/oauth/spotify/callback
or http://home.mydomain.com/your_spotify_backend/oauth/spotify/callback
Step 3
Select Web API, agree to the TOS and Save
Step 4
Back at main page for the App, open up the settings page
Step 5
Copy the Client ID and the client secret key into your docker-compose
file under the name of SPOTIFY_PUBLIC
and SPOTIFY_SECRET
respectively
After creating your application, you may need to register the users who will have access to it. (Note: The account that created the application is automatically registered.)
- Click the User Management button.
- Enter the required information: the user's name and the email associated with their Spotify account.
- (Optional) You can request an extension if you prefer not to register users manually.
Importing Past History
By default, YourSpotify retrieves data for the past 24 hours once registered. This is a technical limitation. However, you can import previous data in two ways.
The import process uses cache to limit requests to the Spotify API. By default, the cache size is unlimited, but you can set a limit with the MAX_IMPORT_CACHE_SIZE
environment variable in the server.
Spotify Account Data Download
- Request your privacy data from Spotify to access your history for the past year here.
Full Privacy Data (Recommended)
Takes a maximum of 30 days. Retrieves your entire history since the creation of your account.
- Choose the Extended streaming history method.
- Upload your files starting with
endsongX.json
. - Start your import.
Privacy Data
Takes a maximum of 5 days. Only retrieves the last year of history.
- Choose the Account data method.
- Upload your files starting with
StreamingHistoryX.json
. - Start your import.
Importing Spotify account data into your_spotify
Back in Your Spotify, open up the settings page to import your Spotify account data.
Notes & FAQ
Some ARM-based devices have trouble with MongoDB versions 5 and up. It is recommended to use the image mongo:4.4 for compatibility.
How can I block new registrations?
To block new registrations, log in with an admin account, navigate to the Settings page, and click the Disable new registrations button.
Why aren't my songs synchronizing anymore?
If your songs stop synchronizing, it might be because you've revoked access on your Spotify account. To re-sync the songs, go to Settings and click the Relog to Spotify button.
Why is the web application unable to retrieve global preferences?
If the web application cannot retrieve global preferences, it means it can't connect to the backend. Ensure that the API_ENDPOINT
environment variable is correctly set and reachable from your device.
How can a user set a specific timezone if it's different from the server's timezone?
Users can set their own timezone in the Settings page. This timezone will be used for all computed statistics, while the device's timezone will be used for everything else, such as song history.
Import Failures
An import can fail due to the following reasons:
- The server reboots.
- A request fails 10 times consecutively.
You can retry a failed import from the Settings page. If you don't want to retry, make sure to clean up your failed imports to remove the associated files. Failed imports can be cleaned up by selecting the ⋯ beside the failed install and selecting clean up.
For safer data import, it's recommended to import data at the time of account creation. Although your_spotify detects duplicates, some may still be inserted.