parbhatia / your_spotify

Self hosted Spotify tracking dashboard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Client CI Server CI Donate

Your Spotify

Your Spotify is a self-hosted application that tracks what you listen and offers you a dashboard to explore statistics about it! It's composed of a web server which polls the Spotify API every now and then and a web application on which you can explore your statistics.

Prerequisites

  1. You have to own a Spotify application ID that you can create through their dashboard
  2. You need to provide the Server environment the public AND secret key of the application (cf. Installation)
  3. You need to provide an authorized redirect URI to the docker-compose file

A tutorial is available at the end of this readme.

Installation

Using docker-compose

Follow the docker-compose-example.yml to host your application through docker.

version: "3"

services:
  app:
    image: yooooomi/your_spotify_server
    container_name: express-mongo
    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__
      - CORS=http://localhost:3000,http://localhost:3001
      #- CORS=all
      #- MONGO_ENDPOINT=mongodb://mongo:27017/your_spotify
      #- MAX_IMPORT_CACHE_SIZE=100000 # Number of items cached during import of past history
      #- TIMEZONE=Europe/Paris # Only affects read requests, write are in UTC time
  mongo:
    container_name: mongo
    image: mongo
    volumes:
      - ./your_spotify_db:/data/db

  web:
    image: yooooomi/your_spotify_client
    container_name: web
    restart: always
    ports:
      - "3000:3000"
    environment:
      - API_ENDPOINT=http://localhost:8080

Some ARM-based devices might have trouble with Mongo >= 5. I suggest you use the image mongo:4.4.

You can find logs in logs.log in /app in the docker in case you need to check the logs or have log driver to none in your compose. One thing you can do is volume the file so you can access it locally.

Installing locally (not recommended)

You can follow the instructions here. Note that you will still have to do the steps below.

CORS

You can edit the CORS for the server:

  • all will allow every source
  • origin1,origin2 will allow origin1 and origin2

Creating the Spotify Application

For Your spotify to work you need to provide a Spotify application public AND secret to the server environment. To do so, you need to create a Spotify application here.

  1. Click on Create a client ID
  2. Fill out all the informations
  3. Copy the public and the secret key into your docker-compose file under the name of SPOTIFY_PUBLIC and SPOTIFY_SECRET respectively
  4. Add an authorized redirect URI corresponding to your server location on the internet adding the suffix /oauth/spotify/callback,
    1. use the EDIT SETTINGS button on the top right corner of the page.
    2. add your URI under the Redirect URIs section
    • i.e: http://localhost:3000/oauth/spotify/callback or http://home.mydomain.com/your_spotify_backend/oauth/spotify/callback

Importing past history

By default, Your Spotify will only retrieve data for the past 24 hours once registered. This is a technical limitation. However, you can:

  • Request your privacy data at Spotify to have access to your history for the past year here.
  • Optional: once received (after a week), you can ask for extended data that will get you your whole history since the creation of the account. You have to write an email at privacy@spotify.com saying you want your data since the account creation.
  • Go to the settings of your account and import your StreamingHistoryX.json files.
  • Now you can follow the progress of the import with the progress bar.

It is safer to do this at the account creation. Though YourSpotify detects duplicates, some may still be inserted. However, song search is pretty accurate since it filters on artist then search for the song name.

If the server reboots, the import will be terminated. You can safely start another import with the same data as it will skip already existing items.

The import process uses cache to limit requests to the Spotify API. By default, the cache size is unlimited, but you can limit is with the MAX_IMPORT_CACHE_SIZE env variable in the server.

FAQ

How can I block new registrations?

From a logged account, go to the Settings page and hit the Disable new registrations button.

I lost the password of an account.

If you have or create another account, you can change the password based on an account id you can find in the settings. If the registrations are blocked you cannot recover your password without editing the database yourself.

Songs don't seem to synchronize anymore.

This can happen if you revoked access on your Spotify account. To re-sync the songs, go to settings and hit the Relog to Spotify button.

The web application is telling me it cannot retrieve global preferences.

This means that your web application can't connect to the backend. Check that your API_ENDPOINT env variable is reachable from the device you're using the platform from.

External guides

Contributing

If you have any issue or any idea that could make the project better, feel free to open an issue. I'd love to hear about new ideas or bugs you are encountering.

Sponsoring

I work on this project on my spare time and try to fix issues as soon as I can. If you feel generous and like this project and my investment are worth a few cents, you can consider sponsoring it with the button on the right, many thanks.

About

Self hosted Spotify tracking dashboard

License:MIT License


Languages

Language:TypeScript 92.3%Language:CSS 5.1%Language:JavaScript 1.4%Language:Shell 0.6%Language:Dockerfile 0.3%Language:HTML 0.3%