This feature is missing from every YT Music client

Recently I discovered this amazing android app called ViMusic, which can stream music from YouTube.

But it was not the beautiful and intuitive UI that surprised me, but the "Start Radio" functionality. You see, I've never used YT Music before so I had no idea this was something it could do.

After I found this feature, I immediately started searching for a client on desktop that could do the same, but to no avail. Every single one was missing this functionality.

So I started developing my own TUI client, which was actually in a decent state when I said to myself: "Why am I doing this? If I could just have the radio functionality on it's own, it would be completely fine for me."

And so I decided to scrap that entire project and just focus on the radio part. It was surprisingly easy. First I checked the ViMusic source code for some inspiration, which eventually lead me nowhere. But it gave me an idea: I went on YT Music in my browser and started playing around with it. I realized that every radio playlist looked similar to this:

https://music.youtube.com/watch?v=SOME_ID&list=SOME_PLAYLIST&start_radio=1&rv=SOME_ID

the v and rv parameters were quite easy to figure out, since they were the exact same for my use case

v specifies the currently playing song (so which song to start the radio from) and as far as I know, rv is the start of the playlist, although I didn't check that

What was tricky is figuring out how to get the id of the playlist. And after a lot of trial and error I noticed that the id of every radio started with "RDAMVM" and then 11 other characters. And my first idea was: What if I put the video id at the end of the playlist id? It is 11 characters after all.

So I tried exactly that. AND IT WORKED! Running this command gave me a list of titles that when compared to what YT Music displayed when I started a radio, matched pretty well.

yt-dlp --get-title "https://music.youtube.com/..."

Now the only remaining thing to do is 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: https://fossworld.hu/public/ytradio.sh

The ipc server is present so mpv can be controlled using json packets. (MPV documentation)