1
0

feat: subsonic getAlbum/getRecentAlbums and stream url builder

This commit is contained in:
2026-09-03 20:53:49 +02:00
parent 3bdbd8315c
commit 9d1291b58f
2 changed files with 106 additions and 0 deletions

View File

@@ -75,6 +75,40 @@ export class SubsonicClient {
await this.request('ping')
}
/** Raw endpoint URL with auth params — for streaming passthrough. */
url(endpoint: string, params: Record<string, string> = {}): string {
const u = new URL(`${this.base}/rest/${endpoint}`)
const search = { ...this.authParams(), ...params }
for (const [k, v] of Object.entries(search)) u.searchParams.set(k, v)
return u.toString()
}
async getAlbum(albumId: string): Promise<{ id: string; title: string; artist: string; tracks: { id: string; title: string; duration: number | null; track: number | null }[] }> {
const envelope = await this.request('getAlbum', { id: albumId })
const album = envelope.album ?? {}
const songs: any[] = album.song ?? []
const tracks = songs
.map((s) => ({
id: String(s.id),
title: String(s.title ?? ''),
duration: Number.isFinite(Number(s.duration)) ? Number(s.duration) : null,
track: Number.isInteger(Number(s.track)) ? Number(s.track) : null,
}))
.sort((a, b) => (a.track ?? 9999) - (b.track ?? 9999))
return { id: String(album.id ?? albumId), title: album.name ?? album.title ?? '', artist: album.artist ?? '', tracks }
}
async getRecentAlbums(size = 500): Promise<{ id: string; title: string; artist: string; playedAt: string | null }[]> {
const envelope = await this.request('getAlbumList2', { type: 'recent', size: String(size) })
const list: any[] = envelope.albumList2?.album ?? []
return list.map((a) => ({
id: String(a.id),
title: a.name ?? a.title ?? '',
artist: a.artist ?? '',
playedAt: typeof a.played === 'string' ? a.played : typeof a.playedAt === 'string' ? a.playedAt : null,
}))
}
async getAllAlbums(
onProgress?: (albums: SubsonicAlbum[], done: number) => void
): Promise<SubsonicAlbum[]> {