This document describes the complete API available to youtube-music-cli plugins.
A plugin consists of:
{
"id": "my-plugin",
"name": "My Plugin",
"version": "1.0.0",
"description": "A description of what this plugin does",
"author": "Your Name",
"license": "MIT",
"main": "index.ts",
"permissions": ["player", "ui", "filesystem", "network", "config"],
"hooks": ["play", "pause", "track-change", "view-change"],
"ui": {
"views": ["my-view"],
"shortcuts": ["ctrl+shift+m"]
}
}
When your plugin's init() function is called, it receives a PluginContext object with the following APIs:
context.player.play(track: Track): Promise
context.player.pause(): void
context.player.resume(): void
context.player.stop(): void
context.player.next(): void
context.player.previous(): void
context.player.seek(position: number): void
context.player.setVolume(volume: number): void
context.player.getVolume(): number
context.player.getCurrentTrack(): Track | null
context.player.getQueue(): Track[]
context.player.addToQueue(track: Track): void
context.player.removeFromQueue(index: number): void
context.player.clearQueue(): void
context.player.shuffle(enabled: boolean): void
context.player.setRepeat(mode: 'off' | 'all' | 'one'): void
Required Permission: player
context.navigation.navigate(view: string): void
context.navigation.goBack(): void
context.navigation.getCurrentView(): string
context.navigation.registerView(viewId: string, component: ReactElement): void
context.navigation.unregisterView(viewId: string): void
Required Permission: ui
context.config.get(key: string, defaultValue?: T): T
context.config.set(key: string, value: unknown): void
context.config.delete(key: string): void
context.config.getAll(): Record
Required Permission: config
context.logger.debug(message: string, ...args: unknown[]): void
context.logger.info(message: string, ...args: unknown[]): void
context.logger.warn(message: string, ...args: unknown[]): void
context.logger.error(message: string, ...args: unknown[]): void
No permission required - Always available
context.filesystem.readFile(path: string): Promise
context.filesystem.writeFile(path: string, data: string): Promise
context.filesystem.deleteFile(path: string): Promise
context.filesystem.exists(path: string): Promise
context.filesystem.listFiles(path?: string): Promise
context.filesystem.getDataDir(): string
Required Permission: filesystem
Note: All paths are relative to the plugin's data directory.
context.audio.transformStreamUrl(url: string, track: Track): Promise | string | null
context.audio.onStreamRequest(handler: (url, track) => Promise | string | null): void
Required Permission: player
// Subscribe to events
context.on(eventType: T['type'], handler: (event: T) => void): void
// Unsubscribe from events
context.off(eventType: T['type'], handler: (event: T) => void): void
// Emit events (for plugin-to-plugin communication)
context.emit(event: T): void
pause - Fired when playback is pausedresume - Fired when playback resumesprevious - Fired when going to previous trackcontext.hasPermission(permission: PluginPermission): boolean
context.requestPermission(permission: PluginPermission): Promise
context.registerShortcut(keys: string[], handler: () => void): void
context.unregisterShortcut(keys: string[]): void
Required Permission: ui
| Permission | Description |
| ------------ | ------------------------------------------------------- |
| player | Control playback, access queue, intercept audio streams |
| ui | Register views, add keyboard shortcuts |
filesystem | Read/write files in plugin data directory |
|---|
| network | Make network requests |
| config | Read/write application configuration |
const plugin: Plugin = {
manifest,
async init(context) {
/* Setup */
},
async enable(context) {
/* Start functionality */
},
async disable(context) {
/* Stop functionality */
},
async destroy(context) {
/* Final cleanup */
},
};