Automate YouTube Music to Spotify with Python

Imdad Codes
3 min readNov 20, 2020

--

A tutorial on how to automate adding songs from YouTube to Spotify

With a free weekend ahead, I wanted to try something different. Could I spin up a program to automate adding songs from YouTube to Spotify using Python?

Now a quick side note. If you’re learning Python and need some help, check out this book here. It’s probably the best book to learn Python and sits proudly on my bookshelf.

Whether it’s Mellow Beats playing in the background as I work or some of my favourite 90’s Rap/Hip-Hop on a long run, I’m an avid Spotify user. It’s quick, snappy and for the most part it has every song I ever want to listen to.

However, it’s not great for discovering new music. As of 2020, it’s been reported that Spotify have more than 50 million songs — a whooping amount. But guess what, YouTube have even more at 60 million.

Despite both platforms having a load of songs, I find YouTube’s recommendations for new music to be much better. Spotify take the time to curate recommendations based on patterns in your saved songs. Using their funky algorithms, they analyse and compare attributes across millions of songs to better identify what you like. This helps them to build a model of youre preferences and use that to recommend songs to you. Some of the features they look at are a song’s energy, danceability, acoustics, liveness, loudness, speechiness and much much more. Take a look here.

What features Spotify looks for in songs for recommendations
What features Spotify analyse in a Track

Now as good as this looks, it doesn’t seem to do a great job (for me at least). I can’t pinpoint why but it rarely recommends me songs that I like and go on to save.

When I binge on YouTube, sometimes I find a song that I like. Since Spotify is my go-to music player, I’d have to switch to the app and search for the song on Spotify and then add it to my playlist. Switching windows, searching, finding the right song — it’s quite cumbersome. In some cases the song might not even be on Spotify.

In any case, I had a free weekend and thought I’d look into automating this whole process. Could I write a program that takes all of the songs that I’ve saved on YouTube and have them be added automatically to Spotify?

Spoiler alert: that’s exactly what I did. Here’s the full tutorial on how to automate adding songs from YouTube to Spotify in case you want to give it a go:

For the full source code, click here.

You can also reach me on my Instagram, Twitter, YouTube and TikTok.

--

--

Imdad Codes

Cofounder and CTO @ LiveLinkAI | Creator @imdadcodes (10M+ Reach)