rs_plugin_common_interfaces/
lib.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use strum_macros::EnumString;
4
5pub use domain::{element_type::ElementType, external_images::{ExternalImage, ImageType}};
6pub use request::{RsRequest, RsCookie, RsCookies, RsRequestFiles, RsRequestPluginRequest, RsRequestStatus};
7pub use url::{RsLink, RsLinkType};
8pub use lookup::{RsLookupEpisode, RsLookupBook, RsLookupMovie, RsLookupMedia, RsLookupPerson, RsLookupSerie, RsLookupSerieSeason, RsLookupSong, RsLookupQuery, RsLookupSourceResult, RsLookupWrapper};
9
10pub use video::{RsAudio, RsResolution, RsVideoCodec, RsVideoFormat};
11
12#[cfg(feature = "rusqlite")]
13pub mod rusqlite;
14
15pub mod request;
16pub mod url;
17pub mod lookup;
18pub mod provider;
19
20pub mod video;
21
22pub mod domain;
23
24pub const INTERFACE_VERSION: u16 = 1;
25
26#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
27#[serde(rename_all = "camelCase")] 
28pub struct CustomParam {
29    pub name: String,
30    pub param: CustomParamTypes,
31    pub description: Option<String>,
32    #[serde(default)]
33    pub required: bool
34}
35
36
37
38#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
39#[serde(rename_all = "camelCase")] 
40pub struct PluginInformation {
41    pub name: String,
42    pub capabilities: Vec<PluginType>,
43    pub publisher: String,
44    pub description: String,
45    pub credential_kind: Option<CredentialType>,
46    pub repo: Option<String>,
47    pub oauth_url: Option<String>,
48    pub version: u16,
49    
50    #[serde(default)]
51    pub settings: Vec<CustomParam>,
52
53    pub interface_version: u16,
54}
55
56impl PluginInformation {
57    pub fn capabilities_tostring(&self) -> String {
58        self.capabilities.iter()
59        .map(|plugin| plugin.to_string())
60        .collect::<Vec<_>>()
61        .join(", ")
62    }
63}
64
65
66
67
68#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, strum_macros::Display,EnumString, Default)]
69#[serde(rename_all = "camelCase")] 
70#[strum(serialize_all = "camelCase")]
71pub enum PluginType {
72	ImageClassification,
73    UrlParser,
74    Request,
75    Lookup,
76    Provider,
77    #[default]
78    Other,
79}
80
81#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, strum_macros::Display,EnumString, Default)]
82#[serde(rename_all = "camelCase", tag = "type")] 
83#[strum(serialize_all = "camelCase")]
84pub enum CredentialType {
85	Url,
86	Password,
87    Oauth {
88        /// Oauth url to get code from user; use #redirecturi# in the url
89        url: String
90    },
91    #[default]
92    Token,
93}
94
95#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, strum_macros::Display,EnumString)]
96#[serde(rename_all = "camelCase")] 
97#[strum(serialize_all = "camelCase")]
98pub enum CustomParamTypes {
99	Text(Option<String>),
100    Url(Option<String>),
101    Integer(Option<i64>),
102    UInteger(Option<u64>),
103    Float(Option<f64>),
104}
105
106#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
107#[serde(rename_all = "camelCase")] 
108pub struct PluginCredential {
109    pub kind: CredentialType,
110    pub login: Option<String>,
111    pub password: Option<String>,
112    pub settings: Value,
113    pub user_ref: Option<String>,
114    pub refresh_token: Option<String>,
115    pub expires: Option<i64>,
116}
117
118#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, strum_macros::Display,EnumString, Default)]
119#[strum(serialize_all = "camelCase")]
120#[serde(rename_all = "camelCase")]
121pub enum RsFileType {
122    Directory,
123    Photo,
124    Video,
125    Archive,
126    Album,
127    #[default]
128    Other
129}
130
131#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, strum_macros::Display, EnumString, Default)]
132#[serde(rename_all = "camelCase")] 
133#[strum(serialize_all = "camelCase")]
134pub enum MediaType {
135	Movie,
136	Episode,
137    Book,
138    Song,
139    #[strum(default)]
140    Custom(String),
141    #[default]
142    Unknown,
143}
144
145#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, strum_macros::Display, EnumString, Default)]
146#[serde(rename_all = "camelCase")] 
147#[strum(serialize_all = "camelCase")]
148pub enum Gender {
149	Male,
150	Female,
151    Animal,
152    Other,
153    #[strum(default)]
154    Custom(String),
155    #[default]
156    Unknown,
157}
158
159
160
161#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
162#[serde(rename_all = "camelCase")] 
163pub struct RsPluginRequest<T> {
164    pub request: T,
165    pub plugin_settings: Value,
166    pub credential: Option<PluginCredential>
167}
168
169
170
171
172#[cfg(test)]
173mod tests {
174    use std::str::FromStr;
175
176    use super::*;
177
178    #[test]
179    fn resolution_parsing() {
180        assert_eq!(RsResolution::from_filename("Test.2024.S01E01.1080p.VOSTFR.DSNP.WEB-DL.DDP5.1.H.264"), RsResolution::FullHD);
181        assert_eq!(RsResolution::from_filename("Test.2024.S01E01_720p VOSTFR.DSNP.WEB-DL.DDP5.1.H.264"), RsResolution::HD);  
182        assert_eq!(RsResolution::from_filename("TestIn4k.2024.S01E01_VOSTFR.DSNP.WEB-DL.DDP5.1.H.264"), RsResolution::Unknown);
183        assert_eq!(RsResolution::from_filename("TestIn4k.2024.S01E01_4K_VOSTFR.DSNP.WEB-DL.DDP5.Atmos.1.H.264"), RsResolution::UHD);
184    }
185
186
187    #[test]
188    fn resolution_string() {
189        assert_eq!("4K", RsResolution::UHD.to_string());
190        assert_eq!(RsResolution::from_str("1080p").unwrap(), RsResolution::FullHD);
191        assert_eq!(RsResolution::from_str("erzr").unwrap(), RsResolution::Custom("erzr".to_owned()));
192    }
193    #[test]
194    fn audio_parsing() {
195        assert_eq!(RsAudio::from_filename("Test.2024.S01E01.1080p.VOSTFR.DSNP.WEB-DL.DDP5.1.H.264"), RsAudio::DDP51);
196        assert_eq!(RsAudio::from_filename("Test.2024.S01E01_720p VOSTFR.DSNP.WEB-DL.DDP5.1._atmos_H.264"), RsAudio::Atmos);  
197        let list = RsAudio::list_from_filename("TestIn4k.2024.S01E01_4K_VOSTFR.DSNP.WEB-DL.DDP5.1.Atmos.H.264");
198        assert_eq!(list.len(), 2);
199        assert!(list.contains(&RsAudio::Atmos));
200        assert!(list.contains(&RsAudio::DDP51));
201    }
202
203    #[test]
204    fn videocodec_parsing() {
205        assert_eq!(RsVideoCodec::from_filename("Test.2024.S01E01.1080p.VOSTFR.DSNP.WEB-DL.DDP5.1.H.264"), RsVideoCodec::H264);
206        assert_eq!(RsVideoCodec::from_filename("Test.2024.S01E01_720p VOSTFR.DSNP.WEB-DL.DDP5.1.HEVC"), RsVideoCodec::H265);  
207        assert_eq!(RsVideoCodec::from_filename("TestIn4k.2024.S01E01_VOSTFR.DSNP.WEB-DL.DDP5.1.X.265"), RsVideoCodec::H265);
208        
209    }
210
211    #[test]
212    fn video_format_parsing() {
213        assert_eq!(RsVideoFormat::from_filename("Test.2024.S01E01.1080p.VOSTFR.DSNP.WEB-DL.DDP5.1.H.264.mp4"), RsVideoFormat::Mp4);
214        assert_eq!(RsVideoFormat::from_filename("Test.2024.S01E01_720p VOSTFR.DSNP.WEB-DL.DDP5.1._atmos_H.264"), RsVideoFormat::Other);  
215        assert_eq!(RsVideoFormat::from_filename("Test.2024.S01E01.1080p.VOSTFR.DSNP.WEB-DL.DDP5.1.H.264.WMV"), RsVideoFormat::Wmv);
216        
217        assert_eq!(RsVideoFormat::Mp4.to_string(), "mp4");
218        assert_eq!(RsVideoFormat::from_str("mkv").unwrap(), RsVideoFormat::Mkv);
219    }
220}