diff --git a/conreq/core/arrs/base.py b/conreq/core/arrs/base.py index 91020308..c2752364 100644 --- a/conreq/core/arrs/base.py +++ b/conreq/core/arrs/base.py @@ -23,43 +23,44 @@ def _set_content_attributes(content_type, content_source, results): results["content_source"] = content_source @staticmethod - def _check_availability(content: dict): - """Checks the availability of one item. For use within check_availability()""" + def _determine_availability(content: dict): + """Checks the availability of one item using fuzzy logic.""" + # TODO: Rewrite this into separate methods for Sonarr season, Sonarr series, Radarr movie, etc. statistics: dict = content.get("statistics") or content or {} percent_available: int | None = statistics.get("percentOfEpisodes") - grabbed: bool | None = statistics.get("grabbed") + monitored: bool | None = statistics.get("monitored") or content.get("monitored") ##### "Unavailable" ##### - # Sonarr/Radarr: Check if an individual movie or episode does not exist - if "hasFile" in content and not content["hasFile"]: + # Sonarr/Radarr: Check if an individual movie or episode does not exist and isn't monitored + if content.get("hasFile") is False and not monitored: content["availability"] = "Unavailable" - return content + return # Sonarr: Check if a season or series is completely unavailable - if statistics and percent_available == 0: + if percent_available == 0 and not monitored: content["availability"] = "Unavailable" - return content - - ##### "Partial" ##### - # Sonarr: Check if season or series is partially downloaded - if statistics and percent_available and percent_available < 100: - content["availability"] = "Partial" - return content - # Radarr: Check if a movie is being downloaded. - if grabbed is True and statistics.get("movieFileCount") == 0: - content["availability"] = "Partial" - return content + return ##### "Available" ##### # Sonarr: Check if a season or series is fully downloaded - if statistics and percent_available == 100: + if percent_available == 100: content["availability"] = "Available" - return content + return # Sonarr/Radarr: Check if an individual movie or individual episode exists - if "hasFile" in content and content["hasFile"]: + if content.get("hasFile"): content["availability"] = "Available" - return content + return + + ##### "Partial" ##### + # Sonarr: Check if season or series is partially downloaded + if percent_available and percent_available < 100: + content["availability"] = "Partial" + return + # Sonarr/Radarr: Check if a content is being monitored. + if monitored: + content["availability"] = "Partial" + return ##### "Unknown" ##### # This should never be reached except with Sonarr/Raddarr API changes content["availability"] = "Unknown" - return content + return diff --git a/conreq/core/arrs/radarr.py b/conreq/core/arrs/radarr.py index d1ed53cf..ad41b2e7 100644 --- a/conreq/core/arrs/radarr.py +++ b/conreq/core/arrs/radarr.py @@ -286,7 +286,7 @@ def get_radarr_library(self) -> dict | None: results_with_ids = {} for movie in results: if "tmdbId" in movie: - self._check_availability(movie) + self._determine_availability(movie) self._set_content_attributes("movie", "radarr", movie) results_with_ids[str(movie["tmdbId"])] = movie diff --git a/conreq/core/arrs/sonarr.py b/conreq/core/arrs/sonarr.py index 478057ee..5023c621 100644 --- a/conreq/core/arrs/sonarr.py +++ b/conreq/core/arrs/sonarr.py @@ -409,7 +409,7 @@ def get_sonarr_library(self) -> dict | None: results_with_ids = {} for series in results: if "tvdbId" in series: - self._check_availability(series) + self._determine_availability(series) self._set_content_attributes("tv", "sonarr", series) results_with_ids[str(series["tvdbId"])] = series @@ -436,11 +436,11 @@ def _season_episode_availability(self, series) -> None: episodes = self.__sonarr.get_episodes_by_series_id(series["id"]) for season in series["seasons"]: # Set the season availability - self._check_availability(season["statistics"]) + self._determine_availability(season["statistics"]) # Set the episode availability season["episodes"] = [] for episode in episodes: if episode["seasonNumber"] == season["seasonNumber"]: - self._check_availability(episode) + self._determine_availability(episode) season["episodes"].append(episode) diff --git a/conreq/core/tmdb/templates/modal/content_preview.html b/conreq/core/tmdb/templates/modal/content_preview.html index cd70ff02..7cc0a50f 100644 --- a/conreq/core/tmdb/templates/modal/content_preview.html +++ b/conreq/core/tmdb/templates/modal/content_preview.html @@ -124,4 +124,4 @@ -
-
Availabity
+
Availability
{% if content.availability == "Available" %} Available
- {% elif content.availability == "Partial" %} Partial + {% elif content.availability == "Partial" %} Partially available or monitored
{% else %} Not Downloaded
@@ -455,4 +455,4 @@
-
\ No newline at end of file +