0.6.0 • Published 4 years ago

subsonicjs v0.6.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

subsonicjs

NOTE: Alpha release; Will have basic functionality working soon.

npm version

An abstraction of the subsonic API as a node package. This package attempts to line up API methods and their parameters as close to 1:1 with the original documentation Official Subsonic API Docs.

Changelog

Changelog is available here: Changelog

Installation

npm install --save subsonicjs

Usage

The package needs to be configured with your subsonic username, a password token, and the salt used to generate the password token. To create a password token perform an md5 encryption of the password and salt. (e.g. salt = 'secret'; token = md5('password'+'secret');)

var subsonic = require("subsonicjs")(username, token, salt, url);

var pingServer = await subsonic.system.ping();

Initialize with config object

The package can also be configured with several options. The only required option is host all other options are optional.

var subsonic = require("subsonicjs")(username, token, salt, {
    protocol: 'http',
    host: 'www.subsonic.org',
    port: 80,
    timeout: 30,
    client: 'subsonicjs',
    version: '1.16.1'
});
OptionDefaultDescription
protocolhttpProtocol to connect to server. (e.g. http,https, etc )
hostnullRequired. Host subsonic server which requests are made to.
port80Port on subsonic server which requests are made to.
timeout30Request timeout in seconds.
clientsubsonicjsA unique string identifying the client application.
version1.16.1Subsonic server API version to be used.

Using Promises

Nearly every method returns a chainable promise which can be used.

subsonic.browsing
    .getIndexes()
    .then((indexes) => {
        let firstIndexedArtist = indexes.index[0].artist[0];
        return subsonic.browsing().getArtist(firstIndexedArtist.id);
    })
    .then((artist) => {
        //First artist details according to index order
    }).catch((err) => {
        // Handle error
    })

Promise Exceptions

A select few methods don't return promises as the end data object is not JSON but rather Binary. In these instances, the method will return a uri for the end client to consume.

subsonic.media.stream(id); //Will return stream uri for media player to consume
subsonic.media.getCoverArt(id); //Will return cover art uri for image components to consume

Optional Parameters

If a call has optional parameters, you can add them to the end of the method as an object.

subsonic.playlists
    .updatePlaylist(playlistId, {
        name: 'My Playlist',
        comment: 'My playlist description'
    })
    .then((response) => {
        //Handle response
    })

API Layout

The package has broken api calls out into different buckets for organization purposes. The following table contains the buckets and methods. Access methods through the following: subsonic.{bucket}.{method}(). Largely follows organization from official API docs, but some methods were moved to other areas.

BucketMethods
bookmarksgetBookmarks, createBookmark, deleteBookmark
browsinggetMusicFolders, getIndexes, getMusicDirectory, getGenres, getArtists, getArtist, getAlbum, getSong, getVideos, getVideoInfo, getArtistInfo, getArtistInfo2, getAlbumInfo, getAlbumInfo2, getSimilarSongs, getSimilarSongs2, getTopSongs, getAlbumList, getAlbumList2, getRandomSongs, getSongsByGenre, getNowPlaying, getStarred
chatgetChatMessages, addChatMessage
internetRadiogetInternetRadioStations, createInternetRadioStation, updateInternetRadioStation, deleteInternetRadioStation
jukeboxControljukeboxControl
mediastream, download, getCaptions, getCoverArt, getLyrics, getAvatar, star, unstar, setRating, scrobble
playlistsgetPlaylists, getPlaylist, createPlaylist, updatePlaylist, deletePlaylist
playQueuegetPlayQueue, savePlayQueue
podcastsgetPodcasts, getNewestPodcasts, refreshPodcasts, createPodcastChannel, deletePodcastChannel, deletePodcastEpisode, downloadPodcastEpisode
searchingsearch2, search3
sharinggetShares, createShare, updateShare, deleteShare
systemping, getLicense, getScanStatus, startScan
0.6.0

4 years ago

0.5.0

4 years ago

1.0.0

4 years ago