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 |
|---|---|
builder() |
Create a YTMusicClientBuilder with defaults |
is_authenticated() |
Check whether browser auth is configured |
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 |
get_song(video_id) |
Get song metadata from the player endpoint |
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 |
send_request(endpoint, body) |
Low-level API helper that sends a raw request and returns JSON |
YTMusicClientBuilder
| Method | Description |
|---|---|
with_browser_auth(auth) |
Configure browser-cookie authentication |
with_language(language) |
Set request language (default: en) |
with_location(location) |
Set location hint |
with_user(user) |
Set user profile index |
build() |
Build and validate a YTMusicClient instance |
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_songVideoDetails,Microformat,MicroformatDataRenderer- Song metadata subtypesArtist,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 for details.