Source Code
YTMusic Librarian
This skill uses the ytmusicapi Python library to interact with YouTube Music.
Prerequisites
- Python 3.x
ytmusicapipackage:pip install ytmusicapi- Authentication file (
oauth.jsonorbrowser.json) in the skill folder.
Setup Instructions
Install the library:
pip install ytmusicapiGenerate Authentication (The "cURL Handshake"):
- Open Microsoft Edge and visit music.youtube.com (ensure you are logged in).
- Press
F12to open DevTools, go to the Network tab. - Click your Profile Icon -> Library on the page.
- Look for a request named
browsein the network list. - Right-click the
browserequest -> Copy -> Copy as cURL (bash). - Paste that cURL command into a file named
headers.txtin the skill folder. - Run the following Python snippet to generate
browser.json:from ytmusicapi.auth.browser import setup_browser with open('headers.txt', 'r') as f: setup_browser('browser.json', f.read()) - Ensure
browser.jsonis located in the skill folder.
Verify:
python -c "from ytmusicapi import YTMusic; yt = YTMusic('browser.json'); print(yt.get_library_songs(limit=1))"
Workflows
Library Management
- List songs/albums:
yt.get_library_songs(),yt.get_library_albums() - Add/Remove:
yt.rate_song(videoId, 'LIKE'),yt.edit_song_library_status(feedbackToken)
Playlist Management
- Create:
yt.create_playlist(title, description) - Add Tracks:
yt.add_playlist_items(playlistId, [videoIds]) - Remove Tracks:
yt.remove_playlist_items(playlistId, [videoIds])
Metadata & Discovery
- Get Lyrics:
yt.get_lyrics(browseId) - Get Related:
yt.get_watch_playlist(videoId)->related