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
sourceimpl Client
impl Client
sourcepub fn new(url: &str, user: &str, password: &str) -> Result<Client>
pub fn new(url: &str, user: &str, password: &str) -> Result<Client>
Constructs a client to interact with a Subsonic instance.
sourcepub fn with_target(self, ver: Version) -> Client
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.
sourcepub fn check_license(&self) -> Result<License>
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.
sourcepub fn scan_library(&self) -> Result<()>
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.
sourcepub fn scan_status(&self) -> Result<(bool, u64)>
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.
sourcepub fn music_folders(&self) -> Result<Vec<MusicFolder>>
pub fn music_folders(&self) -> Result<Vec<MusicFolder>>
Returns all configured top-level music folders.
sourcepub fn now_playing(&self) -> Result<Vec<NowPlaying>>
pub fn now_playing(&self) -> Result<Vec<NowPlaying>>
Returns all currently playing media on the server.
sourcepub fn lyrics<'a, S>(&self, artist: S, title: S) -> Result<Option<Lyrics>>where
S: Into<Option<&'a str>>,
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.
sourcepub fn search(
&self,
query: &str,
artist_page: SearchPage,
album_page: SearchPage,
song_page: SearchPage
) -> Result<SearchResult>
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());