Skip to main content

CiderClient

Struct CiderClient 

Source
pub struct CiderClient { /* private fields */ }
Expand description

Async client for the Cider music player REST API.

Communicates with Cider’s local HTTP server (default http://127.0.0.1:10767) to control playback, manage the queue, and query track information.

§Construction

use cider_api::CiderClient;

// Default (localhost:10767, no auth)
let client = CiderClient::new();

// Custom port
let client = CiderClient::with_port(9999);

// With authentication
let client = CiderClient::new().with_token("my-token");

The client is cheaply Cloneable — it shares an inner connection pool.

§Errors

All async methods return Result<_, CiderError>. Common error cases:

Implementations§

Source§

impl CiderClient

Source

pub fn new() -> Self

Create a new client targeting http://127.0.0.1:10767.

Source

pub fn with_port(port: u16) -> Self

Create a new client targeting http://127.0.0.1:{port}.

§Panics

Panics if the underlying HTTP client cannot be constructed (only possible if TLS initialisation fails at the OS level).

Source

pub fn with_token(self, token: impl Into<String>) -> Self

Attach an API token for authentication.

The token is sent in the apptoken header on every request. Generate one in Cider under Settings > Connectivity > Manage External Application Access.

Source

pub async fn is_active(&self) -> Result<(), CiderError>

Check that Cider is running and the RPC server is reachable.

Sends GET /active — Cider responds with 204 No Content if alive.

§Errors
Source

pub async fn is_playing(&self) -> Result<bool, CiderError>

Check whether music is currently playing.

Sends GET /is-playing.

§Errors

Returns CiderError if the request fails or the response cannot be parsed.

Source

pub async fn now_playing(&self) -> Result<Option<NowPlaying>, CiderError>

Get the currently playing track.

Returns None if nothing is loaded. The returned NowPlaying includes both Apple Music catalog metadata and live playback state (current_playback_time, remaining_time, etc.).

Sends GET /now-playing.

§Errors

Returns CiderError on network failure. Returns Ok(None) (not an error) if nothing is playing or the response cannot be parsed.

Source

pub async fn play(&self) -> Result<(), CiderError>

Resume playback.

If nothing is loaded, the behaviour set under Settings > Play Button on Stopped Action takes effect.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn pause(&self) -> Result<(), CiderError>

Pause the current track. No-op if already paused or nothing is playing.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn play_pause(&self) -> Result<(), CiderError>

Toggle between playing and paused.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn stop(&self) -> Result<(), CiderError>

Stop playback and unload the current track. Queue items are kept.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn next(&self) -> Result<(), CiderError>

Skip to the next track in the queue.

Respects autoplay status if the queue is empty.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn previous(&self) -> Result<(), CiderError>

Go back to the previously played track (from playback history).

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn seek(&self, position_secs: f64) -> Result<(), CiderError>

Seek to a position in the current track.

§Arguments
  • position_secs — target offset in seconds (e.g. 30.0).
§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn seek_ms(&self, position_ms: u64) -> Result<(), CiderError>

Convenience wrapper for seek that accepts milliseconds.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn play_url(&self, url: &str) -> Result<(), CiderError>

Start playback of an Apple Music URL.

The URL can be obtained from Share > Apple Music in Cider or the Apple Music web player.

§Arguments
  • url — e.g. "https://music.apple.com/ca/album/…/1719860281"
§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn play_item( &self, item_type: &str, id: &str, ) -> Result<(), CiderError>

Start playback of an item by Apple Music type and catalog ID.

§Arguments
  • item_type — Apple Music type: "songs", "albums", "playlists", etc.
  • id — catalog ID as a string (e.g. "1719861213").
§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn play_item_href(&self, href: &str) -> Result<(), CiderError>

Start playback of an item by its Apple Music API href.

§Arguments
  • href — API path, e.g. "/v1/catalog/ca/songs/1719861213".
§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn play_next( &self, item_type: &str, id: &str, ) -> Result<(), CiderError>

Add an item to the start of the queue (plays next).

§Arguments
  • item_type"songs", "albums", etc.
  • id — catalog ID as a string.
§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn play_later( &self, item_type: &str, id: &str, ) -> Result<(), CiderError>

Add an item to the end of the queue (plays last).

§Arguments
  • item_type"songs", "albums", etc.
  • id — catalog ID as a string.
§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn get_queue(&self) -> Result<Vec<QueueItem>, CiderError>

Get the current playback queue.

Returns a Vec<QueueItem> that includes history items, the currently playing track, and upcoming items. Use QueueItem::is_current to find the active track.

Returns an empty Vec if the queue is empty or the response format is unexpected.

§Errors

Returns CiderError on network failure. Returns Ok(vec![]) (not an error) if the queue is empty or the format is unrecognised.

Source

pub async fn queue_move_to_position( &self, start_index: u32, destination_index: u32, ) -> Result<(), CiderError>

Move a queue item from one position to another.

Both indices are 1-based. The queue includes history items, so the first visible “Up Next” item may not be at index 1.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn queue_remove_by_index(&self, index: u32) -> Result<(), CiderError>

Remove a queue item by its 1-based index.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn clear_queue(&self) -> Result<(), CiderError>

Clear all items from the queue.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn get_volume(&self) -> Result<f32, CiderError>

Get the current volume (0.0 = muted, 1.0 = full).

§Errors

Returns CiderError if the request fails or the response cannot be parsed.

Source

pub async fn set_volume(&self, volume: f32) -> Result<(), CiderError>

Set the volume. Values are clamped to 0.0..=1.0.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn add_to_library(&self) -> Result<(), CiderError>

Add the currently playing track to the user’s library.

No-op if the track is already in the library.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn set_rating(&self, rating: i8) -> Result<(), CiderError>

Rate the currently playing track.

  • -1 — dislike
  • 0 — remove rating
  • 1 — like

The value is clamped to -1..=1.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn get_repeat_mode(&self) -> Result<u8, CiderError>

Get the current repeat mode.

  • 0 — off
  • 1 — repeat this song
  • 2 — repeat all
§Errors

Returns CiderError if the request fails or the response cannot be parsed.

Source

pub async fn toggle_repeat(&self) -> Result<(), CiderError>

Cycle repeat mode: repeat one > repeat all > off.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn get_shuffle_mode(&self) -> Result<u8, CiderError>

Get the current shuffle mode (0 = off, 1 = on).

§Errors

Returns CiderError if the request fails or the response cannot be parsed.

Source

pub async fn toggle_shuffle(&self) -> Result<(), CiderError>

Toggle shuffle on/off.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn get_autoplay(&self) -> Result<bool, CiderError>

Get the current autoplay status (true = on).

§Errors

Returns CiderError if the request fails or the response cannot be parsed.

Source

pub async fn toggle_autoplay(&self) -> Result<(), CiderError>

Toggle autoplay on/off.

§Errors

Returns CiderError if the request fails or the server rejects it.

Source

pub async fn amapi_run_v3(&self, path: &str) -> Result<Value, CiderError>

Execute a raw Apple Music API request via Cider’s passthrough.

Sends POST /api/v1/amapi/run-v3 with the given path, and returns the raw JSON response from Apple Music.

§Arguments
  • path — Apple Music API path, e.g. "/v1/me/library/songs" or "/v1/catalog/us/search?term=flume&types=songs".
§Errors

Returns CiderError if the request fails or the response cannot be parsed.

Trait Implementations§

Source§

impl Clone for CiderClient

Source§

fn clone(&self) -> CiderClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CiderClient

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CiderClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more