ytmusicapi-rs
A Rust library for the YouTube Music API.
[!NOTE] 🚧 Work in Progress: currently implementing only playlist reading features. Search, library management, and uploads are not yet supported.
Features
- 🔐 Authentication: Browser cookies or OAuth device flow
- 📋 Playlist APIs: List library playlists, get playlist tracks
- ❤️ Liked Songs: Access your liked songs playlist
- 📄 Pagination: Automatic handling of large playlists
- 🦀 Idiomatic Rust: Builder pattern, strong typing, async/await
Installation
Add to your Cargo.toml:
[]
= { = "0.1.0" }
= { = "1", = ["rt-multi-thread", "macros"] }
Quick Start
Option A: 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:
Option B: OAuth device flow
- Create a YouTube Data API OAuth client (type: TVs and Limited Input devices)
- Run the device flow in code to obtain an
oauth.jsontoken file:
use ;
# async
You can reuse oauth.json later without repeating the flow.
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 |
Types
Playlist- Full playlist with metadata and tracksPlaylistSummary- Brief playlist info (for library listing)PlaylistTrack- Track within a playlistArtist,Album,Thumbnail- Common types
Examples
- List playlists with browser auth:
- OAuth device flow (requires
CLIENT_ID/CLIENT_SECRETenv vars):CLIENT_ID=... CLIENT_SECRET=...
TODO / Missing Parity
- Auth parity: accept fully formed OAuth headers/custom clients; visitor-id bootstrap; mobile context toggle
- Pagination/continuations: finish library playlist paging and general continuation handling for new endpoints
- Search + suggestions: search API plus suggestion fetch/remove
- Library reads/actions: library songs/albums/artists, subscriptions/channels, history add/remove, ratings, account info
- Playlists: create/edit/delete, add/remove items, rate playlists
- Browse metadata: home feed, artist/album/user/channel/podcast info, related songs, lyrics (incl. timed), taste profile get/set
- Explore/Charts and watch/queue (
get_watch_playlist) - Uploads: list upload songs/albums/artists, upload song, delete upload entity
- Podcasts: channel/podcast/episode APIs, saved episodes
Acknowledgements
This library is a Rust port of ytmusicapi.
License
MIT License - see license for details.