Skip to content

Commit

Permalink
Slight tweaks to availability indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Jul 1, 2024
1 parent dbf0b93 commit 0c63853
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
47 changes: 24 additions & 23 deletions conreq/core/arrs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion conreq/core/arrs/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions conreq/core/arrs/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
2 changes: 1 addition & 1 deletion conreq/core/tmdb/templates/modal/content_preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@

</div>
</div>
</div
</div
6 changes: 3 additions & 3 deletions conreq/core/tmdb/templates/viewport/more_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@

<!-- Availability -->
<div class="quick-info-block availability">
<div class="quick-info bold"> Availabity </div>
<div class="quick-info bold"> Availability </div>
<div class="quick-info">
{% if content.availability == "Available" %} Available
<div class="inline-availablity-dot green"> </div>
{% elif content.availability == "Partial" %} Partial
{% elif content.availability == "Partial" %} Partially available or monitored
<div class="inline-availablity-dot yellow"> </div>
{% else %} Not Downloaded
<div class="inline-availablity-dot red"> </div>
Expand Down Expand Up @@ -455,4 +455,4 @@
<img src="{% static 'images/transparent.png' %}" data-src="{% firstof content.backdrop_path content.backdropPath %}"
class="more-info-backdrop lazy" alt="">
<div class="backdrop-placeholder-gradient"></div>
</div>
</div>

0 comments on commit 0c63853

Please sign in to comment.