Skip to content

Commit

Permalink
[minor] Added Minimum Availability options for Radarr in configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Feramance committed Aug 16, 2023
1 parent 0e958a1 commit 0d2ae85
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
26 changes: 21 additions & 5 deletions qBitrr/arss.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def __init__(
self.quality_unmet_search = CONFIG.get(
f"{name}.EntrySearch.QualityUnmetSearch", fallback=False
)
self.minimum_availability = CONFIG.get(
f"{name}.EntrySearch.MinimumAvailability", fallback=3
)

self.ignore_torrents_younger_than = CONFIG.get(
f"{name}.Torrent.IgnoreTorrentsYoungerThan", fallback=600
Expand Down Expand Up @@ -634,6 +637,10 @@ def _get_oversee_requests_all(self) -> dict[str, set]:
self.logger.warning("Couldn't connect to Overseerr")
self._temp_overseer_request_cache = defaultdict(set)
return self._temp_overseer_request_cache
except requests.exceptions.ReadTimeout:
self.logger.warning("Connection to Overseerr timed out")
self._temp_overseer_request_cache = defaultdict(set)
return self._temp_overseer_request_cache
except Exception as e:
self.logger.exception(e, exc_info=sys.exc_info())
self._temp_overseer_request_cache = defaultdict(set)
Expand Down Expand Up @@ -1245,6 +1252,7 @@ def _db_request_update(self, request_ids: dict[str, set[int | str]]):
self.model_arr_movies_file: MoviesMetadataModel
condition = self.model_arr_movies_file.Year <= datetime.now().year
condition &= self.model_arr_movies_file.Year > 0
condition &= self.model_arr_file.MinimumAvailability == self.minimum_availability
tmdb_con = None
imdb_con = None
if ImdbIds := request_ids.get("ImdbId"):
Expand All @@ -1257,12 +1265,15 @@ def _db_request_update(self, request_ids: dict[str, set[int | str]]):
condition &= tmdb_con
elif imdb_con:
condition &= imdb_con

for db_entry in (
self.model_arr_file.select(self.model_arr_file)
self.model_arr_file.select()
.join(
self.model_arr_movies_file,
on=(self.model_arr_file.MovieMetadataId == self.model_arr_movies_file.Id),
join_type=JOIN.LEFT_OUTER,
)
.switch(self.model_arr_file)
.where(condition)
.order_by(self.model_arr_file.Added.desc())
):
Expand Down Expand Up @@ -1352,7 +1363,11 @@ def db_update(self):
self.model_arr_movies_file,
on=(self.model_arr_file.MovieMetadataId == self.model_arr_movies_file.Id),
)
.where(self.model_arr_movies_file.Year == self.search_current_year)
.where(
self.model_arr_movies_file.Year
== self.search_current_year & self.model_arr_file.MinimumAvailability
== self.minimum_availability
)
.order_by(self.model_arr_file.Added.desc())
):
self.db_update_single_series(db_entry=movies)
Expand All @@ -1371,7 +1386,7 @@ def db_update_single_series(
if self.type == "sonarr":
if not series:
db_entry: EpisodesModel
QualityUnmet = True
QualityUnmet = self.quality_unmet_search
if db_entry.EpisodeFileId != 0 and not QualityUnmet:
searched = True
self.model_queue.update(Completed=True).where(
Expand Down Expand Up @@ -1479,7 +1494,7 @@ def db_update_single_series(
elif self.type == "radarr":
db_entry: MoviesModel
searched = False
QualityUnmet = True
QualityUnmet = self.quality_unmet_search
if db_entry.MovieFileId != 0 and not QualityUnmet:
searched = True
self.model_queue.update(Completed=True).where(
Expand All @@ -1489,6 +1504,7 @@ def db_update_single_series(
metadata = self.model_arr_movies_file.get(
self.model_arr_movies_file.Id == db_entry.MovieMetadataId
)
metadata: MoviesMetadataModel

title = metadata.Title
monitored = db_entry.Monitored
Expand Down Expand Up @@ -1624,7 +1640,7 @@ def remove_and_maybe_blocklist(self, downloads_id: str | None, file_or_folder: p

if file_or_folder.is_dir():
try:
shutil.rmtree(file_or_folder)
shutil.rmtree(file_or_folder, ignore_errors=True)
self.logger.debug(
"Folder removed: Folder was marked as failed by Arr, "
"manually removing it | %s",
Expand Down
7 changes: 7 additions & 0 deletions qBitrr/gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,13 @@ def _gen_default_search_table(category: str, cat_default: Table):
search_table.add(comment("Do a quality unmet search for existing entries."))
search_table.add("QualityUnmetSearch", False)
search_table.add(nl())
search_table.add(
comment(
"Choose Minimum Availability for Radarr Instances. (Cinema=1, Digital=2, Physical=3)"
)
)
search_table.add("MinimumAvailability", 3)
search_table.add(nl())
search_table.add(
comment(
"Once you have search all files on your specified year range restart the loop and "
Expand Down

0 comments on commit 0d2ae85

Please sign in to comment.