aboutsummaryrefslogtreecommitdiff
path: root/common/src/lib.rs
blob: fd69d8fa737dac7f5c712cddd0d75c0aaec036b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
pub mod api;
pub mod r#impl;

use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
use std::{
    collections::BTreeMap,
    ops::{Deref, DerefMut},
    path::PathBuf,
};

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CommmonInfo {
    pub title: String,
    #[serde(default)]
    pub tagline: Option<String>,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub poster: Option<PathBuf>,
    #[serde(default)]
    pub backdrop: Option<PathBuf>,
    #[serde(default)]
    pub index: Option<usize>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DirectoryInfo {
    #[serde(flatten)]
    pub common: CommmonInfo,
    #[serde(default)]
    pub kind: DirectoryKind,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ItemInfo {
    #[serde(flatten)]
    pub common: CommmonInfo,
    pub duration: f64, // in seconds
    pub tracks: BTreeMap<usize, SourceTrack>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum DirectoryKind {
    Folder,
    Series,
    Show,
    Season,
}
impl Default for DirectoryKind {
    fn default() -> Self {
        Self::Folder
    }
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SourceTrack {
    pub path: PathBuf,
    pub track_number: u64,
    pub kind: SourceTrackKind,
    pub name: String,
    pub codec: String,
    pub language: String,
    pub default_duration: Option<u64>,
    pub codec_private: Option<Vec<u8>>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum SourceTrackKind {
    Video {
        width: u64,
        height: u64,
        fps: f64,
    },
    Audio {
        channels: usize,
        sample_rate: f64,
        bit_depth: usize,
    },
    Subtitles,
}

#[derive(Debug, Clone, Decode, Encode)]
pub struct SeekIndex {
    pub blocks: Vec<BlockIndex>,
}

#[derive(Debug, Clone, Decode, Encode)]
pub struct BlockIndex {
    pub pts: u64,
    pub source_off: usize,
    pub size: usize,
}

impl Deref for ItemInfo {
    type Target = CommmonInfo;
    fn deref(&self) -> &Self::Target {
        &self.common
    }
}
impl Deref for DirectoryInfo {
    type Target = CommmonInfo;
    fn deref(&self) -> &Self::Target {
        &self.common
    }
}
impl DerefMut for ItemInfo {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.common
    }
}
impl DerefMut for DirectoryInfo {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.common
    }
}