feat(network): Added get quality profiles and get episode details events for Sonarr

This commit is contained in:
2024-11-15 18:19:03 -07:00
parent 1fe95d057b
commit e14b7072c6
11 changed files with 941 additions and 27 deletions
+1
View File
@@ -1 +1,2 @@
pub mod modals;
pub mod sonarr_data;
+13
View File
@@ -0,0 +1,13 @@
use crate::models::ScrollableText;
#[derive(Default)]
pub struct EpisodeDetailsModal {
pub episode_details: ScrollableText,
pub file_details: String,
pub audio_details: String,
pub video_details: String,
// pub episode_history: StatefulTable<MovieHistoryItem>,
// pub episode_cast: StatefulTable<Credit>,
// pub episode_crew: StatefulTable<Credit>,
// pub episode_releases: StatefulTable<Release>,
}
+17 -3
View File
@@ -1,14 +1,17 @@
use bimap::BiMap;
use chrono::{DateTime, Utc};
use strum::EnumIter;
use crate::models::{
sonarr_models::{BlocklistItem, Episode, Series},
sonarr_models::{BlocklistItem, DownloadRecord, Episode, Series},
stateful_list::StatefulList,
stateful_table::StatefulTable,
stateful_tree::StatefulTree,
HorizontallyScrollableText, Route,
};
use super::modals::EpisodeDetailsModal;
#[cfg(test)]
#[path = "sonarr_data_tests.rs"]
mod sonarr_data_tests;
@@ -19,7 +22,11 @@ pub struct SonarrData {
pub series: StatefulTable<Series>,
pub blocklist: StatefulTable<BlocklistItem>,
pub logs: StatefulList<HorizontallyScrollableText>,
pub episodes: StatefulTree<Episode>,
pub episodes_tree: StatefulTree<Episode>,
pub episodes_table: StatefulTable<Episode>,
pub downloads: StatefulTable<DownloadRecord>,
pub episode_details_modal: Option<EpisodeDetailsModal>,
pub quality_profile_map: BiMap<i64, String>,
}
impl Default for SonarrData {
@@ -30,7 +37,11 @@ impl Default for SonarrData {
series: StatefulTable::default(),
blocklist: StatefulTable::default(),
logs: StatefulList::default(),
episodes: StatefulTree::default(),
episodes_tree: StatefulTree::default(),
episodes_table: StatefulTable::default(),
downloads: StatefulTable::default(),
episode_details_modal: None,
quality_profile_map: BiMap::new(),
}
}
}
@@ -39,6 +50,9 @@ impl Default for SonarrData {
pub enum ActiveSonarrBlock {
Blocklist,
BlocklistSortPrompt,
EpisodesExplorer,
EpisodesTable,
EpisodesTableSortPrompt,
#[default]
Series,
SeriesSortPrompt,
@@ -39,6 +39,11 @@ mod tests {
assert!(sonarr_data.series.is_empty());
assert!(sonarr_data.blocklist.is_empty());
assert!(sonarr_data.logs.is_empty());
assert!(sonarr_data.episodes_tree.is_empty());
assert!(sonarr_data.episodes_table.is_empty());
assert!(sonarr_data.downloads.is_empty());
assert!(sonarr_data.episode_details_modal.is_none());
assert!(sonarr_data.quality_profile_map.is_empty());
}
}
}
+71 -3
View File
@@ -37,6 +37,25 @@ pub struct BlocklistResponse {
pub records: Vec<BlocklistItem>,
}
#[derive(Derivative, Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct DownloadRecord {
pub title: String,
pub status: String,
#[serde(deserialize_with = "super::from_i64")]
pub id: i64,
#[serde(deserialize_with = "super::from_i64")]
pub episode_id: i64,
#[serde(deserialize_with = "super::from_i64")]
pub size: i64,
#[serde(deserialize_with = "super::from_i64")]
pub sizeleft: i64,
pub output_path: Option<HorizontallyScrollableText>,
#[serde(default)]
pub indexer: String,
pub download_client: String,
}
#[derive(Default, Serialize, Deserialize, Hash, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Episode {
@@ -57,6 +76,7 @@ pub struct Episode {
pub overview: Option<String>,
pub has_file: bool,
pub monitored: bool,
pub episode_file: Option<EpisodeFile>,
}
impl Display for Episode {
@@ -65,7 +85,19 @@ impl Display for Episode {
}
}
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[derive(Default, Serialize, Deserialize, Hash, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EpisodeFile {
pub relative_path: String,
pub path: String,
#[serde(deserialize_with = "super::from_i64")]
pub size: i64,
pub language: Language,
pub date_added: DateTime<Utc>,
pub media_info: Option<MediaInfo>,
}
#[derive(Serialize, Deserialize, Default, Debug, Hash, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct Language {
pub name: String,
}
@@ -87,16 +119,48 @@ pub struct LogResponse {
pub records: Vec<Log>,
}
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[derive(Serialize, Deserialize, Derivative, Hash, Debug, Clone, PartialEq, Eq)]
#[derivative(Default)]
#[serde(rename_all = "camelCase")]
pub struct MediaInfo {
#[serde(deserialize_with = "super::from_i64")]
pub audio_bitrate: i64,
#[derivative(Default(value = "Number::from(0)"))]
pub audio_channels: Number,
pub audio_codec: Option<String>,
pub audio_languages: Option<String>,
#[serde(deserialize_with = "super::from_i64")]
pub audio_stream_count: i64,
#[serde(deserialize_with = "super::from_i64")]
pub video_bit_depth: i64,
#[serde(deserialize_with = "super::from_i64")]
pub video_bitrate: i64,
pub video_codec: String,
#[derivative(Default(value = "Number::from(0)"))]
pub video_fps: Number,
pub resolution: String,
pub run_time: String,
pub scan_type: String,
pub subtitles: Option<String>,
}
#[derive(Serialize, Deserialize, Default, Debug, Hash, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct Quality {
pub name: String,
}
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[derive(Serialize, Deserialize, Default, Debug, Hash, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct QualityWrapper {
pub quality: Quality,
}
#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct QualityProfile {
#[serde(deserialize_with = "super::from_i64")]
pub id: i64,
pub name: String,
}
#[derive(Derivative, Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derivative(Default)]
pub struct Rating {
@@ -257,7 +321,9 @@ impl SeriesStatus {
#[allow(clippy::large_enum_variant)]
pub enum SonarrSerdeable {
Value(Value),
Episode(Episode),
Episodes(Vec<Episode>),
QualityProfiles(Vec<QualityProfile>),
SeriesVec(Vec<Series>),
SystemStatus(SystemStatus),
BlocklistResponse(BlocklistResponse),
@@ -279,7 +345,9 @@ impl From<()> for SonarrSerdeable {
serde_enum_from!(
SonarrSerdeable {
Value(Value),
Episode(Episode),
Episodes(Vec<Episode>),
QualityProfiles(Vec<QualityProfile>),
SeriesVec(Vec<Series>),
SystemStatus(SystemStatus),
BlocklistResponse(BlocklistResponse),
+29 -2
View File
@@ -5,8 +5,8 @@ mod tests {
use crate::models::{
sonarr_models::{
BlocklistItem, BlocklistResponse, Episode, Log, LogResponse, Series, SeriesStatus,
SeriesType, SonarrSerdeable, SystemStatus,
BlocklistItem, BlocklistResponse, Episode, Log, LogResponse, QualityProfile, Series,
SeriesStatus, SeriesType, SonarrSerdeable, SystemStatus,
},
Serdeable,
};
@@ -77,6 +77,18 @@ mod tests {
assert_eq!(sonarr_serdeable, SonarrSerdeable::Value(value));
}
#[test]
fn test_sonarr_serdeable_from_episode() {
let episode = Episode {
id: 1,
..Episode::default()
};
let sonarr_serdeable: SonarrSerdeable = episode.clone().into();
assert_eq!(sonarr_serdeable, SonarrSerdeable::Episode(episode));
}
#[test]
fn test_sonarr_serdeable_from_episodes() {
let episodes = vec![Episode {
@@ -146,4 +158,19 @@ mod tests {
assert_eq!(sonarr_serdeable, SonarrSerdeable::LogResponse(log_response));
}
#[test]
fn test_sonarr_serdeable_from_quality_profiles() {
let quality_profiles = vec![QualityProfile {
name: "Test Profile".to_owned(),
id: 1,
}];
let sonarr_serdeable: SonarrSerdeable = quality_profiles.clone().into();
assert_eq!(
sonarr_serdeable,
SonarrSerdeable::QualityProfiles(quality_profiles)
);
}
}