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