feat(yarr): restructure into workspace with separate API and CLI crates
This commit is contained in:
33
yarr-api/Cargo.toml
Normal file
33
yarr-api/Cargo.toml
Normal file
@@ -0,0 +1,33 @@
|
||||
[package]
|
||||
name = "yarr-api"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
description = "Sonarr API client library"
|
||||
authors = ["yarr contributors"]
|
||||
repository = "https://github.com/user/yarr"
|
||||
|
||||
[dependencies]
|
||||
# HTTP client and serialization
|
||||
reqwest = { workspace = true, features = ["json"] }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
# Async runtime
|
||||
tokio = { workspace = true }
|
||||
|
||||
# Date/time handling
|
||||
chrono = { workspace = true, features = ["serde"] }
|
||||
|
||||
# Error handling
|
||||
thiserror = { workspace = true }
|
||||
|
||||
# Logging
|
||||
tracing = { workspace = true }
|
||||
|
||||
# URL encoding
|
||||
urlencoding = "2.1.3"
|
||||
|
||||
[dev-dependencies]
|
||||
# For examples
|
||||
tracing-subscriber = { workspace = true }
|
||||
135
yarr-api/README.md
Normal file
135
yarr-api/README.md
Normal file
@@ -0,0 +1,135 @@
|
||||
# yarr-api
|
||||
|
||||
A Rust client library for the Sonarr API.
|
||||
|
||||
## Overview
|
||||
|
||||
`yarr-api` provides a strongly-typed, async Rust client for interacting with Sonarr instances. It handles authentication, request/response serialization, and provides convenient methods for all major Sonarr API endpoints.
|
||||
|
||||
## Features
|
||||
|
||||
- **Async/await support** - Built on `tokio` and `reqwest`
|
||||
- **Type-safe API** - All API responses are strongly typed with `serde`
|
||||
- **Error handling** - Comprehensive error types with detailed error information
|
||||
- **Easy to use** - Simple client interface with intuitive method names
|
||||
- **Well documented** - Extensive documentation and examples
|
||||
|
||||
## Installation
|
||||
|
||||
Add this to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
yarr-api = "0.1.0"
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
```rust
|
||||
use yarr_api::{SonarrClient, Result};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Create a client
|
||||
let client = SonarrClient::new(
|
||||
"http://localhost:8989".to_string(),
|
||||
"your-api-key".to_string()
|
||||
);
|
||||
|
||||
// Get system status
|
||||
let status = client.get_system_status().await?;
|
||||
println!("Sonarr version: {}", status.version.unwrap_or_default());
|
||||
|
||||
// Get all series
|
||||
let series = client.get_series().await?;
|
||||
println!("Total series: {}", series.len());
|
||||
|
||||
// Get download queue
|
||||
let queue = client.get_queue().await?;
|
||||
println!("Items in queue: {}", queue.records.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
## API Coverage
|
||||
|
||||
### System
|
||||
- ✅ System status
|
||||
- ✅ Health check
|
||||
|
||||
### Series Management
|
||||
- ✅ List all series
|
||||
- ✅ Get series by ID
|
||||
- ✅ Search for series
|
||||
- ✅ Add new series
|
||||
|
||||
### Episodes
|
||||
- ✅ Get episodes for series/season
|
||||
- ✅ Get calendar (upcoming episodes)
|
||||
- ✅ Get missing episodes
|
||||
|
||||
### Downloads
|
||||
- ✅ Get download queue
|
||||
- ✅ Get download history
|
||||
|
||||
## Examples
|
||||
|
||||
See the `examples/` directory for more comprehensive usage examples:
|
||||
|
||||
```bash
|
||||
# Run the basic usage example
|
||||
cargo run --example basic_usage
|
||||
|
||||
# Make sure to set your Sonarr URL and API key first:
|
||||
export SONARR_URL="http://localhost:8989"
|
||||
export SONARR_API_KEY="your-api-key-here"
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
The library uses a custom `ApiError` type that provides detailed error information:
|
||||
|
||||
```rust
|
||||
use yarr_api::{SonarrClient, ApiError};
|
||||
|
||||
let client = SonarrClient::new(url, api_key);
|
||||
|
||||
match client.get_series().await {
|
||||
Ok(series) => println!("Found {} series", series.len()),
|
||||
Err(ApiError::Authentication) => println!("Invalid API key"),
|
||||
Err(ApiError::NotFound) => println!("Endpoint not found"),
|
||||
Err(ApiError::ServerError) => println!("Sonarr server error"),
|
||||
Err(e) => println!("Other error: {}", e),
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The client requires two pieces of information:
|
||||
|
||||
1. **Base URL** - The URL of your Sonarr instance (e.g., `http://localhost:8989`)
|
||||
2. **API Key** - Your Sonarr API key (found in Settings > General > Security)
|
||||
|
||||
## Data Types
|
||||
|
||||
All Sonarr API responses are represented as strongly-typed Rust structs:
|
||||
|
||||
- `SystemStatus` - System information and status
|
||||
- `Series` - TV series information
|
||||
- `Episode` - Episode details
|
||||
- `QueueItem` - Download queue items
|
||||
- `HistoryItem` - Download history
|
||||
- `HealthResource` - Health check results
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the LICENSE file for details.
|
||||
|
||||
## Related Projects
|
||||
|
||||
- [yarr](../yarr-cli) - TUI client for Sonarr built using this library
|
||||
125
yarr-api/examples/basic_usage.rs
Normal file
125
yarr-api/examples/basic_usage.rs
Normal file
@@ -0,0 +1,125 @@
|
||||
//! Basic usage example for the yarr-api crate
|
||||
//!
|
||||
//! This example demonstrates how to use the Sonarr API client to fetch basic information.
|
||||
//!
|
||||
//! To run this example:
|
||||
//! ```bash
|
||||
//! cargo run --example basic_usage
|
||||
//! ```
|
||||
//!
|
||||
//! Make sure to set the following environment variables:
|
||||
//! - SONARR_URL: Your Sonarr instance URL (e.g., "http://localhost:8989")
|
||||
//! - SONARR_API_KEY: Your Sonarr API key
|
||||
|
||||
use yarr_api::{Result, SonarrClient};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Initialize tracing for better error visibility
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
// Get configuration from environment variables
|
||||
let sonarr_url =
|
||||
std::env::var("SONARR_URL").unwrap_or_else(|_| "http://localhost:8989".to_string());
|
||||
let sonarr_api_key =
|
||||
std::env::var("SONARR_API_KEY").expect("SONARR_API_KEY environment variable must be set");
|
||||
|
||||
// Create the API client
|
||||
let client = SonarrClient::new(sonarr_url, sonarr_api_key);
|
||||
|
||||
println!("Connecting to Sonarr...");
|
||||
|
||||
// Fetch and display system status
|
||||
match client.get_system_status().await {
|
||||
Ok(status) => {
|
||||
println!("✓ Connected to Sonarr successfully!");
|
||||
println!(" App Name: {}", status.app_name.unwrap_or_default());
|
||||
println!(" Version: {}", status.version.unwrap_or_default());
|
||||
println!(" Instance: {}", status.instance_name.unwrap_or_default());
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("✗ Failed to connect to Sonarr: {}", e);
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch and display series count
|
||||
match client.get_series().await {
|
||||
Ok(series) => {
|
||||
println!("\n📺 Series Information:");
|
||||
println!(" Total series: {}", series.len());
|
||||
|
||||
let monitored_count = series.iter().filter(|s| s.monitored).count();
|
||||
println!(" Monitored series: {}", monitored_count);
|
||||
|
||||
if !series.is_empty() {
|
||||
println!("\n🎬 Sample series:");
|
||||
for (i, show) in series.iter().take(5).enumerate() {
|
||||
let title = show.title.as_deref().unwrap_or("Unknown");
|
||||
let status = if show.monitored {
|
||||
"Monitored"
|
||||
} else {
|
||||
"Not Monitored"
|
||||
};
|
||||
println!(" {}. {} ({})", i + 1, title, status);
|
||||
}
|
||||
|
||||
if series.len() > 5 {
|
||||
println!(" ... and {} more", series.len() - 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("✗ Failed to fetch series: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch and display queue information
|
||||
match client.get_queue().await {
|
||||
Ok(queue) => {
|
||||
println!("\n📥 Download Queue:");
|
||||
println!(" Items in queue: {}", queue.records.len());
|
||||
|
||||
if !queue.records.is_empty() {
|
||||
for (i, item) in queue.records.iter().take(3).enumerate() {
|
||||
let title = item.title.as_deref().unwrap_or("Unknown");
|
||||
let status = &item.status;
|
||||
println!(" {}. {} ({})", i + 1, title, status);
|
||||
}
|
||||
|
||||
if queue.records.len() > 3 {
|
||||
println!(" ... and {} more", queue.records.len() - 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("✗ Failed to fetch queue: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Check health status
|
||||
match client.get_health().await {
|
||||
Ok(health) => {
|
||||
println!("\n🏥 Health Status:");
|
||||
if health.is_empty() {
|
||||
println!(" ✓ All systems healthy!");
|
||||
} else {
|
||||
println!(" ⚠️ {} health issue(s) detected:", health.len());
|
||||
for (i, issue) in health.iter().take(3).enumerate() {
|
||||
let message = issue.message.as_deref().unwrap_or("Unknown issue");
|
||||
println!(" {}. {}", i + 1, message);
|
||||
}
|
||||
|
||||
if health.len() > 3 {
|
||||
println!(" ... and {} more issues", health.len() - 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("✗ Failed to fetch health status: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
println!("\n🎉 Example completed successfully!");
|
||||
Ok(())
|
||||
}
|
||||
74
yarr-api/src/error.rs
Normal file
74
yarr-api/src/error.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use thiserror::Error;
|
||||
|
||||
/// Result type alias for API operations
|
||||
pub type Result<T, E = ApiError> = std::result::Result<T, E>;
|
||||
|
||||
/// Error types for the Sonarr API client
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ApiError {
|
||||
/// HTTP request failed
|
||||
#[error("HTTP request failed")]
|
||||
Request,
|
||||
|
||||
/// API returned an error response
|
||||
#[error("API error")]
|
||||
Api,
|
||||
|
||||
/// Failed to serialize/deserialize JSON
|
||||
#[error("JSON serialization/deserialization failed")]
|
||||
Json,
|
||||
|
||||
/// Invalid URL or endpoint
|
||||
#[error("Invalid URL or endpoint")]
|
||||
InvalidUrl,
|
||||
|
||||
/// Authentication failed (invalid API key)
|
||||
#[error("Authentication failed")]
|
||||
Authentication,
|
||||
|
||||
/// Resource not found
|
||||
#[error("Resource not found")]
|
||||
NotFound,
|
||||
|
||||
/// Rate limit exceeded
|
||||
#[error("Rate limit exceeded")]
|
||||
RateLimit,
|
||||
|
||||
/// Server error (5xx responses)
|
||||
#[error("Server error")]
|
||||
ServerError,
|
||||
|
||||
/// Connection timeout
|
||||
#[error("Connection timeout")]
|
||||
Timeout,
|
||||
|
||||
/// Generic error with custom message
|
||||
#[error("API client error: {message}")]
|
||||
Generic { message: String },
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for ApiError {
|
||||
fn from(err: reqwest::Error) -> Self {
|
||||
if err.is_timeout() {
|
||||
ApiError::Timeout
|
||||
} else if err.is_connect() {
|
||||
ApiError::Request
|
||||
} else if let Some(status) = err.status() {
|
||||
match status.as_u16() {
|
||||
401 | 403 => ApiError::Authentication,
|
||||
404 => ApiError::NotFound,
|
||||
429 => ApiError::RateLimit,
|
||||
500..=599 => ApiError::ServerError,
|
||||
_ => ApiError::Api,
|
||||
}
|
||||
} else {
|
||||
ApiError::Request
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for ApiError {
|
||||
fn from(_: serde_json::Error) -> Self {
|
||||
ApiError::Json
|
||||
}
|
||||
}
|
||||
570
yarr-api/src/lib.rs
Normal file
570
yarr-api/src/lib.rs
Normal file
@@ -0,0 +1,570 @@
|
||||
//! Sonarr API client library
|
||||
//!
|
||||
//! This crate provides a Rust client for the Sonarr API, allowing you to interact
|
||||
//! with Sonarr instances programmatically.
|
||||
|
||||
pub mod error;
|
||||
|
||||
pub use error::{ApiError, Result};
|
||||
|
||||
use reqwest::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SonarrClient {
|
||||
client: Client,
|
||||
base_url: String,
|
||||
api_key: String,
|
||||
}
|
||||
|
||||
impl SonarrClient {
|
||||
pub fn new(base_url: String, api_key: String) -> Self {
|
||||
Self {
|
||||
client: Client::new(),
|
||||
base_url: base_url.trim_end_matches('/').to_string(),
|
||||
api_key,
|
||||
}
|
||||
}
|
||||
|
||||
async fn get<T: for<'de> Deserialize<'de>>(&self, endpoint: &str) -> Result<T, ApiError> {
|
||||
let url = format!("{}/api/v3{}", self.base_url, endpoint);
|
||||
let response = self
|
||||
.client
|
||||
.get(&url)
|
||||
.header("X-Api-Key", &self.api_key)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
let status = response.status();
|
||||
let error_text = response
|
||||
.text()
|
||||
.await
|
||||
.unwrap_or_else(|_| "Unknown error".to_string());
|
||||
return Err(ApiError::Generic {
|
||||
message: format!("HTTP {}: {}", status, error_text),
|
||||
});
|
||||
}
|
||||
|
||||
let text = response.text().await?;
|
||||
let result: T = serde_json::from_str(&text)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_debug<T: for<'de> Deserialize<'de>>(&self, endpoint: &str) -> Result<T, ApiError> {
|
||||
let url = format!("{}/api/v3{}", self.base_url, endpoint);
|
||||
let response = self
|
||||
.client
|
||||
.get(&url)
|
||||
.header("X-Api-Key", &self.api_key)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
let status = response.status();
|
||||
let error_text = response
|
||||
.text()
|
||||
.await
|
||||
.unwrap_or_else(|_| "Unknown error".to_string());
|
||||
return Err(ApiError::Generic {
|
||||
message: format!("Debug HTTP {}: {}", status, error_text),
|
||||
});
|
||||
}
|
||||
|
||||
let text = response.text().await?;
|
||||
let _ = std::fs::write(endpoint.replace("/", "_"), &text);
|
||||
let result: T = serde_json::from_str(&text)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn post<T: Serialize, R: for<'de> Deserialize<'de>>(
|
||||
&self,
|
||||
endpoint: &str,
|
||||
body: &T,
|
||||
) -> Result<R, ApiError> {
|
||||
let url = format!("{}/api/v3{}", self.base_url, endpoint);
|
||||
let response = self
|
||||
.client
|
||||
.post(&url)
|
||||
.header("X-Api-Key", &self.api_key)
|
||||
.json(body)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
let status = response.status();
|
||||
let error_text = response
|
||||
.text()
|
||||
.await
|
||||
.unwrap_or_else(|_| "Unknown error".to_string());
|
||||
return Err(ApiError::Generic {
|
||||
message: format!("POST HTTP {}: {}", status, error_text),
|
||||
});
|
||||
}
|
||||
|
||||
let text = response.text().await?;
|
||||
let result: R = serde_json::from_str(&text)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn get_system_status(&self) -> Result<SystemStatus, ApiError> {
|
||||
self.get("/system/status").await
|
||||
}
|
||||
|
||||
pub async fn get_series(&self) -> Result<Vec<Series>, ApiError> {
|
||||
self.get("/series").await
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_series_by_id(&self, id: u32) -> Result<Series, ApiError> {
|
||||
self.get(&format!("/series/{}", id)).await
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_episodes(
|
||||
&self,
|
||||
series_id: Option<u32>,
|
||||
season_number: Option<u32>,
|
||||
) -> Result<Vec<Episode>, ApiError> {
|
||||
let mut query = Vec::new();
|
||||
if let Some(id) = series_id {
|
||||
query.push(format!("seriesId={}", id));
|
||||
}
|
||||
if let Some(season) = season_number {
|
||||
query.push(format!("seasonNumber={}", season));
|
||||
}
|
||||
|
||||
let query_string = if query.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!("?{}", query.join("&"))
|
||||
};
|
||||
|
||||
self.get(&format!("/episode{}", query_string)).await
|
||||
}
|
||||
|
||||
pub async fn get_calendar(
|
||||
&self,
|
||||
start: Option<&str>,
|
||||
end: Option<&str>,
|
||||
) -> Result<Vec<Episode>, ApiError> {
|
||||
let mut query = Vec::new();
|
||||
if let Some(start_date) = start {
|
||||
query.push(format!("start={}", start_date));
|
||||
}
|
||||
if let Some(end_date) = end {
|
||||
query.push(format!("end={}", end_date));
|
||||
}
|
||||
|
||||
let query_string = if query.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!("?{}", query.join("&"))
|
||||
};
|
||||
|
||||
self.get(&format!("/calendar{}", query_string)).await
|
||||
}
|
||||
|
||||
pub async fn get_queue(&self) -> Result<QueuePagingResource, ApiError> {
|
||||
self.get("/queue").await
|
||||
}
|
||||
|
||||
pub async fn get_history(&self) -> Result<HistoryPagingResource, ApiError> {
|
||||
self.get("/history").await
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_missing_episodes(&self) -> Result<EpisodePagingResource, ApiError> {
|
||||
self.get("/wanted/missing").await
|
||||
}
|
||||
|
||||
pub async fn get_health(&self) -> Result<Vec<HealthResource>, ApiError> {
|
||||
self.get("/health").await
|
||||
}
|
||||
|
||||
pub async fn search_series(&self, term: &str) -> Result<Vec<Series>, ApiError> {
|
||||
self.get(&format!(
|
||||
"/series/lookup?term={}",
|
||||
urlencoding::encode(term)
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn add_series(&self, series: &Series) -> Result<Series, ApiError> {
|
||||
self.post("/series", series).await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SystemStatus {
|
||||
pub app_name: Option<String>,
|
||||
pub instance_name: Option<String>,
|
||||
pub version: Option<String>,
|
||||
pub build_time: chrono::DateTime<chrono::Utc>,
|
||||
pub is_debug: bool,
|
||||
pub is_production: bool,
|
||||
pub is_admin: bool,
|
||||
pub is_user_interactive: bool,
|
||||
pub startup_path: Option<String>,
|
||||
pub app_data: Option<String>,
|
||||
pub os_name: Option<String>,
|
||||
pub os_version: Option<String>,
|
||||
pub is_net_core: bool,
|
||||
pub is_linux: bool,
|
||||
pub is_osx: bool,
|
||||
pub is_windows: bool,
|
||||
pub is_docker: bool,
|
||||
pub mode: String,
|
||||
pub branch: Option<String>,
|
||||
pub authentication: String,
|
||||
pub sqlite_version: Option<String>,
|
||||
pub migration_version: i32,
|
||||
pub url_base: Option<String>,
|
||||
pub runtime_version: Option<String>,
|
||||
pub runtime_name: Option<String>,
|
||||
pub start_time: chrono::DateTime<chrono::Utc>,
|
||||
pub package_version: Option<String>,
|
||||
pub package_author: Option<String>,
|
||||
pub package_update_mechanism: String,
|
||||
pub package_update_mechanism_message: Option<String>,
|
||||
pub database_version: Option<String>,
|
||||
pub database_type: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Series {
|
||||
pub id: Option<u32>,
|
||||
pub title: Option<String>,
|
||||
pub alternate_titles: Option<Vec<AlternateTitle>>,
|
||||
pub sort_title: Option<String>,
|
||||
pub status: String,
|
||||
pub ended: Option<bool>,
|
||||
pub profile_name: Option<String>,
|
||||
pub overview: Option<String>,
|
||||
pub next_airing: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub previous_airing: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub network: Option<String>,
|
||||
pub air_time: Option<String>,
|
||||
pub images: Option<Vec<MediaCover>>,
|
||||
pub original_language: Option<Language>,
|
||||
pub remote_poster: Option<String>,
|
||||
pub seasons: Option<Vec<Season>>,
|
||||
pub year: u32,
|
||||
pub path: Option<String>,
|
||||
pub quality_profile_id: u32,
|
||||
pub season_folder: bool,
|
||||
pub monitored: bool,
|
||||
pub monitor_new_items: String,
|
||||
pub use_scene_numbering: bool,
|
||||
pub runtime: u32,
|
||||
pub tvdb_id: u32,
|
||||
pub tv_rage_id: u32,
|
||||
pub tv_maze_id: u32,
|
||||
pub tmdb_id: u32,
|
||||
pub first_aired: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub last_aired: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub series_type: String,
|
||||
pub clean_title: Option<String>,
|
||||
pub imdb_id: Option<String>,
|
||||
pub title_slug: Option<String>,
|
||||
pub root_folder_path: Option<String>,
|
||||
pub folder: Option<String>,
|
||||
pub certification: Option<String>,
|
||||
pub genres: Option<Vec<String>>,
|
||||
pub tags: Option<Vec<u32>>,
|
||||
pub added: chrono::DateTime<chrono::Utc>,
|
||||
pub add_options: Option<AddSeriesOptions>,
|
||||
pub ratings: Option<Ratings>,
|
||||
pub statistics: Option<SeriesStatistics>,
|
||||
pub episodes_changed: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AlternateTitle {
|
||||
pub title: Option<String>,
|
||||
pub season_number: Option<i32>,
|
||||
pub scene_season_number: Option<i32>,
|
||||
pub scene_origin: Option<String>,
|
||||
pub comment: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MediaCover {
|
||||
pub cover_type: String,
|
||||
pub url: Option<String>,
|
||||
pub remote_url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Language {
|
||||
pub id: u32,
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Season {
|
||||
pub season_number: i32,
|
||||
pub monitored: bool,
|
||||
pub statistics: Option<SeasonStatistics>,
|
||||
pub images: Option<Vec<MediaCover>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AddSeriesOptions {
|
||||
pub ignore_episodes_with_files: bool,
|
||||
pub ignore_episodes_without_files: bool,
|
||||
pub monitor: String,
|
||||
pub search_for_missing_episodes: bool,
|
||||
pub search_for_cutoff_unmet_episodes: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Ratings {
|
||||
pub votes: i32,
|
||||
pub value: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SeriesStatistics {
|
||||
pub season_count: i32,
|
||||
pub episode_file_count: i32,
|
||||
pub episode_count: i32,
|
||||
pub total_episode_count: i32,
|
||||
pub size_on_disk: i64,
|
||||
pub release_groups: Option<Vec<String>>,
|
||||
pub percent_of_episodes: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SeasonStatistics {
|
||||
pub next_airing: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub previous_airing: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub episode_file_count: i32,
|
||||
pub episode_count: i32,
|
||||
pub total_episode_count: i32,
|
||||
pub size_on_disk: i64,
|
||||
pub release_groups: Option<Vec<String>>,
|
||||
pub percent_of_episodes: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Episode {
|
||||
pub id: u32,
|
||||
pub series_id: u32,
|
||||
pub tvdb_id: u32,
|
||||
pub episode_file_id: u32,
|
||||
pub season_number: i32,
|
||||
pub episode_number: i32,
|
||||
pub title: Option<String>,
|
||||
pub air_date: Option<String>,
|
||||
pub air_date_utc: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub last_search_time: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub runtime: i32,
|
||||
pub finale_type: Option<String>,
|
||||
pub overview: Option<String>,
|
||||
pub episode_file: Option<EpisodeFile>,
|
||||
pub has_file: bool,
|
||||
pub monitored: bool,
|
||||
pub absolute_episode_number: Option<i32>,
|
||||
pub scene_absolute_episode_number: Option<i32>,
|
||||
pub scene_episode_number: Option<i32>,
|
||||
pub scene_season_number: Option<i32>,
|
||||
pub unverified_scene_numbering: bool,
|
||||
pub end_time: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub grab_date: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub series: Option<Series>,
|
||||
pub images: Option<Vec<MediaCover>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpisodeFile {
|
||||
pub id: u32,
|
||||
pub series_id: u32,
|
||||
pub season_number: i32,
|
||||
pub relative_path: Option<String>,
|
||||
pub path: Option<String>,
|
||||
pub size: i64,
|
||||
pub date_added: chrono::DateTime<chrono::Utc>,
|
||||
pub scene_name: Option<String>,
|
||||
pub release_group: Option<String>,
|
||||
pub languages: Option<Vec<Language>>,
|
||||
pub quality: Option<Quality>,
|
||||
pub custom_formats: Option<Vec<CustomFormat>>,
|
||||
pub custom_format_score: i32,
|
||||
pub indexer_flags: Option<i32>,
|
||||
pub release_type: Option<String>,
|
||||
pub media_info: Option<MediaInfo>,
|
||||
pub quality_cutoff_not_met: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Quality {
|
||||
pub quality: QualityDefinition,
|
||||
pub revision: Revision,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct QualityDefinition {
|
||||
pub id: u32,
|
||||
pub name: Option<String>,
|
||||
pub source: String,
|
||||
pub resolution: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Revision {
|
||||
pub version: i32,
|
||||
pub real: i32,
|
||||
pub is_repack: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CustomFormat {
|
||||
pub id: u32,
|
||||
pub name: Option<String>,
|
||||
pub include_custom_format_when_renaming: Option<bool>,
|
||||
pub specifications: Option<Vec<HashMap<String, serde_json::Value>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MediaInfo {
|
||||
pub id: u32,
|
||||
pub audio_bitrate: i64,
|
||||
pub audio_channels: f64,
|
||||
pub audio_codec: Option<String>,
|
||||
pub audio_languages: Option<String>,
|
||||
pub audio_stream_count: i32,
|
||||
pub video_bit_depth: i32,
|
||||
pub video_bitrate: i64,
|
||||
pub video_codec: Option<String>,
|
||||
pub video_fps: f64,
|
||||
pub video_dynamic_range: Option<String>,
|
||||
pub video_dynamic_range_type: Option<String>,
|
||||
pub resolution: Option<String>,
|
||||
pub run_time: Option<String>,
|
||||
pub scan_type: Option<String>,
|
||||
pub subtitles: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct QueuePagingResource {
|
||||
pub page: i32,
|
||||
pub page_size: i32,
|
||||
pub sort_key: Option<String>,
|
||||
pub sort_direction: String,
|
||||
pub total_records: i32,
|
||||
pub records: Vec<QueueItem>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct QueueItem {
|
||||
pub id: u32,
|
||||
pub series_id: Option<u32>,
|
||||
pub episode_id: Option<u32>,
|
||||
pub season_number: Option<i32>,
|
||||
pub series: Option<Series>,
|
||||
pub episode: Option<Episode>,
|
||||
pub languages: Option<Vec<Language>>,
|
||||
pub quality: Option<Quality>,
|
||||
pub custom_formats: Option<Vec<CustomFormat>>,
|
||||
pub custom_format_score: i32,
|
||||
pub size: f64,
|
||||
pub title: Option<String>,
|
||||
pub estimated_completion_time: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub added: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub status: String,
|
||||
pub tracked_download_status: Option<String>,
|
||||
pub tracked_download_state: Option<String>,
|
||||
pub status_messages: Option<Vec<StatusMessage>>,
|
||||
pub error_message: Option<String>,
|
||||
pub download_id: Option<String>,
|
||||
pub protocol: String,
|
||||
pub download_client: Option<String>,
|
||||
pub download_client_has_post_import_category: bool,
|
||||
pub indexer: Option<String>,
|
||||
pub output_path: Option<String>,
|
||||
pub episode_has_file: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct StatusMessage {
|
||||
pub title: Option<String>,
|
||||
pub messages: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HistoryPagingResource {
|
||||
pub page: i32,
|
||||
pub page_size: i32,
|
||||
pub sort_key: Option<String>,
|
||||
pub sort_direction: String,
|
||||
pub total_records: i32,
|
||||
pub records: Vec<HistoryItem>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HistoryItem {
|
||||
pub id: u32,
|
||||
pub episode_id: u32,
|
||||
pub series_id: u32,
|
||||
pub source_title: Option<String>,
|
||||
pub languages: Option<Vec<Language>>,
|
||||
pub quality: Option<Quality>,
|
||||
pub custom_formats: Option<Vec<CustomFormat>>,
|
||||
pub custom_format_score: i32,
|
||||
pub quality_cutoff_not_met: bool,
|
||||
pub date: chrono::DateTime<chrono::Utc>,
|
||||
pub download_id: Option<String>,
|
||||
pub event_type: Option<String>,
|
||||
pub data: Option<HashMap<String, Option<String>>>,
|
||||
pub episode: Option<Episode>,
|
||||
pub series: Option<Series>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpisodePagingResource {
|
||||
pub page: i32,
|
||||
pub page_size: i32,
|
||||
pub sort_key: Option<String>,
|
||||
pub sort_direction: String,
|
||||
pub total_records: i32,
|
||||
pub records: Vec<Episode>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HealthResource {
|
||||
pub id: Option<i32>,
|
||||
pub source: Option<String>,
|
||||
#[serde(rename = "type")]
|
||||
pub health_type: String,
|
||||
pub message: Option<String>,
|
||||
pub wiki_url: Option<String>,
|
||||
}
|
||||
Reference in New Issue
Block a user