LOADING...
LOADING...
A Python automation script that builds optimised Spotify playlists for deep focus and passive study sessions. Uses the Spotify Web API to filter tracks by audio features — tempo, energy, and instrumentalness — and writes the results directly to your Spotify library.
200+
Tracks Processed
3
Playlist Profiles
5
Audio Features Used
1
Script, Zero Ads
Spotify's algorithmic playlists — Focus, Chill, Deep Work — are hit or miss. They include tracks with vocals, jarring tempo changes, or dynamics that break concentration. Building study playlists manually is tedious, and saved playlists go stale.
The goal was a script that could programmatically curate tracks from your Liked Songs or a seed playlist, filter by audio characteristics, and write the result to a fresh Spotify playlist — automatically.
Filters tracks by Spotify's audio analysis data: instrumentalness > 0.7, energy range 0.3–0.6, tempo 60–120 BPM. Configurable per profile.
Three built-in profiles: Deep Focus (strict filtering), Background Study (relaxed), and Lo-Fi Mode (tempo-bias). JSON config for custom profiles.
Generates a new playlist each run with a datestamp. Keeps your library clean — no stale tracks accumulating in one bloated list.
Uses Spotipy's PKCE flow for secure authentication. Tokens cached locally — no re-auth on repeat runs.
Works from Liked Songs, any playlist, or a mix of artists. Sampling logic avoids overrepresenting a single artist.
Profile selection, playlist size, and source via CLI args. No GUI needed — runs from a scheduled task or cron job.
The Spotify Web API returns per-track audio analysis including acousticness, danceability, energy, instrumentalness, liveness, loudness, speechiness, tempo, and valence. The script batches feature requests (max 100 tracks per call) to stay within rate limits.
Spotipy handles the OAuth dance and wraps the REST API. Scope required: user-library-read playlist-modify-private playlist-modify-public.
{
"deep_focus": {
"instrumentalness_min": 0.7,
"energy_min": 0.3,
"energy_max": 0.55,
"tempo_min": 60,
"tempo_max": 110,
"size": 40
}
}First time implementing a proper OAuth 2.0 PKCE auth flow — learned token storage, scope minimisation, and refresh handling.
Spotify limits audio feature lookups to 100 tracks per request. Batching + sleep(0.3) between calls keeps it clean.
Instrumentalness and energy alone aren't enough — some "instrumental" tracks are still jarring. Combining with loudness improves results significantly.
The real win was realising that small daily-life friction points are ideal automation candidates. Study playlists took 20 mins to automate and saved hours.
Drop me a message if you'd like the source code or a walkthrough on setting it up with your own Spotify account.
Get in Touch →