GithubHelp home page GithubHelp logo

explodingcamera / subsonic-api Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 1.0 636 KB

typescript/javascript library for interacting with subsonic-compatible apis

Home Page: https://www.npmjs.com/package/subsonic-api

License: MIT License

TypeScript 100.00%
navidrome subsonic airsonic

subsonic-api's Introduction

Subsonic-API

A simple API library for interacting with Subsonic-compatible servers (Up to API version 1.16.1) written in TypeScript. Supports Node.js >= 18, bun >= 1 and modern Browsers. No dependencies and less than 4kb minified and gzipped.

Installation

$ npm install subsonic-api

Example Usage

You can also try out the example on CodeSandbox here.

import { SubsonicAPI } from "subsonic-api";

const api = new SubsonicAPI({
  url: "https://demo.navidrome.org",
  type: "navidrome", // or "generic" or "subsonic"
});

await api.login({
  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. All methods return a promise that resolves to the JSON response from the server.

Additionally, the following methods are available:

login

login(options: LoginOptions): Promise<void>

Logs in to the server and stores the password for future requests.

interface LoginOptions {
  username: string;
  password: string;
}

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.

subsonic-api's People

Contributors

explodingcamera avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

geoxor

subsonic-api's Issues

Is there a way to get all albums from an artistId?

Hello ✌️

I'm currently using Navidrome.

Navidrome seems to have a private API with different endpoints and parameters like we see here:
CleanShot 2023-09-08 at 13 52 56

Is there a way to get all albums from an artistId like Navidrome does? I can only see the getAlbumList method which only has the id (of the album) parameter. This returns a list of albums that all have the artistId. I could get the albums from an artist by using both the getArtists and getAlbumList but it's not practical.

Is there a cleaner/simpler way of doing this?

Thanks ;)

Login method errors with "Unknown encoding: base64url"

The environment is in Electron v24.1.3, Node v19.1.0 (trying to implement in https://github.com/Geoxor/amethyst)

Sample code:

import { SubsonicAPI } from "subsonic-api";

const api = new SubsonicAPI({
  url: "https://demo.navidrome.org",
  type: "navidrome", // or "generic" or "subsonic"
});

api.login({
  username: "demo",
  password: "demo",
}).then(() => {
  api.getTopSongs({count: 50}).then(songs => console.log(songs));
  console.log("logged in");
}).catch(err => {
  console.log("subsonic error:", err);
});

Error in console:

subsonic error: TypeError: Unknown encoding: base64url
    at Uint8Array.slowToString (index.js:544:32)
    at Uint8Array.toString (index.js:606:23)
    at M (index.js:1:9081)
    at n.E_fn (index.js:1:10196)
    at n.G_fn (index.js:1:10257)
    at n.C_fn (index.js:1:11207)
    at n.R_fn (index.js:1:10408)
    at n.ping (index.js:1:11393)
    at n.login (index.js:1:9663)

Scrobble() method doesn't take into account submission param

I'm creating a player component that gets the current song that is playing.

From Subsonic API I see I need to call the following methods in this exact order:

  1. stream(songId)
  2. scrobble(songId)
  3. getNowPlaying

The scrobble method needs to have the submission param set to false to add the a song in the playing queue.

Issue: the scrobble method doesn't seem to take into account the submission param. The id and time params work well though.

When directly using the Subsonic API in Postman with the same params everything works well.

My code:
CleanShot 2023-09-13 at 12 47 14

The request in the browser doesn't send the submission param:
CleanShot 2023-09-13 at 12 48 21

Did I miss something?

Thanks in advance ;)

EDIT
After setting the submission value as a string it works. It may be coming from this line in your package :)
CleanShot 2023-09-13 at 18 45 19
CleanShot 2023-09-13 at 18 42 38

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.