Menu

Building a music mini-site with data from Last.fm, Discogs, and YouTube

It’s been a little quiet on the blog recently, and the reason for that is either perfectly valid or profoundly unnecessary, depending on your viewpoint. Even I am not entirely sure which one it is.

Over the past couple of weekends (and too many late weeknights) I have used all my spare time to build a mini-site for my obsession with music. It started as a small idea to just show the current track I’m listening to, and a list of recent physical albums I added to my collection. But then it snowballed into something much more. You can view the site at music.elezea.com, or by clicking on the link in the top navigation. If you want to know a bit more about how it works, read on!

It all started when I came across Andy Bell’s mini-site for his music collection. He uses a Notion database and Last.fm to show all the music he has in his collection, and what he’s listening to. Since I also still use Last.fm (yes, it’s still around!), and all my physical music is documented on Discogs, I wanted to build a small site that uses the Last.fm and Discogs APIs to show some of that information.

But once I got started and got stuck into all the information available via those APIs, I just couldn’t stop. I still have so much more I want to do, but I know it’s time to take a break. All in all this has been such a fun and rewarding thing to spend my time on. I know the site has pretty much zero value to the world at large. But I love checking it to get more information about something I’m listening to—and it helped me take quite a few steps forward in my technical skills. So I’m choosing to call it a win.

Below are some notes about what the site does, how it works, and also what the experience was like for me (as a non-developer trying to learn).

Now playing

  • Get the most recently played track from the Last.fm API, and check if the song is currently playing or not.
  • If it’s currently playing, show the current time and a message that what you’re seeing is what I’m listening to in real-time.
  • If it’s not currently playing, mention that and show the time it was played.
  • Pull in the cover art and other data about the song from Last.fm.
  • Do a lookup for the artist and if Last.fm has data about them, show the first two tags (genres), first 3 related artists, and their bio.
  • Do another lookup to a different API endpoint for the artist’s top albums, and display data about their two most popular albums.
  • Use the YouTube API to do a lookup for the song, and embed the most relevant result in the page so that you can listen to it right there.

Top albums and artists

  • Show the top albums I listened to in the last 7 days, including play counts.
  • Show the top artists I listened to in the last 7 days, including play counts.
  • Make a separate API call for each artist to get their genres and similar artists, if that data exists on Last.fm.
  • Make another API call to get each artist’s most popular albums.

Recent purchases

  • Pull the last 6 releases I added to my Discogs collection.
  • Also pull in data about the genre, label, and release date.
  • ⏳ The Discogs API is really great, so I want to add a bunch more stuff here, but that’s also for the mythical v2 of this thing.

Random thoughts, complaints, and what’s next

  • The site is deployed with Netlify via a Github repo, and it just works. Netlify is so great.
  • I don’t care what you “real developers” say, the two biggest problems in programming are environmental variables and formatting dates. I am thankful for ChatGPT for helping me with the date formatting piece, and my colleague and friend Derek for helping to get the environmental variables to work.
  • Last.fm’s API clearly hasn’t been touched in years and the documentation isn’t great, so it’s been a bit of a mission to figure all that out. Postman has been a life-saver here to test the API calls and see what data comes back.
  • YouTube’s API has a limit of 100 search lookups per day, which feels ridiculously low. I hit that within an hour while I was building and testing it. Oops! On the upside: I am now much better at error handling. If the site hits that limit it will now show a message to that effect, and link to a direct search on YouTube for the song.
  • ⏳ I’m using YouTube only because the Spotify API makes it incredibly difficult to get an auth token. Auth tokens expire after 1 hour, and refreshing that token every hour is currently beyond my limited skills. I might come back to this as well because the Spotify API has sooo much interesting data.
  • ⏳ Another huge data source is the MusicBrainz API. I plan to spend some time wading through those docs as well to see what else I could add.
  • If you can think of any other cool things I might want to add to this, please reach out on Mastodon!