Skip to main content

rs_plugin_common_interfaces/domain/
library_stats.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5use super::embedding::MediaEmbeddingCounts;
6use super::library::{LibraryEncryptionStatus, LibraryStorage};
7
8/// What a library holds and what is left to process (`GET /libraries/{id}/stats`).
9#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
10#[serde(rename_all = "camelCase")]
11pub struct LibraryStats {
12    pub medias: LibraryMediaStats,
13    /// Left out for virtual libraries and when the provider cannot tell.
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub storage: Option<LibraryStorage>,
16    pub entities: LibraryEntityCounts,
17    pub duplicates: LibraryDuplicates,
18    pub processing: LibraryProcessing,
19    /// Left out until a backup of the library has completed.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub last_backup: Option<LibraryLastBackup>,
22    pub server: LibraryServerFootprint,
23}
24
25#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
26#[serde(rename_all = "camelCase")]
27pub struct LibraryMediaTypeStats {
28    pub count: u64,
29    /// Bytes.
30    pub size: u64,
31    /// Seconds. Left out when no media of the type has a duration.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub duration: Option<u64>,
34}
35
36#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
37#[serde(rename_all = "camelCase")]
38pub struct LibraryMediaStats {
39    pub count: u64,
40    pub size: u64,
41    /// Keyed by media type (`photo`, `video`...): only the types the library holds.
42    pub by_type: BTreeMap<String, LibraryMediaTypeStats>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub first_created: Option<i64>,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub last_created: Option<i64>,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub last_added: Option<i64>,
49}
50
51/// Rows of each entity table.
52#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
53#[serde(rename_all = "camelCase")]
54pub struct LibraryEntityCounts {
55    pub movies: u64,
56    pub series: u64,
57    /// Episodes known from metadata, with a file or not.
58    pub episodes: u64,
59    pub people: u64,
60    pub tags: u64,
61    pub books: u64,
62    pub channels: u64,
63}
64
65/// Medias with the same content hash.
66#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
67#[serde(rename_all = "camelCase")]
68pub struct LibraryDuplicates {
69    /// Contents stored as more than one media.
70    pub groups: u64,
71    /// Medias beyond the first of each group.
72    pub extra_medias: u64,
73    /// Bytes those extra medias take.
74    pub extra_size: u64,
75}
76
77#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
78#[serde(rename_all = "camelCase")]
79pub struct LibraryFaceCounts {
80    /// Medias the face scan has still to process.
81    pub pending: u64,
82    /// Medias the face scan failed on: it does not try them again.
83    pub failed: u64,
84    /// Faces found but not attached to a person yet.
85    pub unassigned: u64,
86}
87
88#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
89#[serde(rename_all = "camelCase")]
90pub struct LibraryProcessing {
91    pub faces: LibraryFaceCounts,
92    pub embeddings: MediaEmbeddingCounts,
93    pub encryption: LibraryEncryptionStatus,
94}
95
96#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
97#[serde(rename_all = "camelCase")]
98pub struct LibraryLastBackup {
99    pub id: String,
100    pub name: String,
101    /// When it last completed (ms).
102    pub date: i64,
103    /// Bytes the backup holds at its destination, every kept version included.
104    pub size: u64,
105}
106
107/// What Redseat itself stores for the library, in bytes.
108#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
109#[serde(rename_all = "camelCase")]
110pub struct LibraryServerFootprint {
111    /// Library database, write-ahead log included.
112    pub database_size: u64,
113    /// Data folder: thumbnails, portraits, faces and caches.
114    pub data_size: u64,
115}