as

Projects / Music Analyzer

Music Analyzer

A local Python app. It reads your Spotify top tracks, groups them by artist genre, and shows audio features next to them.

Why

Spotify will hand you a playlist. It will not show you that half your long-term top tracks sit in two genres, or which songs are close enough in tempo and key to sit next to each other. That is a few API calls and a window.

Diagrams

A solid outline is the path in the repo. A dashed outline is the alternative that shape is refusing.

SpotifyAPI.py uses spotipy. The scopes in the file are playlist-modify-private and user-top-read. Forty long-term top tracks are grouped by the union of their artists’ genres. Pairs inside a 3.1 tempo band are tiered by key distance.

flowchart TD
  oauth["spotipy OAuth"]
  top["40 long-term top tracks"]
  genre["Union of artist genres"]
  feats["Audio features"]
  pairs["Tempo within 3.1, then key tiers"]
  oauth --> top --> genre
  top --> feats --> pairs
  class oauth,top,genre,feats,pairs chosen
          

Energy and danceability are fetched and then ignored by the pairing. The tiers use tempo and key only. Client id and secret are empty strings in the file. You fill them in locally.

flowchart TD
  q{Which songs sit together}
  q -->|"tempo band, then distance on the circle of fifths"| key["Five key tiers"]
  q -->|"energy and danceability"| other["Features the pairing ignores"]
  class key chosen
  class other rejected
          

Why this shape

SpotifyAPI.py uses spotipy and a Tkinter window. The OAuth scopes in the file are playlist-modify-private and user-top-read. Top tracks are the long-term list, 40 of them. Genres come from the artists, and a track lands in every genre any of its artists carries. Audio features on a track are the usual Spotify set: acousticness, danceability, energy, instrumentalness, liveness, loudness, speechiness, tempo, time signature, and key, plus name, album, and popularity.

The pairing view only keeps pairs whose tempos differ by 3.1 or less. Same key is tier one. A key distance of 5, on the circle, is tier two. A distance of 2 or less is tier three. 4 or less is tier four. Anything else in that tempo band is tier five. Client id and secret are blank strings in the file. You fill them in locally.

Where it breaks

A track with three artists lands in the union of their genres, so a feature can file a song under a genre you would not. The pair tiers use tempo and key only. Energy and danceability are fetched and then ignored by the pairing. Spotify’s audio-features route has also changed out from under older clients. If that call comes back empty, the tiers have nothing to sort. And the keys live in the source file. A real secret committed there would be a real leak. Right now the strings are empty.