Skip to content

Commit

Permalink
Use correct count for already downloaded episodes
Browse files Browse the repository at this point in the history
Unlike expected, the `episodeCount` of Sonarr also includes
episodes that are aired and monitored. Use `episodeFileCount`
instead.
  • Loading branch information
p-hueber committed Dec 1, 2024
1 parent 0e0b0eb commit 72a6a0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## Fixed

- Use the correct episode count from Sonarr to not consider monitored episodes
as downloaded.


## [0.8.1] - 2024-10-31

## Fixed
Expand Down
24 changes: 18 additions & 6 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Actor {
let is_only_episode = season
.statistics
.as_ref()
.is_some_and(|s| s.episode_count == 1);
.is_some_and(|s| s.episode_file_count == 1);
let is_end_of_season = np.episode
> season
.last_episode()
Expand Down Expand Up @@ -118,7 +118,7 @@ impl Actor {
}

if let Some(statistics) = &next_season.statistics {
if statistics.episode_count == statistics.total_episode_count {
if statistics.episode_file_count == statistics.total_episode_count {
debug!(num = next_season_num, "skip already downloaded season");
return Ok(());
}
Expand Down Expand Up @@ -168,6 +168,7 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 8,
"episodeFileCount": 8,
"totalEpisodeCount": 8,
}
},{
Expand All @@ -176,6 +177,7 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 0,
"episodeFileCount": 0,
"totalEpisodeCount": 8,
}
}]
Expand All @@ -202,6 +204,7 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 8,
"episodeFileCount": 8,
"totalEpisodeCount": 8,
}
},{
Expand All @@ -210,6 +213,7 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 0,
"episodeFileCount": 0,
"totalEpisodeCount": 8,
}
}]
Expand Down Expand Up @@ -278,14 +282,16 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 8,
"episodeFileCount": 8,
"totalEpisodeCount": 8,
}
},{
"seasonNumber": 2,
"monitored": false,
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 0,
"episodeCount": 8,
"episodeFileCount": 0,
"totalEpisodeCount": 8,
}
}]
Expand All @@ -312,14 +318,16 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 8,
"episodeFileCount": 8,
"totalEpisodeCount": 8,
}
},{
"seasonNumber": 2,
"monitored": true,
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 0,
"episodeCount": 8,
"episodeFileCount": 0,
"totalEpisodeCount": 8,
}
}]
Expand Down Expand Up @@ -468,6 +476,7 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 8,
"episodeFileCount": 8,
"totalEpisodeCount": 8,
}
}]
Expand All @@ -494,6 +503,7 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 8,
"episodeFileCount": 8,
"totalEpisodeCount": 8,
}
}]
Expand Down Expand Up @@ -547,7 +557,8 @@ mod test {
"monitored": true,
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 1,
"episodeCount": 8,
"episodeFileCount": 1,
"totalEpisodeCount": 8,
}
}]
Expand All @@ -573,7 +584,8 @@ mod test {
"monitored": true,
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 1,
"episodeCount": 8,
"episodeFileCount": 1,
"totalEpisodeCount": 8,
}
}]
Expand Down
3 changes: 3 additions & 0 deletions src/sonarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl Client {
pub struct SeasonStatisticsResource {
pub size_on_disk: i64,
pub episode_count: i32,
pub episode_file_count: i32,
pub total_episode_count: i32,
#[serde(flatten)]
other: serde_json::Value,
Expand Down Expand Up @@ -414,6 +415,7 @@ mod test {
statistics: SeasonStatisticsResource {
size_on_disk: 9000,
episode_count: 8,
episode_file_count: 8,
total_episode_count: 0,
other: Value::Null,
}
Expand Down Expand Up @@ -461,6 +463,7 @@ mod test {
"statistics": {
"sizeOnDisk": 9000,
"episodeCount": 8,
"episodeFileCount": 8,
"totalEpisodeCount": 0,
}
}]
Expand Down

0 comments on commit 72a6a0c

Please sign in to comment.