Struct Client

Source
pub struct Client {
    pub ver: Version,
    pub target_ver: Version,
    /* private fields */
}
Expand description

A client to make requests to a Subsonic instance.

The Client holds an internal connection pool and stores authentication details. It is highly recommended to re-use a Client where possible rather than creating a new one each time it is required.

§Examples

Basic usage:

use sunk::Client;

let client = Client::new(site, user, password)?;
client.ping()?;

§Notes

Generally, any method that requires a response from a Subsonic server will require a Client . Any method that issues a request will have the possiblity to return an error. A request will result in an error if any of the following occurs:

  • the Client is built with an unrecognised URL
  • connecting to the Subsonic server fails
  • the Subsonic server returns an API error

Fields§

§ver: Version

Version that the Client supports.

§target_ver: Version

Version that the Client is targeting; currently only has an effect on the authentication method.

Implementations§

Source§

impl Client

Source

pub fn new(url: &str, user: &str, password: &str) -> Result<Client>

Constructs a client to interact with a Subsonic instance.

Source

pub fn with_target(self, ver: Version) -> Client

Adjusts the client to target a specific version.

By default, the client will target version 1.14.0, as built by sunk. However, this means that any servers that don’t implement advanced features that sunk does automatically, such as token-based authentication, will be incompatible. The target version allows setting an override on these features by making the client limit itself to features that the target will support.

Note that (currently) the client does not provide any sanity-checking on which methods are called; attempting to access an endpoint not supported by the server will fail after the call, not before.

Source

pub fn hls_bytes(&self, hls: &Hls) -> Result<Vec<u8>>

Returns the raw bytes of a HLS slice.

Source

pub fn ping(&self) -> Result<()>

Tests a connection with the server.

Source

pub fn check_license(&self) -> Result<License>

Get details about the software license. Note that access to the REST API requires that the server has a valid license (after a 30-day trial period). To get a license key you must upgrade to Subsonic Premium.

Forks of Subsonic (Libresonic, Airsonic, etc.) do not require licenses; this method will always return a valid license and trial when attempting to connect to these services.

Source

pub fn scan_library(&self) -> Result<()>

Initiates a rescan of the media libraries.

§Note

This method was introduced in version 1.15.0. It will not be supported on servers with earlier versions of the Subsonic API.

Source

pub fn scan_status(&self) -> Result<(bool, u64)>

Gets the status of a scan. Returns the current status for media library scanning.

§Note

This method was introduced in version 1.15.0. It will not be supported on servers with earlier versions of the Subsonic API.

Source

pub fn music_folders(&self) -> Result<Vec<MusicFolder>>

Returns all configured top-level music folders.

Source

pub fn genres(&self) -> Result<Vec<Genre>>

Returns all genres.

Source

pub fn now_playing(&self) -> Result<Vec<NowPlaying>>

Returns all currently playing media on the server.

Source

pub fn lyrics<'a, S>(&self, artist: S, title: S) -> Result<Option<Lyrics>>
where S: Into<Option<&'a str>>,

Searches for lyrics matching the artist and title. Returns None if no lyrics are found.

Source

pub fn search( &self, query: &str, artist_page: SearchPage, album_page: SearchPage, song_page: SearchPage, ) -> Result<SearchResult>

Returns albums, artists and songs matching the given search criteria. Supports paging through the result. See the search module for documentation.

§Examples

Basic usage:

use sunk::search::{self, SearchPage};
use sunk::Client;

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

let search_size = SearchPage::new();
let ignore = search::NONE;

let result = client.search("smile", ignore, ignore, search_size)?;

assert!(result.artists.is_empty());
assert!(result.albums.is_empty());
assert!(!result.songs.is_empty());
Source

pub fn starred<U>(&self, folder_id: U) -> Result<SearchResult>
where U: Into<Option<usize>>,

Returns a list of all starred artists, albums, and songs.

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Err = <U as TryFrom<T>>::Err

Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Err>

Source§

impl<T> ErasedDestructor for T
where T: 'static,