Spotify Playlist Generator

A scheduled Python script that scrapes new song titles and builds 🔥 playlists through the Spotify API
Alternatives To Spotify Playlist Generator
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Spotify Downloader11,674222 days ago64June 27, 202210mitPython
Download your Spotify playlists and songs along with album art and metadata (from YouTube if a match is found).
Spotiflyer8,537
7 days ago55gpl-3.0Kotlin
Kotlin Multiplatform Music Downloader, Supports Spotify / Gaana / Youtube Music / Jio Saavn / SoundCloud.
Mopidy7,654210782 months ago79April 28, 2022201apache-2.0Python
Mopidy is an extensible music server written in Python
Psst7,614
7 days ago95mitRust
Fast and multi-platform Spotify client with native GUI
Ncspot3,825
a day ago37September 17, 202299bsd-2-clauseRust
Cross-platform ncurses Spotify client written in Rust, inspired by ncmpc and the likes.
Spotify Web Api Node2,874852922 months ago50January 24, 2021160mitJavaScript
A Node.js wrapper for Spotify's Web API.
Exportify2,439
15 days ago27mitJavaScript
Export/Backup Spotify playlists using the Web API
Spotify Dl1,321
15 days ago31April 19, 202224mitPython
Downloads songs from your Spotify Playlist
Spotifyapi Net1,30812213 days ago34September 28, 20219mitC#
:sound: A Client for the Spotify Web API, written in C#/.NET
Everyones Guide For Starting Up On Wechat Network868
9 months ago7
微信互联网平民创业
Alternatives To Spotify Playlist Generator
Select To Compare


Alternative Project Comparisons
Readme

Shoutout to MyBridge for listing this project as one of the Top 10 Python Open Source Projects of June 2018!

Python Open Source

Spotify Playlist Generator

Spotify Playlist Generator is a Python script that automatically builds a new Spotify playlist each week with new music. This script was written for personal use, so the playlist creation is authorized by an access token retreived for my Spotify account. I used Windows Task Scheduler to regulate the script to run every morning at 10:00 AM on my computer.

How it works

  1. The most recently acquired Spotify access token, the script's Spotify refresh token, and a Base64-encoded string containing my "app's" client ID and secret are stored in a local SQLite table called tokens (I've excluded this database from the repository because these tokens provide read and write access to my Spotify account).
  2. When the script starts, it first checks the authority of its current access token. Since this token expires after one hour, a new one will usually have to be generated. The script uses its refresh token, which never changes, to acquire a new access token from Spotify's token service.
  3. Now that it has a valid access token, it proceeds to scrape the current top 100 songs from HotNewHipHop, located at this URL: https://www.hotnewhiphop.com/top100/ Top 100 list
  4. It parses through the page with the Beautiful Soup 4 library, building a list of "song candidates." A song qualifies as a candidate if its artist list contains at least one artist in a desiredArtists list defined at the beginning of the script (a static list of artists who I like). The binary search algorithm is used to check for matches.
  5. Then, for each song candidate, it ensures that the candidate is not a duplicate by querying the songs_added local db table for a song name and primary artist match.
  6. Songs that are not duplicates are searched through Spotify's /search endpoint. The Spotify song ids that are found (since these songs are new, many aren't on Spotify yet) are accumulated into a list.
  7. Now that the script has a list of song ids to add, it must determine whether to create a new playlist or add to the most recently created (or current) playlist. New playlist are created on Saturday. If it's a Saturday, the script uses the access token retrieved earlier to make a POST request to create a new playlist on my account, named New Songs {date}. Otherwise, it queries the local playlists_created table for the Spotify playlist id of the most recently created playlist.
  8. It then uses the playlist id and song ids to make a POST request to a Spotify endpoint that adds each song to the playlist, entering these songs into the songs_added local db table in the process.

Scheduling

This task is scheduled with Windows Task Scheduler: Spotify Task in Scheduler

Final Result

Generated Spotify Playlist

Popular Spotify Projects
Popular Playlist Projects
Popular Media Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Python
Script
Token
Spotify
Playlist
Songs