cider_api/lib.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! # Cider API
6//!
7//! Async Rust client for the [Cider](https://cider.sh) music player REST API.
8//!
9//! Cider exposes a local HTTP API (default port **10767**) for controlling
10//! playback, managing the queue, and querying track information. This crate
11//! provides a fully typed, async client built on [`reqwest`].
12//!
13//! ## Quick start
14//!
15//! ```no_run
16//! use cider_api::CiderClient;
17//!
18//! # async fn example() -> Result<(), cider_api::CiderError> {
19//! let client = CiderClient::new();
20//!
21//! // Check if Cider is running
22//! client.is_active().await?;
23//!
24//! // Get the currently playing track
25//! if let Some(track) = client.now_playing().await? {
26//! println!("{} — {}", track.name, track.artist_name);
27//! println!("Album: {}", track.album_name);
28//! println!("Artwork: {}", track.artwork_url(600));
29//! println!(
30//! "Position: {:.1}s / {:.1}s",
31//! track.current_playback_time,
32//! track.duration_in_millis as f64 / 1000.0,
33//! );
34//! }
35//!
36//! // Control playback
37//! client.pause().await?;
38//! client.seek_ms(30_000).await?;
39//! client.play().await?;
40//! # Ok(())
41//! # }
42//! ```
43//!
44//! ## Authentication
45//!
46//! If Cider has API authentication enabled (Settings > Connectivity > Manage
47//! External Application Access), pass the token via [`CiderClient::with_token`]:
48//!
49//! ```no_run
50//! # use cider_api::CiderClient;
51//! let client = CiderClient::new().with_token("your-api-token");
52//! ```
53//!
54//! The token is sent in the `apitoken` header — no `Bearer` prefix.
55//!
56//! ## API coverage
57//!
58//! | Category | Methods |
59//! |---|---|
60//! | **Status** | [`is_active`](CiderClient::is_active), [`is_playing`](CiderClient::is_playing), [`now_playing`](CiderClient::now_playing) |
61//! | **Playback** | [`play`](CiderClient::play), [`pause`](CiderClient::pause), [`play_pause`](CiderClient::play_pause), [`stop`](CiderClient::stop), [`next`](CiderClient::next), [`previous`](CiderClient::previous), [`seek`](CiderClient::seek), [`seek_ms`](CiderClient::seek_ms) |
62//! | **Play items** | [`play_url`](CiderClient::play_url), [`play_item`](CiderClient::play_item), [`play_item_href`](CiderClient::play_item_href), [`play_next`](CiderClient::play_next), [`play_later`](CiderClient::play_later) |
63//! | **Queue** | [`get_queue`](CiderClient::get_queue), [`queue_move_to_position`](CiderClient::queue_move_to_position), [`queue_remove_by_index`](CiderClient::queue_remove_by_index), [`clear_queue`](CiderClient::clear_queue) |
64//! | **Volume** | [`get_volume`](CiderClient::get_volume), [`set_volume`](CiderClient::set_volume) |
65//! | **Settings** | [`get_repeat_mode`](CiderClient::get_repeat_mode), [`toggle_repeat`](CiderClient::toggle_repeat), [`get_shuffle_mode`](CiderClient::get_shuffle_mode), [`toggle_shuffle`](CiderClient::toggle_shuffle), [`get_autoplay`](CiderClient::get_autoplay), [`toggle_autoplay`](CiderClient::toggle_autoplay) |
66//! | **Library** | [`add_to_library`](CiderClient::add_to_library), [`set_rating`](CiderClient::set_rating) |
67//! | **Apple Music API** | [`amapi_run_v3`](CiderClient::amapi_run_v3) |
68
69mod client;
70mod types;
71
72pub use client::{CiderClient, CiderError, DEFAULT_PORT};
73pub use types::*;