@@ -23,43 +23,44 @@ def _set_content_attributes(content_type, content_source, results):
2323 results ["content_source" ] = content_source
2424
2525 @staticmethod
26- def _check_availability (content : dict ):
27- """Checks the availability of one item. For use within check_availability()"""
26+ def _determine_availability (content : dict ):
27+ """Checks the availability of one item using fuzzy logic."""
28+ # TODO: Rewrite this into separate methods for Sonarr season, Sonarr series, Radarr movie, etc.
2829 statistics : dict = content .get ("statistics" ) or content or {}
2930 percent_available : int | None = statistics .get ("percentOfEpisodes" )
30- grabbed : bool | None = statistics .get ("grabbed " )
31+ monitored : bool | None = statistics .get ("monitored" ) or content . get ( "monitored " )
3132
3233 ##### "Unavailable" #####
33- # Sonarr/Radarr: Check if an individual movie or episode does not exist
34- if "hasFile" in content and not content [ "hasFile" ] :
34+ # Sonarr/Radarr: Check if an individual movie or episode does not exist and isn't monitored
35+ if content . get ( "hasFile" ) is False and not monitored :
3536 content ["availability" ] = "Unavailable"
36- return content
37+ return
3738 # Sonarr: Check if a season or series is completely unavailable
38- if statistics and percent_available == 0 :
39+ if percent_available == 0 and not monitored :
3940 content ["availability" ] = "Unavailable"
40- return content
41-
42- ##### "Partial" #####
43- # Sonarr: Check if season or series is partially downloaded
44- if statistics and percent_available and percent_available < 100 :
45- content ["availability" ] = "Partial"
46- return content
47- # Radarr: Check if a movie is being downloaded.
48- if grabbed is True and statistics .get ("movieFileCount" ) == 0 :
49- content ["availability" ] = "Partial"
50- return content
41+ return
5142
5243 ##### "Available" #####
5344 # Sonarr: Check if a season or series is fully downloaded
54- if statistics and percent_available == 100 :
45+ if percent_available == 100 :
5546 content ["availability" ] = "Available"
56- return content
47+ return
5748 # Sonarr/Radarr: Check if an individual movie or individual episode exists
58- if "hasFile" in content and content [ "hasFile" ] :
49+ if content . get ( "hasFile" ) :
5950 content ["availability" ] = "Available"
60- return content
51+ return
52+
53+ ##### "Partial" #####
54+ # Sonarr: Check if season or series is partially downloaded
55+ if percent_available and percent_available < 100 :
56+ content ["availability" ] = "Partial"
57+ return
58+ # Sonarr/Radarr: Check if a content is being monitored.
59+ if monitored :
60+ content ["availability" ] = "Partial"
61+ return
6162
6263 ##### "Unknown" #####
6364 # This should never be reached except with Sonarr/Raddarr API changes
6465 content ["availability" ] = "Unknown"
65- return content
66+ return
0 commit comments