Git Product home page Git Product logo

subsonic-java-client's Introduction

Subsonic Java Client

Maven Central Build Airsonic Integration Subsonic Integration codecov

A Java Client for the Subsonic API.

Compatibility

The client is based on the Subsonic API version 1.15.0. The used API version will automatically be adapted to match the server's API version if the server uses an older API version than 1.15.0. In this case only operations supported by the server's API version will work. A minimum server API version of 1.13.0 is still required.

The client is automatically being tested against the latest airsonic and subsonic servers during its build process. It should work with all servers that implement the Subsonic API.

Currently Supported Operations

Here's an overview of which operations this client currently supports. Note that depending on the implementation some servers may not support specific operations even it should be supported by the API version of the server. For example airsonic does not support any chat operations while subsonic does.

API Operation Supported
System ping yes
getLicense yes
Browsing getMusicFolders yes
getIndexes yes
getMusicDirectory yes
getGenres yes
getArtists yes
getArtist yes
getAlbum yes
getSong yes
getVideos no
getVideoInfo no
getArtistInfo no
getArtistInfo2 no
getAlbumInfo no
getAlbumInfo2 no
getSimilarSongs no
getSimilarSongs2 no
getTopSongs no
Album/song lists getAlbumList no
getAlbumList2 no
getRandomSongs no
getSongsByGenre no
getNowPlaying yes
getStarred no
getStarred2 no
Searching search no
search2 yes
search3 yes
Playlists getPlaylists yes
getPlaylist yes
createPlaylist yes
updatePlaylist yes
deletePlaylist yes
Media retrieval stream yes
download yes
hls no
getCaptions no
getCoverArt yes
getLyrics no
getAvatar yes
Media annotation star no
unstar no
setRating no
scrobble yes
Sharing getShares no
createShare no
updateShare no
deleteShare no
Podcasts getPodcasts no
getNewestPodcasts no
refreshPodcasts no
createPodcastChannel no
deletePodcastChannel no
deletePodcastEpisode no
downloadPodcastEpisode no
Jukebox jukeboxControl no
Internet radio getInternetRadioStations no
createInternetRadioStation no
createInternetRadioStation no
updateInternetRadioStation no
deleteInternetRadioStation no
Chat getChatMessages no
addChatMessage no
User management getUser yes
getUsers yes
createUser yes
updateUser yes
deleteUser yes
changePassword yes
Bookmarks getBookmarks no
createBookmark no
deleteBookmark no
getPlayQueue no
savePlayQueue no
Media library scanning getScanStatus yes
startScan yes

Usage

Initialization

SubsonicPreferences preferences = new SubsonicPreferences("http://localhost:13013/airsonic", "username", "password");
preferences.setStreamBitRate(192);
preferences.setClientName("MySubsonicClient");

Subsonic subsonic = new Subsonic(preferences);

Test connection

try {
    if(subsonic.testConnection()){
        log.info("Succesfully connected to server!")
    } else {
        log.error("Failed to connect to server!")
    }   
} catch(SubsonicIncompatibilityException e) {
    log.error("The server is not compatible with the client! Please upgrade you server!")
}

Using the API

Every Subsonic API group has a corresponding method in the Subsonic class. For example to use the search3 operation from the Searching API group you do the following:

SearchResult3 searchResult = subsonic.searching().search3("Caravan Palace",
    SearchParams.create().artistCount(0).albumCount(0).songCount(3));

Some API operations have optional parameters. Their values will, in some cases, be directly passed as arguments but usually the method expects a param class. These param classes always have a static create method and multiple additional methods representing the parameters.

More examples

// Scan library and wait until finished
subsonic.libraryScan().startScan();

while (subsonic.libraryScan().getScanStatus().isScanning()){
    Thread.sleep(1000);
}
// Fetch index and print it
List<Index> indexes = subsonic.browsing().getIndexes();

for (Index index : indexes) {
    System.out.println(index.getName());
    for (Artist artist : index.getArtists()) {
        System.out.println("-- " + artist.getName());
    }
}
// Stream first song from index
String firstArtistDirectoryId = indexes.get(0).getArtists().get(0).getId();

Directory directory = subsonic.browsing().getMusicDirectory(firstArtistDirectoryId);
Child child = directory.getchildren().get(0);

while (child.isDir()){
    directory = subsonic.browsing().getMusicDirectory(child.getId());
    child = directory.getchildren().get(0);
}

InputStream stream = subsonic.media().stream(child.getId());
someAudioPlayer.play(stream);
// Create a new user with stream and download roles
subsonic.users().createUser("testUser", "password", "[email protected]", 
    CreateUserParams.create().roles(UserRole.STREAM,UserRole.DOWNLOAD));

Every other operation supported by this client can be used in a similar way.

subsonic-java-client's People

Contributors

calne-ca avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

subsonic-java-client's Issues

New URLOfStream method (Problems with stream() method)

Problem: Unable to play InputStream of file with API method, problems with UI binding
Solution: (Temp) Write stream to file then play it

Description:
I'm trying to make Linux Client based on this API with JavaFX (it's not published yet)
I have problems with InputStream returned by method:

net.beardbot.subsonic.client.api.media.MediaService.stream(String id)

When I pass it to the https://github.com/goxr3plus/java-stream-player there are problems with properly transcoded (mp3 or wav) stream doesn't support mark/reset (Fixed by creating BufferedInputStream), music plays, however I'm unable to create bindings with slider etc. because It seems that It doesn't offer such features.

I decided to try with something more core like javax.sound.sampled.Clip I got exception: java.lang.IllegalArgumentException: Audio data < 0 when I try to pass there mentioned InputStream

Finally I managed to play file by wring stream to file (javafx.Media doesn't support Streams). But it's not the point to bypass it. Streaming is much more efficient (e.g. memory: especially when we want lossless files) and better for file security.

Java has some core constraints when it comes to media, like javafx.Media (Which only worked for me) doesn't support InpuStream or Codecs representing libraries are badly documented/has their own limits.

Well, actually we do streaming using http(s) and I checked mentioned stream() method. It creates URL (Line 53).

Do you think that creating net.beardbot.subsonic.client.api.media.MediaService.URLOfStream(String id) is good idea? With it we can pass the URL to the chosen Media Library and let it create proper stream with all functionalities like seeking and UI binding methods.

I'm not really experienced so if you find another solution that's probably my lack of knowledge, then please give me a hint. I've spent hours trying to figure out what's going on, reading tons of docs.

Thanks in advance :)

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.