ytmusicapi-rs
A Rust library for the YouTube Music API.
[!NOTE] π§ Work in Progress: search, uploads, and some library management features are not yet supported.
Features
- π Browser cookie authentication
- π Playlist APIs: List library playlists, get playlist tracks
- βοΈ Playlist edits: Add/remove/move tracks between playlists
- β€οΈ Likes: Like and unlike songs
- π Pagination: Automatic handling of large playlists
- π¦ Idiomatic Rust: Builder pattern, strong typing, async/await
Installation
Add to your Cargo.toml:
[]
= { = "0.3.0" }
= { = "1", = ["rt-multi-thread", "macros"] }
Quick Start
1. Get Your Browser Headers
- Open YouTube Music in your browser and log in
- Open Developer Tools (F12) β Network tab
- Find any request to
music.youtube.com - Copy the
cookieandx-goog-authuserheaders - Save as
headers.json:
2. Use the Library
use ;
async
API Reference
YTMusicClient
| Method | Description |
|---|---|
get_library_playlists(limit) |
Get all playlists from your library |
get_playlist(id, limit) |
Get a playlist with its tracks |
get_liked_songs(limit) |
Get your liked songs playlist |
create_playlist(title, description, privacy) |
Create a new playlist |
delete_playlist(id) |
Delete a playlist |
add_playlist_items(id, video_ids, allow_duplicates) |
Add videos to a playlist |
remove_playlist_items(id, tracks) |
Remove playlist items (requires set_video_id) |
move_playlist_items(from, to, tracks, allow_duplicates) |
Move items between playlists |
rate_song(video_id, rating) |
Like/dislike/clear rating for a song |
like_song(video_id) |
Like a song |
unlike_song(video_id) |
Remove like/dislike from a song |
Types
Playlist- Full playlist with metadata and tracksPlaylistSummary- Brief playlist info (for library listing)PlaylistTrack- Track within a playlistCreatePlaylistResponse- Response with newly created playlist IDMovePlaylistItemsResult- Responses from moving items between playlistsPrivacy- Playlist privacy enum (PUBLIC,PRIVATE,UNLISTED)LikeStatus- Rating enum (LIKE,DISLIKE,INDIFFERENT)Song- Song metadata fromget_songArtist,Album,Author,Thumbnail- Common types
Examples
Run the examples:
Acknowledgements
This library is a Rust port of ytmusicapi.
Contributing
PRs are welcome!
Please run cargo fmt and cargo clippy before submitting.
If youβre changing behavior (e.g. stricter parsing), document it in the PR.
Support
If this crate saves you time or helps your work, support is appreciated:
License
This project is licensed under the MIT License; see the license file for details.