DEV Community

Cover image for Tuning Out Spotify: A Programmer’s Approach to Music Streaming
Red Headphone
Red Headphone

Posted on • Updated on

Tuning Out Spotify: A Programmer’s Approach to Music Streaming

In a world full of boundless musical choices, my exploration as a programmer prompted me to challenge the established norms of music platforms like Spotify. While these platforms provide a vast collection of songs readily available, there were certain aspects that consistently bothered me. The constant interruptions from ads that disturbed my rhythm and the need for a consistent internet connection started to become obstacles that I couldn’t overlook any longer. Yet, beyond these frustrations, there was an intriguing option that caught my attention — an option that aligned with my coding instincts.

mad at PC

Picture this usual scenario: a treasured YouTube playlist, carefully curated over time — a situation many of us can easily understand. Could these playlists be changed into portable MP3s, conveniently residing on our devices? However, the idea of individually downloading and converting each track appeared daunting, a task that could eat up a lot of valuable time. This is where my programming skills came to the rescue.

In this venture, two crucial tools became my allies: Google Colab and Google Drive. The former offered its computing power to execute my code, scouring the digital realm for tracks and carefully downloading them, while the latter kindly gave a home to these musical gems, crafting an organized repository that could be accessed whenever needed. To bring these melodies to life, the elegant open-source VLC Player entered the scene, seamlessly weaving the MP3s into audible experiences. Together, this fusion of Google Colab’s computational finesse, Google Drive’s storage capabilities, and VLC Player’s versatile playback features orchestrated a symphony that highlighted the beautiful blend of code and music in a programmer’s universe.


Starting this musical coding adventure requires careful planning. Here’s the simple sequence that makes up the process of getting your music:

  • Get Pytube Working: Begin by installing Pytube in Google Colab, the YouTube video downloader. Be cautious about potential issues due to delayed updates. A working fork of Pytube can usually be found in GitHub issues, serving as a useful temporary solution. This demonstrates how open-source collaboration can address challenges and provide a smoother experience.
!pip install pytube
# if PyPI release is outdated 
# !pip install git+https://github.com/pytube/pytube 
Enter fullscreen mode Exit fullscreen mode
  • Sync Google Drive: Effortlessly connect Google Colab and Google Drive for seamless data transfer.
from google.colab import drive
drive.mount('/content/drive')
Enter fullscreen mode Exit fullscreen mode
  • Bring in the Tunes: Work your magic by downloading tracks and giving life to your collection. Remember, the playlist URL you use should be either public or unlisted for this process to work.
from pytube import YouTube
from pytube import Playlist
from os import system

# if there is already music folder in drive
# system("cd drive/MyDrive && rm -r music && mkdir music") 

counter = 0
playlist_url = "{add your playlist url here}"
playlist = Playlist(playlist_url)

for url in playlist:
  music = YouTube(url).streams.filter(only_audio=True)
  counter+=1
  music.first().download(
    output_path="drive/MyDrive/music/",
    filename_prefix=str(counter).zfill(3)+" ")
Enter fullscreen mode Exit fullscreen mode

And that’s the final touch! Inside your Google Drive, the music folder holds all the songs from your YouTube playlist. This seamless blend of code and creativity is set to echo as you download and enjoy your personally crafted collection using the flexible VLC Player.

thumbs up

Top comments (0)