I was looking for a way to copy my "likes" in YouTube music over to a playlist, in the hopes of stopping YTM from losing songs I have liked. I found this script, but it didn't work for me, so I had to look for other solutions. In the end, this is what worked for me.
It's a small Python script that uses the YTMusic python library to copy tracks from my likes to a new playlist. I will try to outline the steps to run the script, but this will assume some familiarity with Python.
Hopefully this will work for others as well!
from ytmusicapi import YTMusic
yt = YTMusic('oauth.json')
playlistId = yt.create_playlist('My Playlist', "Some Description - leave blank if you want need one")
songs = yt.get_liked_songs(5000) # get 5000 liked songs, this is the maximum playlist size
videoIds = map(lambda x: x['videoId'], songs['tracks']) # convert the tracks into a list of "videoId"s
videoIds = [*set(list(videoIds))] # remove duplicate videoIds
yt.add_playlist_items(playlistId, videoIds = videoIds, duplicates = False) # add all of the videoIds to the new playlist
cd /tmp
- copy the script above into
/tmp/copy_likes.py
pip install ytmusicapi
ytmusicapi oauth
- follow the prompts, copy the URL to a browser and authenticate with your Google account to grant accesspython /tmp/copy_likes.py
rm oauth.json
- this file grants access to your YTM account, so be sure to nuke it when you are finished
it does the work but songs gets shuffled in the created playlist.
To get it as it is:
https://gist.github.com/Redbyte1/1e88e0bfbe97584792b7fbb89207b5fe
use this
use oauth.json instead of headers_auth.json
and increase the liked song counter from 500 to your desires num