ytmbrainz
A MusicBrainz-compatible metadata server backed by YouTube Music. Point any MusicBrainz /ws/2 client at it and get real track, release, artist, and duration data for the long tail of music that only exists on YouTube.
Source: README on GitHub
A MusicBrainz-compatible metadata server backed by YouTube Music. Point any MusicBrainz
/ws/2client at it and get real track, release, artist, and duration data for the long tail of music that only exists on YouTube.
What is this?
ytmbrainz implements the MusicBrainz /ws/2 web service API
in front of YouTube Music (via youtube.js / InnerTube).
It speaks the same XML (MMD-2.0) and JSON shapes as the real MusicBrainz server, so existing
clients work without modification — you just point them at a different URL.
The motivation: Koito (and similar MusicBrainz-backed clients) fill in covers and metadata from MusicBrainz. If you listen through YouTube Music and you like indie and niche music, a lot of that data simply isn’t in MusicBrainz — missing covers, no artist/track metadata, and scrobble minutes that never get attributed. I hit this after moving from Last.fm to Koito: thousands of scrobbled tracks resolved to nothing. Those tracks are almost always on YouTube Music though, so ytmbrainz bridges that gap: point your client’s MusicBrainz server at it and the metadata shows up.
Features
- Full
/ws/2surface: search, lookup, and browse for recordings, artists, releases, release-groups, and urls - Lucene query syntax — fielded terms, phrases,
AND/OR/NOT, negation, and duration ranges likedur:[200000 TO 400000] - XML (MMD-2.0) and JSON responses,
fmt=orAcceptheader, MusicBrainz-compatible error shapes and status codes - Deterministic UUID v5 MBIDs backed by a persistent SQLite store, so every MBID handed out keeps resolving across restarts
- YouTube URL resolution — paste a
watch?v=,youtu.be, channel, or album link and get the linked entity inc=subqueries (artist discographies, release track lists, and more) with per-entity validation- Cover Art Archive-compatible cover routes (
/release/<mbid>/frontand friends) served straight from YouTube Music’s album art - Built to not get banned: zero-config identity that bootstraps a real visitor data and auto-mints/refreshes PO tokens, browser impersonation (Chrome TLS fingerprint via impit) on every outbound request, plus upstream caching with request coalescing, serialized YouTube rate limiting, retries with exponential backoff, and per-IP HTTP rate limiting
- Ships as a hardened Docker image: compiled bundle plus minimal runtime deps (jsdom, impit’s native binding), non-root user, healthcheck
- 100% coverage enforced — lint, typecheck, and the coverage gate run in CI
Stack
- Bun runtime and test runner (
bun test) — Bun ≥ 1.2 required - TypeScript in strict mode
- Biome for linting and formatting
- youtube.js (InnerTube) as the data source — YouTube Music client only, no main-YouTube endpoints
- bgutils-js for minting Proof of Origin tokens against BotGuard
- impit for browser impersonation — Chrome TLS fingerprint and headers on outbound requests
- jsdom as the DOM shim that runs BotGuard’s interpreter when minting PO tokens
bun:sqlitefor the persistent, deterministic MBID store
# prerequisites: Bun >= 1.2
git clone https://github.com/YasogaN/ytmbrainz.git
cd ytmbrainz
bun install
bun run dev # starts on http://127.0.0.1:3000
Try it:
curl 'http://127.0.0.1:3000/ws/2/recording?query=recording:"Roygbiv" AND artist:"Boards of Canada"&fmt=json'
{
"created": "2026-08-14T00:00:00.000Z",
"count": 1,
"offset": 0,
"recordings": [
{
"id": "9f47e23c-...",
"score": 100,
"title": "Roygbiv",
"length": 148000,
"artist-credit": [
{
"name": "Boards of Canada",
"artist": {
"id": "b1a0f4a5-...",
"name": "Boards of Canada",
"sort-name": "Boards of Canada"
}
}
],
"first-release-date": "1998",
"releases": [{ "id": "c3d09e10-...", "title": "Music Has the Right to Children", "date": "1998" }]
}
]
}
Scripts
| Command | What it does |
|---|---|
bun run dev | Start the server in watch mode |
bun run start | Start the server |
bun run check | Biome lint and format check |
bun run check:fix | Auto-fix lint and format issues |
bun run typecheck | Type-check with tsc --noEmit |
bun test | Run tests |
bun run test:coverage | Run tests with 100% coverage gate |
bun run test:watch | Run tests in watch mode |
bun run test:live | Run live tests against the real YouTube |
bun run gen:potoken | Mint a fresh PO token for YTMB_PO_TOKEN |
bun run preflight | Everything: check + typecheck + coverage |
The coverage gate is enforced in bunfig.toml — every file must hit 100% lines,
functions, statements, and branches (src/index.ts and tests/ are excluded).
Configuration
Configuration is read from the environment:
| Variable | Default | Description |
|---|---|---|
YTMB_HOST | 127.0.0.1 | Bind address |
YTMB_PORT | 3000 | HTTP port |
YTMB_CACHE_TTL | 3600 | Upstream response TTL (seconds) |
YTMB_YT_RATE_LIMIT_MS | 1000 | Min interval between YT calls (incl. paged continuations) |
YTMB_YT_RETRIES | 2 | Retries for transient YT failures |
YTMB_YT_BACKOFF_MS | 250 | Retry backoff base (exponential) |
YTMB_HTTP_RATE_LIMIT | 10 | Per-IP requests/sec (0 disables) |
YTMB_VISITOR_DATA | unset | Optional: pin a visitor data |
YTMB_COOKIE | unset | Optional: YouTube cookies (authenticated) |
YTMB_PO_TOKEN | unset | Optional: pin a static PO token |
YTMB_DB_PATH | ./data/ytmbrainz.db | MBID store (SQLite) |
Bot walls & identity
ytmbrainz works out of the box: on first use it bootstraps a real visitor
data from YouTube and mints Proof of Origin tokens bound to it (via
BgUtils), auto-refreshing them as they
expire so the session never goes stale. Every outbound request — InnerTube
calls, the bootstrap session, and the BotGuard attestation — is sent through
a client that impersonates a real Chrome browser at the TLS fingerprint and
header level (via impit), falling back to
the native fetch if the native binding is unavailable. No YTMB_* identity
configuration is required.
The identity variables are optional overrides for cases where you want to pin a specific identity (for example a logged-in YouTube session):
YTMB_VISITOR_DATA— a persistent visitor data string.YTMB_COOKIE— YouTube cookies, for authenticated requests.YTMB_PO_TOKEN— a static PO token. When set, the server uses it as-is and skips auto-minting.
For power users, bun run gen:potoken mints a fresh PO token bound to a given
visitor data for manual setup:
YTMB_VISITOR_DATA=... bun run gen:potoken # -> put the output in YTMB_PO_TOKEN
API
The following MusicBrainz /ws/2 routes are implemented:
| Entity | Search | Lookup | Browse |
|---|---|---|---|
recording | query | <mbid> | by artist, by release |
artist | query | <mbid> | — |
release | query | <mbid> | by artist, by release-group |
release-group | query | <mbid> | by artist |
url | query | <mbid> or ?resource=<url> | — |
- Formats: XML is the default; add
fmt=jsonor sendAccept: application/json.fmt=takes precedence. - Paging:
limit(default 25, max 100) andoffseton search and browse. inc=: lookups accept subqueries likereleases,recordings,artist-credits,url-rels, and more — validated per entity.- Errors: MusicBrainz-shaped errors with proper status codes (400, 404, 405, 503).
Cover art
Cover Art Archive-compatible routes are served for release and release-group covers, backed by YouTube Music’s album art:
curl -I http://127.0.0.1:3000/release/<mbid>/front # 307 -> YTM album art
curl http://127.0.0.1:3000/release/<mbid> # JSON image index
Front, sized (-250/-500/-1200), and per-image variants are supported under
both /release/<mbid> and /release-group/<mbid>. See docs/caa.md
for the route reference and for how to MITM the real coverartarchive.org into
these routes for clients that hardcode it.
See docs/routes.md for the full route reference with XML and JSON examples, and docs/architecture.md for how it works under the hood.
Not the whole MusicBrainz API. YouTube Music has no labels, works, areas, genres, aliases, tags, or ISRCs, so those endpoints and fields are not (and can’t be) implemented. See docs/compatibility.md for the full list of what is supported, what isn’t, and why.
docker build -t ytmbrainz .
docker run --rm -v ytmbrainz-data:/app/data ytmbrainz
No ports are published by default — reach the service over the container
network, or add -p 3000:3000 (or uncomment ports: in docker-compose.yml)
to expose it locally.
or with compose:
docker compose up -d
The image is built in three stages:
- deps — installs with the frozen lockfile
- build — runs the full preflight gate (lint, typecheck, 100% coverage tests),
then compiles
src/index.tsinto a bundle (keepingjsdomexternal) - runtime — installs the minimal production deps (jsdom and impit’s native
binding, which must be present at runtime), copies the built bundle, runs as
an unprivileged
ytmbrainzuser, with a/healthhealthcheck
Images are published to GHCR (ghcr.io/yasogan/ytmbrainz) on v* tags.
Podman (rootless quadlet)
A ready-to-use rootless quadlet is provided in ytmbrainz.container (requires Podman ≥ 4.4):
mkdir -p ~/.config/containers/systemd
cp ytmbrainz.container ~/.config/containers/systemd/
systemctl --user daemon-reload
systemctl --user enable --now ytmbrainz
Enable automatic image updates:
systemctl --user enable --now podman-auto-update.timer
The service runs as your user, keeps the MBID database in a named volume
(ytmbrainz-data), restarts on failure, and pulls fresh ghcr.io/yasogan/ytmbrainz:latest
images on the update timer.
CI/CD
| Workflow | Trigger | What it does |
|---|---|---|
ci.yml | push/PR to main | lint, typecheck, coverage-gated tests |
live.yml | daily cron + manual dispatch | live tests against the real YouTube API |
release.yml | v* tags + manual dispatch | builds and pushes the image to GHCR and creates a GitHub Release |
Development
- Commits: Conventional Commits are enforced by commitlint.
- Hooks: lefthook installs
automatically on
bun install(LEFTHOOK=0to skip) and runs the same checks as CI before every commit. - Tests: unit tests live next to their source files (
src/**/*.test.ts); live tests that hit the real YouTube API live intests/liveand only run withRUN_LIVE=1.
AI Disclosure
This project was built with substantial AI assistance. DeepSeek V4 Flash (DeepSeek-V4-Flash-0731) and DeepSeek V4 Pro (DeepSeek-V4-Pro-0813) handled most of the planning, coding, documentation, and research. I was in the loop throughout, directing and reviewing the work.
Legal Disclaimer
This project is an independent, unofficial project and is not affiliated with, endorsed by, or associated with Google LLC, YouTube, YouTube Music, MusicBrainz, the MetaBrainz Foundation, the Cover Art Archive, the Internet Archive, or any of their products or services. It is not an official MusicBrainz server, an official YouTube or YouTube Music product, or a Google product.
All product and company names used in this project — including YouTube, YouTube Music, Google, MusicBrainz, and Cover Art Archive — are trademarks or registered trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
Purpose of the Project
This project was created solely for personal use.
Non-Commercial Nature
This project is non-commercial and is not intended for any form of profit generation or business use.
Intellectual Property and Fair Use
We acknowledge and respect the intellectual property rights of Google, YouTube,
MusicBrainz, the MetaBrainz Foundation, and all other third parties. ytmbrainz
implements the public MusicBrainz /ws/2 API contract and reads metadata
exposed by YouTube Music; no proprietary APIs, data, or materials belonging to
these parties are distributed by this project. Any content referenced,
redirected to, or linked from this project remains the property of its
respective owners.
Contact and Legal Concerns
If you have any concerns or questions regarding the legality of this project, or any specific legal queries or issues, please seek professional legal advice.
License
MIT © 2026 Yasoga Nanayakkarawasam