Crate sunk

source ·
Expand description

sunk

sunk provides natural Rust bindings to the Subsonic music server API. Many other popular music servers, such as Libresonic and Airsonic, also use the Subsonic API, so this crate can stretch far beyond just Subsonic.

Basic usage

extern crate sunk;
use sunk::song::Song;
use sunk::{Album, Artist, Client, Streamable};

let site = "http://subsonic.example.com";
let username = "admin";
let password = "hunter2";

let client = Client::new(site, username, password)?;

let random_songs = Song::random(&client, 20)?;
for mut song in random_songs {
    song.set_max_bit_rate(320);
    let bytes = song.stream(&client)?;
    // Use another library to stream the `bytes`!
}

Philosophy

The fundamental principle behind the way sunk works is to be able to pivot on everything. If you have something returned from a query, you should be able to investigate that object more deeply. This is modelled after what you’d typically expect from mobile or web clients.

An example can be seen below:

let client = Client::new(site, username, password)?;

// I want to play some <insert artist here>.
let an_artist = Artist::get(&client, 20)?;
let artist_info = an_artist.info(&client)?;
let artists_albums = an_artist.albums(&client)?;

// I love this album. Let's download it.
let ref fav_album = artists_albums[0];
let album_info_and_similar = fav_album.info(&client)?;
let album_songs = fav_album.songs(&client)?;

use std::fs::File;
use std::io::Write;
for song in &album_songs {
    let bytes = song.download(&client)?;
    let mut file =
        File::create(song.title.clone() + "." + song.encoding())?;
    file.write(&bytes)?;
}

// I want to find stuff like this song.
let ref this_is_good = album_songs[6];
let similar = this_is_good.similar(&client, 10)?;

This has the result of many methods requiring an active connection to a Client to fetch more information.

Debugging

The crate uses log as its debugging backend. If your crate uses log, you’ll see output from sunk at any information level starting at warning (for critical processes) or info (for most other processes).

Development

The crate is still under active development. Methods and paths may change, and many have not been tested due to the requirement of having full access to a Subsonic instance. See the repository for any changes and development status.

Bug reports and broken features are encouraged to be reported! If something does not work as reported, it’s probably broken.

Modules

Methods and containers for searching and search results.

Structs

Basic information about an artist.
Detailed information about an artist.
A client to make requests to a Subsonic instance.
A genre contained on a Subsonic server.
A slice of a media for use in a HLS playlist.
A HLS playlist file.
A wrapper on a Client to control just the jukebox.
A more detailed representation of the jukebox’s status. Includes its current playlist.
A representation of the jukebox’s current status.
A representation of a music folder on a Subsonic server.
Information about currently playing media.
A struct representing a Subsonic user.
A new user to be created.

Enums

The possible errors a Subsonic server may return.
Possible errors that may be returned by a function.
Possible errors when initializing a Client.

Traits

A trait deriving common methods for any form of media.
A trait for forms of streamable media.

Type Definitions

An alias for sunk’s error result type.