Subsonic-API

A lightweight Subsonic/Opensubsonic Client written in TypeScript. Supports Node, Deno, Bun, and modern Browsers.
Features
- Supports all Subsonic API methods up to version 1.16.1 / Subsonic 6.1.4.
- Supports most of OpenSubsonic's new API methods.
- Supports both GET and POST requests.
Installation
$ npm install subsonic-api
$ bun add subsonic-api
<script type="module">
import { SubsonicAPI } from "https://esm.sh/subsonic-api";
</script>
Example Usage
import { SubsonicAPI } from "subsonic-api";
const api = new SubsonicAPI({
url: "https://demo.navidrome.org",
auth: {
username: "demo",
password: "demo",
},
});
const { randomSongs } = await api.getRandomSongs();
console.log(randomSongs);
API
subsonic-api
supports all of the Subsonic API methods as documented here, up to API version 1.16.1 / Subsonic 6.1.4. Additionally, most of OpenSubsonic's new API methods are also supported.
All methods return a promise that resolves to the JSON response from the server.
Additionally, the following methods are available:
new SubsonicAPI
new SubsonicAPI(config: SubsonicConfig)
Creates a new SubsonicAPI instance.
interface SubsonicConfig {
url: string;
auth:
| {
username: string;
password: string;
}
| {
apiKey: string;
};
salt?: string;
reuseSalt?: boolean;
post?: boolean;
fetch?: Fetch;
crypto?: WebCrypto;
}
navidromeSession
subsonicSession(): Promise<SessionInfo>
Creates a new Navidrome session
interface SessionInfo {
id: string;
isAdmin: boolean;
name: string;
subsonicSalt: string;
subsonicToken: string;
token: string;
username: string;
}
baseURL
baseURL(): string
Returns the base URL of the server. Useful for interacting with other APIs like Navidrome's.
custom
custom(method: string, params: Params): Promise<Response>
Allows you to make a custom request to the server.
customJSON
customJSON<T>(method: string, params: Params): Promise<T>
Allows you to make a custom request to the server and parse the response as JSON.