This feature is missing from every YT Music client2022/08/24
Recently I discovered an amazing android app called ViMusic, which can stream music from YouTube. And the feature that fascinated me the most was the “Start Radio” functionality. I had no idea YT Music could do that.
I immediately started looking for a desktop client that could do the same thing, but to no avail. Every single one was missing this feature.
Naturally I decided to make my own TUI YouTube Music client from scratch. And it was in a pretty good state when I realised that I didn't even want a full YouTube Music client. I just need the radio.
So I scrapped the entire project and instead focused on making just the radio part, and it was surprisingly easy.
I started by checking the ViMusic source code for inspiration, which eventually lead me nowhere. But it game me an idea: I went on YT Music in my browser and started playing around with it. I realised that every radio playlist's url looked like this:
The v and rv parameters were quite easy to figure out, since they were the exact same. v specifies the currently playing song (so which song to start the radio from) and I didn't check, but presumably rv is the start of the playlist.
Getting the playlist id was a bit more tricky though. After a lot of trial and error I noticed that the id of every radio started with “RDAMVM” and then 11 other characters. Then I thought what if I put the video's id at the end of the playlist id? It is 11 characters after all.
So I tried that AND IT WORKED! Running this command gave me a list of title that when compared to what YT Music displayed when I started a radio, matched pretty well.
yt-dlp --get-title "https://music.youtube.com/watch?v=abcdefghijk&list=RDAMVMabcdefghijk&start_radio=1&rv=abcdefghijk"
Now the only remaining thing to do is to make a shell script that automatically generates that playlist url and starts playing it. The only challenge I faced during this is that while yt-dlp worked great with these “infinite” playlists, mpv would just simply ignore them and only play the first song of the playlist, which is obviously not what we want. I solved this by adding “yes-playlist=” to the extractor args of yt-dlp.
The full script can be found here.