pub struct SubsonicClient { /* private fields */ }Expand description
Subsonic/Navidrome API client.
Holds two HTTP clients with different timeout semantics: http bounds a
whole JSON request, which is right for small API responses read in one go;
downloader bounds only connect and per-read stalls, so a large track on a
slow link is never cut off for taking too long overall.
Implementations§
Source§impl SubsonicClient
impl SubsonicClient
pub fn new(base_url: &str, username: &str, password: &str) -> Self
pub fn from_auth(auth: SubsonicAuth) -> Self
Sourcepub fn get_cover_art(
&self,
id: &str,
size: Option<u32>,
) -> Result<Vec<u8>, SubsonicError>
pub fn get_cover_art( &self, id: &str, size: Option<u32>, ) -> Result<Vec<u8>, SubsonicError>
Fetch cover art bytes for a song or album ID.
Returns the raw image rather than a parsed response — getCoverArt
answers with image data, not JSON, so it can’t go through get().
size requests a square thumbnail; omit it for the original.
Sourcepub fn ping(&self) -> Result<(), SubsonicError>
pub fn ping(&self) -> Result<(), SubsonicError>
Ping the server — verify connection and credentials.
Sourcepub fn server_type(&self) -> Result<Option<String>, SubsonicError>
pub fn server_type(&self) -> Result<Option<String>, SubsonicError>
Which server this is, by its OpenSubsonic type. One round trip.
Sourcepub fn profile(&self) -> Result<ServerProfile, SubsonicError>
pub fn profile(&self) -> Result<ServerProfile, SubsonicError>
What this server says it is and which OpenSubsonic extensions it
offers: ping, then getOpenSubsonicExtensions when it speaks
OpenSubsonic. A server that does not has no extensions to list.
Sourcepub fn get_artists(&self) -> Result<Vec<SubsonicArtist>, SubsonicError>
pub fn get_artists(&self) -> Result<Vec<SubsonicArtist>, SubsonicError>
Get all artists (indexed).
Sourcepub fn get_album(&self, id: &str) -> Result<SubsonicAlbumFull, SubsonicError>
pub fn get_album(&self, id: &str) -> Result<SubsonicAlbumFull, SubsonicError>
Get an album by ID, including its tracks.
Sourcepub fn get_album_list(
&self,
list_type: &str,
size: u32,
offset: u32,
) -> Result<Vec<SubsonicAlbum>, SubsonicError>
pub fn get_album_list( &self, list_type: &str, size: u32, offset: u32, ) -> Result<Vec<SubsonicAlbum>, SubsonicError>
Get a paginated list of albums.
Sourcepub fn stream_url(&self, track_id: &str) -> Result<String, SubsonicError>
pub fn stream_url(&self, track_id: &str) -> Result<String, SubsonicError>
Build the streaming URL for a track (doesn’t make a request).
Sourcepub fn stream_url_template(&self, track_id: &str) -> String
pub fn stream_url_template(&self, track_id: &str) -> String
Stream URL without auth params — safe for database storage.
Sourcepub fn download(&self, track_id: &str, dest: &Path) -> Result<(), SubsonicError>
pub fn download(&self, track_id: &str, dest: &Path) -> Result<(), SubsonicError>
Download a track to a local path.
Sourcepub fn download_with_progress(
&self,
track_id: &str,
dest: &Path,
cancelled: &dyn Fn() -> bool,
on_progress: impl Fn(u64, u64),
) -> Result<(), SubsonicError>
pub fn download_with_progress( &self, track_id: &str, dest: &Path, cancelled: &dyn Fn() -> bool, on_progress: impl Fn(u64, u64), ) -> Result<(), SubsonicError>
Download a track with progress reporting.
The callback receives (bytes_downloaded, total_bytes); total is 0 when
the server sends no Content-Length, and the count restarts from zero if
an attempt is retried. dest only appears once the file is complete.
A server that is not answering is waited out, however long that takes,
until cancelled says the track is no longer wanted.
Sourcepub fn stream_to_file(
&self,
track_id: &str,
dest: &Path,
on_progress: impl Fn(u64, u64),
) -> Result<(), SubsonicError>
pub fn stream_to_file( &self, track_id: &str, dest: &Path, on_progress: impl Fn(u64, u64), ) -> Result<(), SubsonicError>
Fetch a track through /rest/stream instead of /rest/download.
download returns the untranscoded original and is what library sync
wants from Navidrome. koan’s own server implements only stream, so
that is how the remote bridge pulls audio from a koan serve instance.
Sourcepub fn all_songs_page(
&self,
size: u32,
offset: u32,
) -> Result<Vec<SubsonicSong>, SubsonicError>
pub fn all_songs_page( &self, size: u32, offset: u32, ) -> Result<Vec<SubsonicSong>, SubsonicError>
One page of every song on the server, size from offset.
An empty search3 query lists the whole library on OpenSubsonic
servers (Navidrome, koan). Older servers answer it with nothing or an
error, which is the caller’s cue to walk albums one at a time instead.
Sourcepub fn song_count(&self) -> Result<Option<u64>, SubsonicError>
pub fn song_count(&self) -> Result<Option<u64>, SubsonicError>
How many songs the server says it has, from getScanStatus. None
where the server does not count.
Sourcepub fn library_modified(
&self,
since: Option<i64>,
) -> Result<Option<i64>, SubsonicError>
pub fn library_modified( &self, since: Option<i64>, ) -> Result<Option<i64>, SubsonicError>
When the server’s library last changed, in milliseconds, as
getIndexes reports it. Asked since the version last seen, so a
library that has not moved answers with the timestamp alone. None
where the server gives none.
Sourcepub fn search(&self, query: &str) -> Result<SubsonicSearchResult, SubsonicError>
pub fn search(&self, query: &str) -> Result<SubsonicSearchResult, SubsonicError>
Search for tracks/albums/artists.
Sourcepub fn scrobble(
&self,
track_id: &str,
heard_at_ms: u64,
) -> Result<(), SubsonicError>
pub fn scrobble( &self, track_id: &str, heard_at_ms: u64, ) -> Result<(), SubsonicError>
Scrobble a play that counts, dated to heard_at_ms (ms since the
epoch the listen began).
Sourcepub fn report_playback(
&self,
track_id: &str,
state: PlaybackReportState,
position_ms: u64,
) -> Result<(), SubsonicError>
pub fn report_playback( &self, track_id: &str, state: PlaybackReportState, position_ms: u64, ) -> Result<(), SubsonicError>
Tell the server where playback of a track stands, so its Now Playing follows pauses, seeks and stops.
Uses OpenSubsonic’s reportPlayback where the server offers it, always
with ignoreScrobble: koan decides what counts as a play and scrobbles
it itself. Elsewhere only playing can be said, as a now-playing
scrobble from position (seconds, as Navidrome reads it); a pause or
a stop has no equivalent there and is not sent.
Sourcepub fn star(&self, track_id: &str) -> Result<(), SubsonicError>
pub fn star(&self, track_id: &str) -> Result<(), SubsonicError>
Star (favourite) a track on the server.
Sourcepub fn unstar(&self, track_id: &str) -> Result<(), SubsonicError>
pub fn unstar(&self, track_id: &str) -> Result<(), SubsonicError>
Unstar (unfavourite) a track on the server.
Sourcepub fn get_starred_all(&self) -> Result<SubsonicStarred, SubsonicError>
pub fn get_starred_all(&self) -> Result<SubsonicStarred, SubsonicError>
Everything the server has starred: songs, albums and artists.
Subsonic returns all three from one call, so asking for songs alone leaves a starred album invisible to us for no saving.
Sourcepub fn star_album(&self, album_id: &str) -> Result<(), SubsonicError>
pub fn star_album(&self, album_id: &str) -> Result<(), SubsonicError>
Star an album. Subsonic keys this off a different parameter to a song —
id would be read as a track and silently star nothing.
pub fn unstar_album(&self, album_id: &str) -> Result<(), SubsonicError>
pub fn star_artist(&self, artist_id: &str) -> Result<(), SubsonicError>
pub fn unstar_artist(&self, artist_id: &str) -> Result<(), SubsonicError>
Create a sharing link for one or more resources (songs, albums, etc). Returns the created share including its ID which forms the public URL.
Sourcepub fn get_similar_songs(
&self,
song_id: &str,
count: usize,
) -> Result<Vec<SubsonicSong>, SubsonicError>
pub fn get_similar_songs( &self, song_id: &str, count: usize, ) -> Result<Vec<SubsonicSong>, SubsonicError>
Get similar songs for a track (Subsonic getSimilarSongs2 endpoint).
Returns up to count similar songs based on the server’s algorithm.
Sourcepub fn get_playlists(&self) -> Result<Vec<SubsonicPlaylist>, SubsonicError>
pub fn get_playlists(&self) -> Result<Vec<SubsonicPlaylist>, SubsonicError>
Every playlist the server will show this user, without their contents.
Sourcepub fn get_playlist(
&self,
id: &str,
) -> Result<SubsonicPlaylistFull, SubsonicError>
pub fn get_playlist( &self, id: &str, ) -> Result<SubsonicPlaylistFull, SubsonicError>
One playlist, with its songs in order.
Sourcepub fn create_playlist(
&self,
playlist_id: Option<&str>,
name: &str,
song_ids: &[String],
) -> Result<Option<SubsonicPlaylistFull>, SubsonicError>
pub fn create_playlist( &self, playlist_id: Option<&str>, name: &str, song_ids: &[String], ) -> Result<Option<SubsonicPlaylistFull>, SubsonicError>
Create a playlist, or replace an existing one’s contents wholesale.
createPlaylist is the only Subsonic call that can set a playlist’s
order: updatePlaylist appends and removes by index, which cannot
express a reorder. Passing playlist_id turns this into “these songs,
in this order, from now on”, which is exactly what koan has after any
edit — so every push takes this path and there is one way for the two
sides to disagree instead of five.
Sourcepub fn update_playlist(
&self,
id: &str,
name: Option<&str>,
comment: Option<&str>,
public: Option<bool>,
) -> Result<(), SubsonicError>
pub fn update_playlist( &self, id: &str, name: Option<&str>, comment: Option<&str>, public: Option<bool>, ) -> Result<(), SubsonicError>
Change what can be changed without touching the song list.
pub fn delete_playlist(&self, id: &str) -> Result<(), SubsonicError>
pub fn koan_users(&self) -> Result<Vec<KoanUser>, SubsonicError>
Sourcepub fn koan_create_user(
&self,
username: &str,
role: &str,
) -> Result<KoanInvite, SubsonicError>
pub fn koan_create_user( &self, username: &str, role: &str, ) -> Result<KoanInvite, SubsonicError>
role is admin, user or readonly.
Sourcepub fn koan_invite(
&self,
username: &str,
reset: bool,
) -> Result<KoanInvite, SubsonicError>
pub fn koan_invite( &self, username: &str, reset: bool, ) -> Result<KoanInvite, SubsonicError>
With reset, the account gets a new password, which comes back with the
invite, and its devices sign out.
Sourcepub fn koan_revoke_own_key(&self) -> Result<(), SubsonicError>
pub fn koan_revoke_own_key(&self) -> Result<(), SubsonicError>
Revoke the API key this client signs in with (koanRevokeKey).
pub fn koan_set_user_role( &self, username: &str, role: &str, ) -> Result<(), SubsonicError>
pub fn koan_delete_user(&self, username: &str) -> Result<(), SubsonicError>
Sourcepub fn koan_command(&self, to: &str, command: &str) -> Result<(), SubsonicError>
pub fn koan_command(&self, to: &str, command: &str) -> Result<(), SubsonicError>
Have the server hand command (a link command, as JSON) to the device
to on this account: a koan extension, koanDevices.
pub fn auth(&self) -> &SubsonicAuth
Auto Trait Implementations§
impl !Freeze for SubsonicClient
impl !RefUnwindSafe for SubsonicClient
impl !UnwindSafe for SubsonicClient
impl Send for SubsonicClient
impl Sync for SubsonicClient
impl Unpin for SubsonicClient
impl UnsafeUnpin for SubsonicClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);