20
Imagine using Spotify - Nerding Out Episode 1
Well yeah why pay for spotify if can use VLC media player, a text file, a few youtube links and a small python script to listen to your playlist. Why? cuz you know thats the stuff I love to do and if this doesnt interest you, hey youre getting a Ad-Free Music Player without anyone collecting your data. And yeah all of this stuff is open-source, even the libraries i am using too
Skip to the end if you just want the code
You will need some stuff to get this project done, but I guess you probably have some of it or all of it already on your machine. Ok so this is the stuff you will need
Yeah lemme tell you. Imagine you know you use a custom music player that you are using to play songs at a party and then your non-existent friend asks, "hey wheres the equiliser" or "hey i wanna see the music video" or even "hey can you add subtitles" and then you don't have any answer because you didn't code that part out. VLC will help you in those situations, its pretty lightweight but it will help you get low-level customization done
Also im lazy, let VLC do the hard part
First I assume you already have VLC on your computer. Also I assume you are on Windows. Now the thing is that VLC ships with command line tools too. To enable these you need to add the path to these command line tools in the PATH environment variable.
To do so:
C:\Program Files\VideoLAN\VLC\
or
C:\Program Files (x86)\VideoLAN\VLC\
if these folders exist, you can move ahead

Or alternatively, you can open it from the command line


Then close the window
vlc
and check if any error is raised. If successful it should open vlc media playerCreate a python file, anywhere really and open it in your favorite code editor
os
and random
but random is optional (we will use it for shuffling songs but some people dont like it)
import os
import random
playlist.txt
fileThis is where all hyperlinks will be stored. you can execute
copy NUL playlist.txt
to create this file tooAdd a few songs from your playlist, here are some to help you out
https://www.youtube.com/watch?v=dQw4w9WgXcQ
https://www.youtube.com/watch?v=QH2-TGUlwu4
https://www.youtube.com/watch?v=w0AOGeqOnFY
to do so write a simple read mode
open
statement, something like thisfile = open('playlist.txt', 'r').read().split('\n')
Here we also split the file on each newline hence creating a list, so each link must be on a separate line
printing the output of file we should get something like this
['https://www.youtube.com/watch?v=dQw4w9WgXcQ', 'https://www.youtube.com/watch?v=QH2-TGUlwu4', 'https://www.youtube.com/watch?v=w0AOGeqOnFY']
random.shuffle(file)
Omit this line if you don't like your playlist shuffled
Now we append all values of that list from above. We will see the importance of it below. We do it using this for loop
videos = ''
for i in file:
videos+= f"{i} "
printing the output of videos we get something like this
https://www.youtube.com/watch?v=w0AOGeqOnFY https://www.youtube.com/watch?v=QH2-TGUlwu4 https://www.youtube.com/watch?v=dQw4w9WgXcQ
As you can see, all of them are in a single list
os.system(f'vlc --no-video {videos}')
we use the
--no-video flag
because we are listening to songs, not seeing their YouTube videos. This should also cut down on bandwidth usageExecute the file and enjoy your playlist
this is all the code we discussed here
import os
import random
file = open('playlist.txt', 'r').read().split('\n')
random.shuffle(file) # Shuffle the Playlist
## Add all hyperlinks to a single string
videos = ''
for i in file:
videos+= f"{i} "
## Run it all
os.system(f'vlc --no-video {videos}')
Find the full code here https://github.com/akionsight/Imagine-Using-Spotify
Credits to this blog from vlchelp telling me about how to add VLC to path
This is the first episode of this series, hope you like it and please tell me in the comments if you liked this blog or not.
Thanks, cya
20