Files
teamspeak-music-bot/src/music/spotify/go-librespot-config.ts
T
saopig1andClaude Opus 4.8 470a62129a feat(spotify): add SpotifyAudioBackend interface + go-librespot config.yml renderer
- backend.ts: type-only SpotifyAudioBackend contract + track/metadata DTOs
- go-librespot-config.ts: renderConfigYml() hand-built config (pipe/s16le,
  server enabled, interactive OAuth), no yaml dependency
- tests assert exact keys/values and round-trip via a tiny structural parser

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 20:40:15 +08:00

43 lines
1.3 KiB
TypeScript

// src/music/spotify/go-librespot-config.ts
// Hand-built go-librespot config.yml. Keys/values verified against
// devgianlu/go-librespot cmd/daemon/cli_config.go koanf tags. No yaml
// dependency is used; the file is a small, fixed-shape document.
export interface GoLibrespotConfigOptions {
deviceName: string;
bitrate: number;
fifoPath: string;
apiAddress: string;
apiPort: number;
callbackPort: number;
}
/**
* Render a headless go-librespot config.yml:
* - pipe audio backend writing raw 44.1kHz/s16le stereo PCM to a FIFO,
* - HTTP+WebSocket control server enabled (port has NO built-in default,
* so it is always written explicitly),
* - interactive OAuth credentials (persisted automatically to
* <config_dir>/credentials.json after first login).
*/
export function renderConfigYml(o: GoLibrespotConfigOptions): string {
return (
[
`device_name: ${JSON.stringify(o.deviceName)}`,
`device_type: computer`,
`bitrate: ${o.bitrate}`,
`audio_backend: pipe`,
`audio_output_pipe: ${o.fifoPath}`,
`audio_output_pipe_format: s16le`,
`server:`,
` enabled: true`,
` address: ${o.apiAddress}`,
` port: ${o.apiPort}`,
`credentials:`,
` type: interactive`,
` interactive:`,
` callback_port: ${o.callbackPort}`,
].join("\n") + "\n"
);
}