Skip to content

A discount version of the popular Spotify Wrapped feature. This project covers the usage of the Spotify API, storing data in a Supabase postgresdb and visualizing the data.

License

Notifications You must be signed in to change notification settings

Nicolai1205/Unlimited-Spotify-Wrapped

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Visualization examples

Example of a visualization of data using Plotly

image

Trevor.io daily refresh dashboard
image

Inspiration

This project was inspired by @izayl spotify-box. This repository was my first look at the possibilities the Spotify API and its usage.

Unlimited Spotify Wrapped

I've created this Python application out of my passion for music and data. It's my personal take on Spotify's Wrapped feature, delving into your musical journey. By tapping into Spotify's Web API, my script uncovers unique insights about your favorite tunes and artists, reflecting your musical tastes and listening habits.


Features

  • Insight into user's top tracks, artists, genres and basic playlist information.
  • Automated daily data collection and processing.
  • Integration with Supabase for data storage and management.
  • Coded without the use of the Spotipy Python package.
  • Simple dashboard with linecharts to track changes in music preferences. Free hosting & creation on Trevor.io.

Setup and Installation

Instructions on setting up the project, including environment setup, dependencies, and initial configuration.

Spotify Authorization Guide

Follow these steps to authorize your application to access Spotify's API.

Step 1: Create a New Spotify Application

  • Go to the Spotify Developer Dashboard.
  • Log in and create a new application.
  • Note your Client ID and Client Secret.
  • Click on Edit Settings and add http://localhost:3000 to the Redirect URIs.

Step 2: Obtain Authorization Code

  • Replace $CLIENT_ID with your actual Client ID in the URL below:
    https://accounts.spotify.com/authorize?client_id=$CLIENT_ID&response_type=code&redirect_uri=http:%2F%2Flocalhost:3000&scope=user-read-currently-playing%20user-top-read
  • Visit the modified URL, agree to allow access, and you'll be redirected to http://localhost:3000?code=$CODE.
  • $CODE in the URL is your Authorization Code.

Step 3: Acquire Access Token

  • With your Client ID, Client Secret, and the Authorization Code from the previous steps, run the following command in your terminal:
    curl -X POST -d client_id=$CLIENT_ID -d client_secret=$CLIENT_SECRET -d grant_type=authorization_code -d code=$CODE -d redirect_uri=http://localhost:3000 https://accounts.spotify.com/api/token
  • This will return your access_token and refresh_token.

Example response:

{
    "access_token": "BQBi-jz...yCVzcl",
    "token_type": "Bearer",
    "expires_in": 3600,
    "refresh_token": "AQCBvdy70...KvnrVIxe...",
    "scope": "user-read-currently-playing user-top-read"
}

Note: If you don't receive a refresh_token, repeat Step 2.


Supabase Setup Guide

Follow these steps to sign up for Supabase and set up a PostgreSQL database.


Step 1: Sign Up for Supabase

  • Visit the Supabase website.
  • You can get a free database set up with Supabase with up to 256 MB
  • Click on the "Start your project" button.

Step 2: Create a New Project

  • Once logged in, click on "New Project".
  • Fill in the project details, including the project name and database password. Remember to save the password securely, as you will need it to access your database.
  • Select the region closest to you for the best performance.
  • Click "Create Project" and wait for your project to be provisioned.

Step 3: Obtain Project Secrets

  • After your project is ready, go to the "Settings" tab in your project's dashboard.
  • Under "API", you will find your project's URL and anon key, which are needed to interact with your Supabase project.

Step 4: Set Up the Database

  • In your project's dashboard, navigate to the "SQL" section to manage your database.
  • You can use the following SQL scripts to create tables for artists, tracks, genres, and playlists:

-- Creating table for artists
CREATE TABLE artists (
    unique_key VARCHAR(700) PRIMARY KEY,
    date DATE NOT NULL,
    time_range VARCHAR(50) NOT NULL,
    artist_name VARCHAR(255) NOT NULL,
    rank INT NOT NULL
);

-- Creating table for tracks CREATE TABLE tracks ( unique_key VARCHAR(700) PRIMARY KEY, date DATE NOT NULL, time_range VARCHAR(50) NOT NULL, track_name VARCHAR(255) NOT NULL, rank INT NOT NULL );

-- Creating table for genres CREATE TABLE genres ( unique_key VARCHAR(700) PRIMARY KEY, date DATE NOT NULL, time_range VARCHAR(50) NOT NULL, genre_name VARCHAR(255) NOT NULL, count INT NOT NULL, rank INT NOT NULL );

-- Creating table for playlists CREATE TABLE playlists ( unique_key VARCHAR(700) PRIMARY KEY, date DATE NOT NULL, playlist_name VARCHAR(255) NOT NULL, total_tracks INT NOT NULL );


Step 5: Use Supabase in Your Application

  • To connect your application to Supabase, you'll need the URL and keys obtained from Step 3.
  • Refer to the Supabase documentation for guides on integrating with Python.


Setting Up Environmental Secrets in GitHub

This guide details the process of setting up environmental secrets for a GitHub repository, specifically for a project that utilizes Supabase and Spotify.


Environmental Secrets Overview

  • SUPABASE_KEY: Your Supabase key, used for authenticating requests to your Supabase project.
  • SUPABASE_URL: The URL of your Supabase project, required to connect to your Supabase database.
  • CLIENT_ID: Your Spotify application's Client ID, used for Spotify API authentication.
  • CLIENT_SECRET: Your Spotify application's Client Secret, used alongside the Client ID for Spotify API authentication.
  • REFRESH_TOKEN: A Spotify token that allows your application to refresh the access token when it expires.

Step 1: Adding Secrets to GitHub

  • Navigate to your GitHub repository.
  • Click on 'Settings' and then choose 'Secrets and variables' from the left sidebar.
  • Select 'New repository secret' to add each of the environmental secrets.
  • Enter the name of the secret (e.g., 'SUPABASE_KEY') and its corresponding value.
  • Repeat for each secret: 'SUPABASE_URL', 'CLIENT_ID', 'CLIENT_SECRET', and 'REFRESH_TOKEN'.


Important to know

Juicy little notes.

  • If you are aiming to visualize your data in Jupyter Notebooks, you may find that only 1000 rows are returned from Supabase. This limitation can be changed under the Supabase Settings, API, at the bottom and increasing max rows.
  • There is a online dashboard to track changes over time. I also have a jupyter notebook I can share with the start for visualizing data using Plotly

Contact

Feel free to contact me on any of the social platforms linked on my profile if you have any questions regarding this project.


Next steps

Cleaning up the code removing redundancies

About

A discount version of the popular Spotify Wrapped feature. This project covers the usage of the Spotify API, storing data in a Supabase postgresdb and visualizing the data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages