Introduction¶
When integrating music capabilities into agents in the DSH environment, it is usually necessary to handle search, playback, and relay logic separately for each platform. The common approach involves duplicating API implementations across multiple scripts and manually maintaining the playback queue and Discord integration. dsh-jukebox consolidates all of this into a unified jukebox plugin, allowing agents to request songs using natural language and relay the results to a Discord voice channel or the official player.
Plugin Overview¶
dsh-jukebox is a DSH plugin that provides unified jukebox capabilities. It supports multiple sources including local music libraries, YouTube Music, bilibili, Spotify, KKBOX, and Apple Music. It can play within DSH, serve as an audio source for Discord, and also provide official player control and real-time relay capabilities. Developed by puffdog-git under the MIT license.
Supported Sources and Capabilities¶
The plugin lists available operations per source:
| Source | Search | Playlist/Album | DSH Playback or Discord Relay | Open in Official Player |
|---|---|---|---|---|
| Local music library | Yes | — | Direct file playback | — |
| YT Music | Yes | Public playlist links | Direct playback via yt-dlp | Yes |
| bilibili | Yes (video search) | Audio section playlists, collections, series, favorites links | Direct playback of video audio and audio section tracks via yt-dlp | Yes (opens in browser) |
| Spotify | Yes (no login required: reads its own search when desktop app is open; uses official API after login) | Song/album/playlist links (no login required); your own playlists require login | Real-time relay from official player, or equivalent playback | Yes, can play by song name (desktop app just needs to be open; free tier works) |
| KKBOX | Yes (works without API key, one song at a time) | Public shared playlists, album links (requires API key) | Real-time relay from official player, or equivalent playback | Yes, can play by song name |
| Apple Music | Yes (no API key required) | Album links; playlist links require a developer token | Real-time relay from official player, or equivalent playback | Yes, can play by song name (subscription required) |
Equivalent playback: Spotify, KKBOX, and Apple Music tracks are DRM-protected, and the plugin does not obtain or decrypt them. It only uses the song metadata (title, artist, duration) from these services, then finds and plays the same song from your local music library or YouTube. The interface displays which version is actually playing and the similarity score; if no sufficiently similar version is found, it will explicitly state that it cannot be found rather than playing a random track.
Discord Integration and AI Tools¶
Once dsh-jukebox is enabled, it automatically registers the enabled sources as Discord music sources: plugin:jukebox-local, plugin:jukebox-ytmusic, plugin:jukebox-bilibili, plugin:jukebox-spotify, plugin:jukebox-kkbox, plugin:jukebox-apple. Who can request songs and which voice channels they can access is still determined by the Discord plugin’s own configuration. Discord’s limits are: each song must load within 120 seconds and be no larger than 64 MiB.
The plugin provides AI tools in two categories:
- Read-only tools: jukebox_search (search for songs), jukebox_read_link (read the song list from a link).
- Player control tools (must be enabled in settings): jukebox_player_status (check player status), jukebox_player_play (make the player play), jukebox_player_control (pause/resume/next/previous).
AI cannot log in, modify settings, or access API keys.
Installation and Setup¶
Run the following command in the terminal to install:
dsh plugin --profile web add dsh-jukebox
You can also install directly from GitHub:
dsh plugin --profile web add github:puffdog-git/dsh-jukebox
After installation, enable the “Jukebox” feature in the DSH settings page to start using it.
System Requirements and Dependencies¶
- yt-dlp: Used for YT Music, bilibili, and equivalent playback. The plugin does not bundle this tool and will search in the following order: path specified in settings →
~/.dsh/bin/yt-dlp→ system PATH. If you have the “Discord” plugin installed, its yt-dlp will be found automatically. - FFmpeg (optional): Only needed for transcoding when local music files exceed 64 MiB and need to be sent to Discord.
- Node.js: Requires
>=22.15.
Official Player Control (Windows Only)¶
In the “Official Player” tab, you can view the status of each player and perform actions such as pause, resume, next, and previous. Spotify and KKBOX can be played by song name directly.
| Player | Play by Song Name | Pause/Resume/Next/Previous |
|---|---|---|
| Spotify | If Spotify is running on this computer: reads its own search results to find the song and uses its own playback link (tested and works on the free tier without login, runs in background). If not running: uses official API to remotely control another device (requires login and Premium) | System media controls; uses official API when app is not running |
| KKBOX | Uses its own playback link | System media controls; uses media keys if not yet playing |
| Apple Music | Automates its window (search → that song → menu “Play”), takes about 5–8 seconds; requires a subscription (tested and works) | System media controls |
Media keys work like physical keyboard shortcuts — the system determines which player receives them. If multiple players are open simultaneously, control may go to the wrong one. When asking a player to play a song, its window may come to the foreground; the jukebox records your previously active window and restores focus after completing the action (there may be a brief flicker in between).
Live Relay (Windows Only)¶
The plugin provides the ability to relay the audio from the official player in real time to a Discord voice channel (Windows only, disabled by default). When enabled, the jukebox will relay whatever Spotify, KKBOX, or Apple Music is currently playing directly to a Discord voice channel in real time.
- Only captures the audio from those specific player processes (using Windows built-in per-process audio capture). It does not capture the entire system audio or the microphone. This is not decryption — it captures the audio already output by the player.
- Can make the player nearly inaudible locally during relay: no virtual audio device needed; it temporarily sets the player’s volume in the mixer to one-thousandth and restores it afterwards.
- It is real-time: the song plays for as long as it is, and only one voice channel can be relayed to at a time; your computer must have the player running.
- The capture tool is a small C# program (source at
lib/capture/ProcessLoopback.cs), compiled to the folder’sbin/using the Windows built-in compiler on first use. - The terms of service for all these services prohibit rebroadcasting streaming content to others. The risk is borne by the account owner. It is recommended to use this only in your own private small group.
Playback Priority Order¶
When someone requests a song from a specific platform, the jukebox searches for available methods in your configured order: play via official player and relay in real time (Spotify, KKBOX, Apple Music) → platform’s own downloadable audio → find the same song on YouTube → find the same song in the local music library. You can reorder or disable some of these options.
Data and Settings¶
“Settings → Jukebox” has four tabs:
- Playback: Source selection, search, link pasting, playback queue.
- Music Library: Add music folders (full path) → save → scan. The plugin only reads your files; it does not modify them.
- Source Accounts:
- Spotify: Create an app at developer.spotify.com, add the Redirect URI shown on the page, paste the Client ID, then click “Log in to Spotify”. No Client Secret required.
- KKBOX: Create an app at developer.kkbox.com and fill in the Client ID and Client Secret.
- Apple Music: Search requires no configuration. Reading playlist links requires Team ID, Key ID, and the .p8 private key.
- Discord and Settings: Whether to register with Discord, equivalent playback order, region, cache size, etc.
API keys and login tokens are stored encrypted with DPAPI on Windows; on other systems they remain in memory only. No API ever returns the content of a key.
Data Location¶
<DSH_HOME or ~/.dsh>/data/dsh-jukebox: stores settings, music library index, equivalent playback results, and YouTube audio cache (size-limited; the least recently played files are deleted when the limit is exceeded).
Known Limitations¶
- Equivalent playback may match a different version (e.g., a re-recording).
- Videos and live streams longer than 30 minutes on YouTube and bilibili will not play.
- bilibili: content requiring login or a premium membership cannot be played; multi-part videos only play the first part; the audio section has no working search (the official API always returns empty results), so search looks for videos. A playlist can read at most 30 items at a time. When queries are too frequent, bilibili temporarily blocks requests, at which point the jukebox pauses querying for 5 minutes. Equivalent playback only searches the local music library and YouTube, not bilibili.
- Spotify’s developer apps currently require the owner to have a Premium account; using the official API to remotely control another device also requires Premium (playing via this computer’s Spotify does not).
- KKBOX’s open API cannot access personal favorites.
Use Cases and Notes¶
Suitable for scenarios where you need unified management of multi-platform music sources, want to provide music capabilities to agents in DSH, and wish to integrate with Discord voice channels or official players. Before use, please review the plugin source code and license to ensure compliance with your use case and security requirements.
Summary¶
dsh-jukebox consolidates search and playback capabilities for local music libraries, YouTube Music, bilibili, Spotify, KKBOX, and Apple Music into a single DSH plugin. It can play within DSH, serve as a Discord audio source, control official players, and provide real-time relay. Through a unified interface and AI tools, it makes it easier to give agents music capabilities.
- Directory: https://www.skillhub.cn/plugins/puffdog-git/dsh-jukebox
- GitHub: https://github.com/puffdog-git/dsh-jukebox