fix: Sonarr manual search TUI and CLI incorrectly displaying the same unfiltered results for both season and episode searches

This commit is contained in:
2026-01-15 12:43:16 -07:00
parent 8dfa664a06
commit 0ee275d58f
5 changed files with 125 additions and 43 deletions
@@ -2,16 +2,18 @@ use std::sync::Arc;
use anyhow::Result; use anyhow::Result;
use clap::Subcommand; use clap::Subcommand;
use serde_json::json;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use super::SonarrCommand;
use crate::models::Serdeable;
use crate::models::sonarr_models::{SonarrRelease, SonarrSerdeable};
use crate::{ use crate::{
app::App, app::App,
cli::{CliCommandHandler, Command}, cli::{CliCommandHandler, Command},
network::{NetworkTrait, sonarr_network::SonarrEvent}, network::{NetworkTrait, sonarr_network::SonarrEvent},
}; };
use super::SonarrCommand;
#[cfg(test)] #[cfg(test)]
#[path = "manual_search_command_handler_tests.rs"] #[path = "manual_search_command_handler_tests.rs"]
mod manual_search_command_handler_tests; mod manual_search_command_handler_tests;
@@ -28,7 +30,7 @@ pub enum SonarrManualSearchCommand {
episode_id: i64, episode_id: i64,
}, },
#[command( #[command(
about = "Trigger a manual search of releases for the given season corresponding to the series with the given ID.\nNote that when downloading a season release, ensure that the release includes 'fullSeason: true', otherwise you'll run into issues" about = "Trigger a manual search of releases for the given season corresponding to the series with the given ID"
)] )]
Season { Season {
#[arg( #[arg(
@@ -84,11 +86,21 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrManualSearchCommand>
season_number, season_number,
} => { } => {
println!("Searching for season releases. This may take a minute..."); println!("Searching for season releases. This may take a minute...");
let resp = self match self
.network .network
.handle_network_event(SonarrEvent::GetSeasonReleases((series_id, season_number)).into()) .handle_network_event(SonarrEvent::GetSeasonReleases((series_id, season_number)).into())
.await?; .await
serde_json::to_string_pretty(&resp)? {
Ok(Serdeable::Sonarr(SonarrSerdeable::Releases(releases_vec))) => {
let seasons_vec: Vec<SonarrRelease> = releases_vec
.into_iter()
.filter(|release| release.full_season)
.collect();
serde_json::to_string_pretty(&seasons_vec)?
}
Err(e) => return Err(e),
_ => serde_json::to_string_pretty(&json!({"message": "Failed to parse response"}))?,
}
} }
}; };
+1
View File
@@ -537,6 +537,7 @@ pub struct SonarrRelease {
pub quality: QualityWrapper, pub quality: QualityWrapper,
pub full_season: bool, pub full_season: bool,
} }
#[derive(Default, Serialize, Debug, PartialEq, Eq, Clone)] #[derive(Default, Serialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SonarrReleaseDownloadBody { pub struct SonarrReleaseDownloadBody {
@@ -370,6 +370,11 @@ impl Network<'_, '_> {
app.data.sonarr_data.season_details_modal = Some(SeasonDetailsModal::default()); app.data.sonarr_data.season_details_modal = Some(SeasonDetailsModal::default());
} }
let episode_releases_vec = release_vec
.into_iter()
.filter(|release| !release.full_season)
.collect();
if app if app
.data .data
.sonarr_data .sonarr_data
@@ -398,7 +403,7 @@ impl Network<'_, '_> {
.as_mut() .as_mut()
.unwrap() .unwrap()
.episode_releases .episode_releases
.set_items(release_vec); .set_items(episode_releases_vec);
}) })
.await .await
} }
@@ -4,7 +4,7 @@ mod tests {
use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock; use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock;
use crate::models::sonarr_models::{ use crate::models::sonarr_models::{
DownloadRecord, DownloadStatus, Episode, MonitorEpisodeBody, Season, Series, SonarrHistoryItem, DownloadRecord, DownloadStatus, Episode, MonitorEpisodeBody, Season, Series, SonarrHistoryItem,
SonarrHistoryWrapper, SonarrSerdeable, SonarrHistoryWrapper, SonarrRelease, SonarrSerdeable,
}; };
use crate::models::stateful_table::SortOption; use crate::models::stateful_table::SortOption;
use crate::network::NetworkResource; use crate::network::NetworkResource;
@@ -1067,21 +1067,53 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_handle_get_episode_releases_event() { async fn test_handle_get_episode_releases_event() {
let release_json = json!([{ let release_json = json!([
"guid": "1234", {
"protocol": "torrent", "guid": "1234",
"age": 1, "protocol": "torrent",
"title": "Test Release", "age": 1,
"indexer": "kickass torrents", "title": "Test Release",
"indexerId": 2, "indexer": "kickass torrents",
"size": 1234, "indexerId": 2,
"rejected": true, "size": 1234,
"rejections": [ "Unknown quality profile", "Release is already mapped" ], "rejected": true,
"seeders": 2, "rejections": [ "Unknown quality profile", "Release is already mapped" ],
"leechers": 1, "seeders": 2,
"languages": [ { "id": 1, "name": "English" } ], "leechers": 1,
"quality": { "quality": { "name": "Bluray-1080p" }} "languages": [ { "id": 1, "name": "English" } ],
}]); "quality": { "quality": { "name": "Bluray-1080p" }},
"fullSeason": true
},
{
"guid": "4567",
"protocol": "torrent",
"age": 1,
"title": "Test Release",
"indexer": "kickass torrents",
"indexerId": 2,
"size": 1234,
"rejected": true,
"rejections": [ "Unknown quality profile", "Release is already mapped" ],
"seeders": 2,
"leechers": 1,
"languages": [ { "id": 1, "name": "English" } ],
"quality": { "quality": { "name": "Bluray-1080p" }},
}
]);
let expected_filtered_sonarr_release = SonarrRelease {
guid: "4567".to_owned(),
..torrent_release()
};
let expected_raw_sonarr_releases = vec![
SonarrRelease {
full_season: true,
..torrent_release()
},
SonarrRelease {
guid: "4567".to_owned(),
..torrent_release()
},
];
let (async_server, app_arc, _server) = MockServarrApi::get() let (async_server, app_arc, _server) = MockServarrApi::get()
.returns(release_json) .returns(release_json)
.query("episodeId=1") .query("episodeId=1")
@@ -1124,28 +1156,60 @@ mod tests {
.unwrap() .unwrap()
.episode_releases .episode_releases
.items, .items,
vec![torrent_release()] vec![expected_filtered_sonarr_release]
); );
assert_eq!(releases_vec, vec![torrent_release()]); assert_eq!(releases_vec, expected_raw_sonarr_releases);
} }
#[tokio::test] #[tokio::test]
async fn test_handle_get_episode_releases_event_empty_episode_details_modal() { async fn test_handle_get_episode_releases_event_empty_episode_details_modal() {
let release_json = json!([{ let release_json = json!([
"guid": "1234", {
"protocol": "torrent", "guid": "1234",
"age": 1, "protocol": "torrent",
"title": "Test Release", "age": 1,
"indexer": "kickass torrents", "title": "Test Release",
"indexerId": 2, "indexer": "kickass torrents",
"size": 1234, "indexerId": 2,
"rejected": true, "size": 1234,
"rejections": [ "Unknown quality profile", "Release is already mapped" ], "rejected": true,
"seeders": 2, "rejections": [ "Unknown quality profile", "Release is already mapped" ],
"leechers": 1, "seeders": 2,
"languages": [ { "id": 1, "name": "English" } ], "leechers": 1,
"quality": { "quality": { "name": "Bluray-1080p" }} "languages": [ { "id": 1, "name": "English" } ],
}]); "quality": { "quality": { "name": "Bluray-1080p" }},
"fullSeason": true
},
{
"guid": "4567",
"protocol": "torrent",
"age": 1,
"title": "Test Release",
"indexer": "kickass torrents",
"indexerId": 2,
"size": 1234,
"rejected": true,
"rejections": [ "Unknown quality profile", "Release is already mapped" ],
"seeders": 2,
"leechers": 1,
"languages": [ { "id": 1, "name": "English" } ],
"quality": { "quality": { "name": "Bluray-1080p" }},
}
]);
let expected_filtered_sonarr_release = SonarrRelease {
guid: "4567".to_owned(),
..torrent_release()
};
let expected_raw_sonarr_releases = vec![
SonarrRelease {
full_season: true,
..torrent_release()
},
SonarrRelease {
guid: "4567".to_owned(),
..torrent_release()
},
];
let (async_server, app_arc, _server) = MockServarrApi::get() let (async_server, app_arc, _server) = MockServarrApi::get()
.returns(release_json) .returns(release_json)
.query("episodeId=1") .query("episodeId=1")
@@ -1179,9 +1243,9 @@ mod tests {
.unwrap() .unwrap()
.episode_releases .episode_releases
.items, .items,
vec![torrent_release()] vec![expected_filtered_sonarr_release]
); );
assert_eq!(releases_vec, vec![torrent_release()]); assert_eq!(releases_vec, expected_raw_sonarr_releases);
} }
#[tokio::test] #[tokio::test]
@@ -32,6 +32,6 @@ mod tests {
.await; .await;
mock.assert_async().await; mock.assert_async().await;
assert!(result.is_ok()); assert_ok!(result);
} }
} }