Your Spotify: Tracking Your Listening Habits

Mar 26, 2023 | Data Science

YourSpotify is an innovative self-hosted application designed for music enthusiasts. It automatically tracks what you listen to on Spotify and offers you a sophisticated dashboard to explore detailed statistics about your listening habits. This article will walk you through the setup process and provide troubleshooting tips to ensure a smooth experience.

Table of Contents

Prerequisites

Before diving into the installation process, ensure that you meet the following prerequisites:

  • Have a Spotify application ID created through their dashboard.
  • Provide the **Server** environment with the **public** and **secret** key of the application.
  • Specify an **authorized** redirect URI in the docker-compose file.

Installation

There are two primary methods to install YourSpotify: using Docker or locally.

Using Docker

To host your application through docker-compose, utilize the following setup:

version: '3.8'
services:
  server:
    image: yooooomiyour_spotify_server
    restart: always
    ports:
      - 8080:8080
    links:
      - mongo
    depends_on:
      - mongo
    environment:
      API_ENDPOINT: http://localhost:8080
      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: yooooomiyour_spotify_client
    restart: always
    ports:
      - 3000:3000
    environment:
      API_ENDPOINT: http://localhost:8080

Think of the above setup as a recipe to bake a cake. Each ‘ingredient’ (service) has its own role:

  • Server: The main chef who prepares the dish.
  • Mongo: The pantry storing all your ingredients (data).
  • Web: The waiter, delivering information to your table (web app).
Just like perfecting a cake requires precise instructions, ensure that the variables and versions are accurately defined for the best results.

Installing Locally (Not Recommended)

If you choose to install locally, follow the instructions provided here. However, it’s worth noting that this method is not advisable.

Environment Variables

Environment variables help customize your application’s experience depending on your needs. Here’s a brief overview:

Variable                     Default Value        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
SPOTIFY_SECRET                REQUIRED             The secret key of your Spotify application
TIMEZONE                      Europe/Paris        The timezone of your stats
MONGO_ENDPOINT                mongodb:mongo:27017/your_spotify  The Mongo database endpoint
LOG_LEVEL                     info                The log level for debugging
CORS                          _not defined_       Allowed origins for requests
COOKIE_VALIDITY_MS           1h                  Authentication cookie validity
MAX_IMPORT_CACHE_SIZE        Infinite            Maximum element limit when importing data

CORS

If you don’t specify CORS, it defaults to authorize only the CLIENT_ENDPOINT origin. To allow multiple origins, list them separated by commas. To permit all origins (which might raise security concerns), set the value to an insecure option.

Creating the Spotify Application

Follow these steps to create a Spotify application for **YourSpotify**:

  1. Navigating to the Spotify dashboard.
  2. Click **Create app** and fill in required information.
  3. Set the redirect URI for your server using the standard suffixes.
  4. Enable **Web API** and accept terms.
  5. Access **Settings** to copy the public and secret keys into your docker-compose file.

Importing Past History

YourSpotify can import past listening data. It provides two methods for this purpose:

Supported Import Methods:

Privacy Data

Takes a maximum of 5 days. Only retrieves history from the past year. Follow the instructions in your account settings.

Full Privacy Data

Takes up to 30 days but retrieves history from the day you created your account. Follow the same procedure as above for full access.

Troubleshoot

Encountering issues while importing data? Here are some common problems and solutions:

  • If the server reboots, the import may fail.
  • A request failing ten times in a row can also lead to import issues.
  • Retry failed imports through the **Settings** page, but clean up any previous failed attempts to avoid complications.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

FAQ

  • How can I block new registrations? Use the admin account to navigate to the **Settings** page and hit **Disable new registrations**.
  • What if my songs don’t synchronize? This could indicate revoked access on your Spotify account. Use the **Relog to Spotify** button in Settings to rectify.
  • Timezone mismatches? Users can set their timezone in settings, while the device’s timezone will apply to other actions.

External Guides

For additional resources, check out this installation tutorial.

Contributing

Have suggestions or found issues? Feel free to open an issue on GitHub. Your input is invaluable!

Sponsoring

If you appreciate the work put into this project and want to support its development, consider sponsoring it.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox