Skip to main content

redseat_api/
lib.rs

1//! Rust client for Redseat media servers.
2//!
3//! - [`CloudClient`]: the Redseat cloud: sign-in with a Google ID token, the user's
4//!   servers, server tokens.
5//! - [`google`] (feature `desktop-auth`, not on wasm): Google sign-in in the browser
6//!   for desktop apps.
7//! - [`RedseatClient`]: requests to one server through a [`Transport`], with the server
8//!   token refreshed before it expires, and its events as a typed stream.
9//! - [`ServerApi`] and [`LibraryApi`]: libraries, medias and their files, tags, people,
10//!   series, movies, books, channels, watch history, requests through plugins.
11//! - [`http`] (feature `http`, default): the HTTP + SSE transport, and the choice of
12//!   the server address.
13//!
14//! The data types are the server's own, from `rs-plugin-common-interfaces`
15//! ([`types`]), and encrypted libraries use the server's own implementation, from
16//! `redseat-crypto` ([`crypto`]).
17//!
18//! ```no_run
19//! # #[cfg(feature = "http")]
20//! # async fn run(google_id_token: &str) -> redseat_api::Result<()> {
21//! use redseat_api::{CloudClient, RedseatClient, ServerApi};
22//! use redseat_api::types::media::MediaQuery;
23//!
24//! let cloud = CloudClient::http()?;
25//! let session = cloud.sign_in_with_google_id_token(google_id_token).await?;
26//! let servers = cloud.list_servers(&session.token).await?;
27//! let client =
28//!     RedseatClient::connect_http(&servers[0], cloud, &session.token, Default::default())
29//!         .await?;
30//! let server = ServerApi::new(client);
31//! let libraries = server.get_libraries().await?;
32//! let library = server.library(libraries[0].clone());
33//! let query = MediaQuery { limit: Some(10), ..Default::default() };
34//! let page = library.get_medias_page(&query).await?;
35//! let thumb = library.get_thumb(&page.medias[0].item).await?;
36//! # Ok(()) }
37//! ```
38
39#![cfg_attr(
40    not(test),
41    deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)
42)]
43// On wasm, transports and token sources are not `Send` (JS handles): the client still
44// shares them with `Arc`, so the code is the same on every target.
45#![cfg_attr(target_arch = "wasm32", allow(clippy::arc_with_non_send_sync))]
46
47/// Data exchanged with the server: libraries, medias, movies, series, events...
48pub use rs_plugin_common_interfaces::domain as types;
49
50/// The crate the data types come from, for those outside [`types`]:
51/// `request::RsRequest` and `request::RsGroupDownload`, `MediaType`, `url::RsLink`...
52pub use rs_plugin_common_interfaces;
53
54/// Encryption of encrypted libraries, byte-compatible with the server.
55pub use redseat_crypto as crypto;
56
57pub mod client;
58pub mod cloud;
59pub mod direct;
60pub mod encrypted;
61pub mod error;
62pub mod events;
63pub mod library;
64#[cfg(feature = "mirror")]
65pub mod mirror;
66pub mod server;
67pub mod sse;
68pub mod transport;
69
70#[cfg(feature = "http")]
71pub mod http;
72
73#[cfg(all(feature = "desktop-auth", not(target_arch = "wasm32")))]
74pub mod google;
75
76#[cfg(test)]
77mod test_support;
78
79pub use client::{
80    AuthorizedUrl, ClientOptions, CloudTokenSource, EventOptions, RedseatClient, ServerEventStream,
81    ServerTokenSource,
82};
83pub use cloud::{CloudClient, CloudServer, CloudSession, CloudUser, ServerToken};
84pub use encrypted::EncryptedMediaReader;
85pub use error::{Error, ErrorKind, Result};
86pub use events::ServerEvent;
87pub use library::{LibraryApi, MediaItem, MediaPage};
88#[cfg(feature = "mirror")]
89pub use mirror::{Mirror, MirrorEvent, MirrorOptions};
90pub use server::ServerApi;
91pub use transport::Transport;
92
93#[cfg(test)]
94mod tests {
95    use super::types::library::{LibraryType, ServerLibrary};
96
97    #[test]
98    fn reads_a_library_as_the_server_sends_it() {
99        let library: ServerLibrary = serde_json::from_value(serde_json::json!({
100            "id": "lib1",
101            "name": "Photos",
102            "source": "PathProvider",
103            "type": "photos",
104            "settings": {}
105        }))
106        .unwrap();
107        assert_eq!(library.kind, LibraryType::Photos);
108    }
109}