Skip to content

YouTube Music: ~1000% faster playback start by getting audio from the player API instead of yt-dlp#4370

Draft
rathlinus wants to merge 1 commit into
music-assistant:devfrom
rathlinus:dev
Draft

YouTube Music: ~1000% faster playback start by getting audio from the player API instead of yt-dlp#4370
rathlinus wants to merge 1 commit into
music-assistant:devfrom
rathlinus:dev

Conversation

@rathlinus

Copy link
Copy Markdown

What does this implement/fix?

Adds a new experimental music provider, YouTube Music (Native).

It talks to the YouTube Music InnerTube API directly instead of going through ytmusicapi, yt-dlp or deno, and it doesn't need a POtoken server. You set it up by pasting the cookie from a logged-in music.youtube.com session.

On the metadata side it covers search, your library (artists, albums, tracks, playlists), album/artist/playlist pages, artist albums and top tracks, similar tracks and recommendations.

For audio it plays the premium 256k streams (itag 141 / 774) by running the player's signature/n cipher in-process with an embedded V8. Without Node, or a browser, no po_token. If that can't run for some reason it falls back to the ANDROID_VR ~150k stream so playback still works. The only new dependency is mini-racer, which ships V8 as a normal pip wheel, so this works in the standard container without anything extra installed.

The existing YouTube Music provider is left as-is; this is a separate one for now.

Tested locally against two Premium accounts: setup, search, browsing an album, and playing a premium track (itag 141, 259 kbps, streams and transcodes fine).

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • New music/player/metadata/plugin provider — new-provider
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — documentation
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • pytest passes, and tests have been added/updated under tests/ where applicable.
  • For changes to shared models, the companion PR in music-assistant/models is linked.
  • For changes affecting the UI, the companion PR in music-assistant/frontend is linked.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.
  • I have raised a PR against the documentation repository targeting the main or beta branch as appropriate.

@rathlinus rathlinus changed the title YouTube Music: ~1160% faster playback start by getting audio from the player API instead of yt-dlp YouTube Music: ~1000% faster playback start by getting audio from the player API instead of yt-dlp Jun 20, 2026
@rathlinus

rathlinus commented Jun 20, 2026

Copy link
Copy Markdown
Author

Click-to-play benchmark

ytmusic_native vs the stock ytmusic provider tested with 12 tracks, on a Premium account

Both play itag141 258 kbps AAC

Step native stock Improvement
Get a playable URL 142 ms 4228 ms ~30× faster
Click to first audio 300 ms 4400 ms ~15× faster

Native spread: 114–452 ms. Stock spread: 3.8–6.1 s.

native does one API call + an in-process cipher solve (~12 ms) against the
cached base.js. Stock spawns yt-dlp every play and solves the challenge with
deno.

One-off: native spends ~1.8 s at startup (grab base.js once), then every play is
fast. Stock pays the full ~4 s on every single play.

per-track (get-URL ms)

videoId native stock
-LMuWqr4z5I 452 5032
-eBL6fqrq1s 180 6120
-hqCgw59QXc 125 4210
03ZHI-LYncE 116 4176
0EKyo5HWuXY 114 3812
0X2mn7Sk9lQ 116 4403
0YYWgKTgAQw 118 4198
0f-doEMeI3k 159 4572
0ru6miGzTNs 161 3804
0snTYLgg9w0 115 4246
1DrFDVhb9TY 164 3836
1LPNuFkteI8 169 4765

@rathlinus

Copy link
Copy Markdown
Author

Use this tool to extract the data for the native provider: https://github.com/rathlinus/ytm-login-grabber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant