How to get youtube mix playlist?

Viewed 3056

Using Python 3, I was able to get a playlist and get an individual video, but I want to get the mix playlist of each user (public mix), since every user see different mixes.

Should I authenticate users using google auth and then grab the mix like I grab a normal playlist? If so, how to send the auth token with Youtube's API request? I couldn't find anything related to the mix in the docs.

Do mixes have a unique URL that I could use to grab them without authentication?

I'm currently using Pafy, it's a wrapper for Youtube's API, but neither that library nor the official API has a way to get the info off Youtube's mix, my code is below

def get_youtube_playlist(url):
    playlist = pafy.get_playlist(url)
    for item in playlist['items']:
        return item['pafy'].title

That works with playlists, not mixes.

1 Answers

I don't think that YouTube API has the required functionality for retrieve the mix playlist (and I couldn't find any info about it, actually).

Saying this, I want share the discovery I made:


Let's say you want a mix from the video "Eminem - Lose Yourself (Explicit)".

This is the URL of the video:

Eminem - Lose Yourself (Explicit)

https://www.youtube.com/watch?v=nPA2czkOsFE

If you want get the mix playlist of this video, you can modify the URL as follows:

Mix: Eminem - Lose Yourself (Explicit)

https://www.youtube.com/watch?v=nPA2czkOsFE&start_radio=1&list=RDnPA2czkOsFE

These additional parameters are found in mix playlists generated by YouTube.

Explanation:

  • start_radio=1: No idea, IMHO, but if anyone can find any information about it, please, consider edit this question and add it.

  • list=RD: IMHO, this settings indicates that the declared videoId will be used for generate the mix playlist - by adding the "RD" letters + videoId.

So, if you enter the modified URL, you'll get: Mix: Eminem - Lose Yourself (Explicit).


Making more testings, I discovered also that the start_radio=1 is not needed for "create" an mix playlist using a given video.

Using other example, let's say: Ludwig Van Beethoven's 5th Symphony in C Minor (Full):

This is the URL:

Ludwig Van Beethoven's 5th Symphony in C Minor (Full)

https://www.youtube.com/watch?v=fOk8Tm815lE

After the modifications made in the URL, the result is:

Mix: Ludwig Van Beethoven's 5th Symphony in C Minor (Full)

https://www.youtube.com/watch?v=fOk8Tm815lE&list=RDfOk8Tm815lE

N.B that in this case, the start_radio=1 is not required and the result will be: Mix: Ludwig Van Beethoven's 5th Symphony in C Minor (Full)


Side note: I really hope this discovery won't be removed.

Related