rs-plugin-common-interfaces 0.49.2

Common description for plugin creation
Documentation
use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use super::embedding::MediaEmbeddingCounts;
use super::library::{LibraryEncryptionStatus, LibraryStorage};

/// What a library holds and what is left to process (`GET /libraries/{id}/stats`).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryStats {
    pub medias: LibraryMediaStats,
    /// Left out for virtual libraries and when the provider cannot tell.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub storage: Option<LibraryStorage>,
    pub entities: LibraryEntityCounts,
    pub duplicates: LibraryDuplicates,
    pub processing: LibraryProcessing,
    /// Left out until a backup of the library has completed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_backup: Option<LibraryLastBackup>,
    pub server: LibraryServerFootprint,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryMediaTypeStats {
    pub count: u64,
    /// Bytes.
    pub size: u64,
    /// Seconds. Left out when no media of the type has a duration.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<u64>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryMediaStats {
    pub count: u64,
    pub size: u64,
    /// Keyed by media type (`photo`, `video`...): only the types the library holds.
    pub by_type: BTreeMap<String, LibraryMediaTypeStats>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub first_created: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_created: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_added: Option<i64>,
}

/// Rows of each entity table.
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryEntityCounts {
    pub movies: u64,
    pub series: u64,
    /// Episodes known from metadata, with a file or not.
    pub episodes: u64,
    pub people: u64,
    pub tags: u64,
    pub books: u64,
    pub channels: u64,
}

/// Medias with the same content hash.
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryDuplicates {
    /// Contents stored as more than one media.
    pub groups: u64,
    /// Medias beyond the first of each group.
    pub extra_medias: u64,
    /// Bytes those extra medias take.
    pub extra_size: u64,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryFaceCounts {
    /// Medias the face scan has still to process.
    pub pending: u64,
    /// Medias the face scan failed on: it does not try them again.
    pub failed: u64,
    /// Faces found but not attached to a person yet.
    pub unassigned: u64,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryProcessing {
    pub faces: LibraryFaceCounts,
    pub embeddings: MediaEmbeddingCounts,
    pub encryption: LibraryEncryptionStatus,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryLastBackup {
    pub id: String,
    pub name: String,
    /// When it last completed (ms).
    pub date: i64,
    /// Bytes the backup holds at its destination, every kept version included.
    pub size: u64,
}

/// What Redseat itself stores for the library, in bytes.
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct LibraryServerFootprint {
    /// Library database, write-ahead log included.
    pub database_size: u64,
    /// Data folder: thumbnails, portraits, faces and caches.
    pub data_size: u64,
}