Lavalink
The bot never talks to YouTube directly. From a datacenter IP, yt-dlp and friends hit a "sign in to confirm you're not a bot" wall; with a cookie session they get SABR-flagged streams (storyboard images only, no audio). A local Lavalink 4.2.2 server with the youtube-source plugin does all fetching instead:
- The bot resolves searches, URLs, and playlists through Lavalink's REST API (
GET /v4/loadtracks). - Audio itself is streamed from the plugin's endpoint,
GET /youtube/stream/<videoId>, and piped into ffmpeg by the bot.
Lavalink listens on 127.0.0.1:2333 only. Template and notes live in deploy/lavalink/ in the repo. The template also disables Lavalink's own http and local sources (lavalink.server.sources): with the http source on, anything that can reach Lavalink could make it fetch arbitrary URLs through the host's network, and the local source would play files off the host's disk. The bot uses neither: provider tracks come from the youtube plugin, and direct URLs go through the framework's own fetcher (see "Which path guards what" in the plugin guide).
Pieces
Lavalink.jar
Release 4.2.2 from the Lavalink GitHub releases. deploy.sh downloads it automatically if missing. Needs Java 17+.
The youtube-source plugin (build from source)
The plugin jar must be built from commit e41dd95f8bd134b51e75080fb28cc805fecb431a. That commit contains the PlayStation 4 user-agent fix for the TV client ("Use a PlayStation 4 User-Agent for the TV client", PR #233), the fix that makes TV-client playback work from datacenter IPs, and it is in no released version.
git clone https://github.com/lavalink-devs/youtube-source
cd youtube-source
git checkout e41dd95f8bd134b51e75080fb28cc805fecb431a
./gradlew :plugin:jar
# copy the built jar into <lavalink-dir>/plugins/The built-in YouTube source stays disabled in application.yml (sources.youtube: false), the plugin replaces it.
application.yml
Copy deploy/lavalink/application.yml.template to application.yml next to the jar and set:
lavalink.server.password, the server password. Also save it toPASSWORD.txt(mode600) in the same folder, and pointLAVALINK_PASSWORD_FILEin the bot's.envat that file (there is no default path); the bot reads it from there whenLAVALINK_PASSWORDis not set.plugins.youtube.oauth.refreshToken, after the device-code step below.- The client ladder is already set in the template:
MUSIC, TV, TVHTML5_SIMPLY, WEB, WEBEMBEDDED, MWEB, ANDROID_VR. Only TV supports OAuth, which is the path that matters.
Verify the server is up:
curl -H "Authorization: <password>" http://127.0.0.1:2333/v4/infoYouTube OAuth device-code step (one time, manual)
The TV client needs an OAuth refresh token from a burner Google account, never your main; the plugin's own log warns that Google may terminate accounts used this way.
- Start Lavalink once with
oauth.enabled: trueand norefreshToken. - The log prints a device code and
https://www.google.com/device. - Open that URL signed in as the burner account and approve the code.
- The log prints "Token retrieved successfully" and the refresh token.
- Paste it into
application.ymlasoauth.refreshTokenand restart Lavalink. - Verify: the log shows "YouTube access token refreshed successfully".
With OAuth, the TV client receives normal direct formats, no PO token, no cookies, and the SABR forcing that attaches to browser-cookie sessions does not apply.
Cipher
Signature deciphering uses the public demo cipher server (https://cipher.kikkia.dev) by default, via the template's remoteCipher block. It is a shared demo, fine for light use. For heavy reliance, self-host yt-cipher and point remoteCipher.url at your instance.
Running it
Under systemd, the lavalink.service unit runs java -jar Lavalink.jar from the Lavalink directory and logs to lavalink.log there. The manual equivalent is deploy/lavalink/start-lavalink.sh. See Deployment.