Skip to content

Commit

Permalink
[minor] Upgrade search overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
Feramance committed Nov 15, 2023
1 parent 8fe20da commit 60874c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
32 changes: 26 additions & 6 deletions qBitrr/arss.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ def db_reset__series_searched_state(self):
if (
self.loop_completed and self.reset_on_completion and self.series_search
): # Only wipe if a loop completed was tagged
self.series_file_model.update(Searched=False).where(
self.series_file_model.update(Searched=False, Upgrade=False).where(
self.series_file_model.Searched == True
).execute()
Ids = [id.Id for id in self.model_arr_series_file.select().execute()]
Expand All @@ -1177,7 +1177,7 @@ def db_reset__episode_searched_state(self):
if (
self.loop_completed is True and self.reset_on_completion
): # Only wipe if a loop completed was tagged
self.model_file.update(Searched=False).where(
self.model_file.update(Searched=False, Upgrade=False).where(
self.model_file.Searched == True
).execute()
Ids = [id.Id for id in self.model_arr_file.select().execute()]
Expand All @@ -1188,7 +1188,7 @@ def db_reset__movie_searched_state(self):
if (
self.loop_completed is True and self.reset_on_completion
): # Only wipe if a loop completed was tagged
self.model_file.update(Searched=False).where(
self.model_file.update(Searched=False, Upgrade=False).where(
self.model_file.Searched == True
).execute()
Ids = [id.Id for id in self.model_arr_file.select().execute()]
Expand All @@ -1203,11 +1203,13 @@ def db_get_files_series(
yield None, False, False
elif self.type == "sonarr":
condition = self.model_file.AirDateUtc.is_null(False)
condition &= self.model_file.Searched == False
if not self.search_specials:
condition &= self.model_file.SeasonNumber != 0
if not self.do_upgrade_search:
condition &= self.model_file.Searched == False
condition &= self.model_file.EpisodeFileId == 0
else:
condition &= self.model_file.Upgrade == False
condition &= self.model_file.AirDateUtc < (
datetime.now(timezone.utc) - timedelta(hours=2)
)
Expand All @@ -1232,15 +1234,17 @@ def db_get_files_episodes(
yield None, False, False
elif self.type == "sonarr":
condition = self.model_file.AirDateUtc.is_null(False)
condition &= self.model_file.Searched == False
if not self.search_specials:
condition &= self.model_file.SeasonNumber != 0
condition &= self.model_file.AirDateUtc.is_null(False)
if not self.do_upgrade_search:
if self.quality_unmet_search:
condition &= self.model_file.QualityMet == False
else:
condition &= self.model_file.Searched == False
condition &= self.model_file.EpisodeFileId == 0
else:
condition &= self.model_file.Upgrade == False
condition &= self.model_file.AirDateUtc < (
datetime.now(timezone.utc) - timedelta(hours=2)
)
Expand Down Expand Up @@ -1288,20 +1292,26 @@ def db_get_files_movies(
if not self.search_missing:
yield None, False, False
if self.type == "radarr":
condition = self.model_file.Searched == False
condition = self.model_file.Year.is_null(False)
if self.search_by_year:
condition &= self.model_file.Year == self.search_current_year
if not self.do_upgrade_search:
if self.quality_unmet_search:
condition &= self.model_file.QualityMet == False
else:
condition &= self.model_file.MovieFileId == 0
condition &= self.model_file.Searched == False
else:
condition &= self.model_file.Upgrade == False
else:
if not self.do_upgrade_search:
if self.quality_unmet_search:
condition &= self.model_file.QualityMet == False
else:
condition &= self.model_file.MovieFileId == 0
condition &= self.model_file.Searched == False
else:
condition &= self.model_file.Upgrade == False
for entry in (
self.model_file.select()
.where(condition)
Expand All @@ -1322,6 +1332,8 @@ def db_get_request_files(self) -> Iterable[MoviesFilesModel | EpisodeFilesModel]
condition &= self.model_file.QualityMet == False
else:
condition &= self.model_file.EpisodeFileId == 0
else:
condition &= self.model_file.Upgrade == False
if not self.search_specials:
condition &= self.model_file.SeasonNumber != 0
condition &= self.model_file.AbsoluteEpisodeNumber.is_null(
Expand Down Expand Up @@ -1350,6 +1362,8 @@ def db_get_request_files(self) -> Iterable[MoviesFilesModel | EpisodeFilesModel]
else:
condition &= self.model_file.MovieFileId == 0
condition &= self.model_file.IsRequest == True
else:
condition &= self.model_file.Upgrade == False
yield from (
self.model_file.select()
.where(condition)
Expand Down Expand Up @@ -1925,6 +1939,7 @@ def db_update_single_series(
Searched=searched,
IsRequest=request,
QualityMet=QualityMet,
Upgrade=False,
).on_conflict(
conflict_target=[self.model_file.EntryId],
update=to_update,
Expand Down Expand Up @@ -1975,6 +1990,7 @@ def db_update_single_series(
Title=Title,
Searched=searched,
Monitored=Monitored,
Upgrade=False,
).on_conflict(
conflict_target=[self.series_file_model.EntryId],
update=to_update,
Expand Down Expand Up @@ -2036,6 +2052,7 @@ def db_update_single_series(
MovieFileId=movieFileId,
IsRequest=request,
QualityMet=qualityMet,
Upgrade=False,
).on_conflict(
conflict_target=[self.model_file.EntryId],
update=to_update,
Expand Down Expand Up @@ -2284,6 +2301,7 @@ def maybe_do_search(
):
completed = True
file_model.Searched = True
file_model.Upgrade = True
file_model.save()
self.logger.hnotice(
"%sSearching for: %s | S%02dE%03d | %s | [id=%s|AirDateUTC=%s]",
Expand Down Expand Up @@ -2334,6 +2352,7 @@ def maybe_do_search(
):
completed = True
file_model.Searched = True
file_model.Upgrade = True
file_model.save()
self.logger.hnotice(
"%sSearching for: %s | %s | [id=%s]",
Expand Down Expand Up @@ -2398,6 +2417,7 @@ def maybe_do_search(
):
completed = True
file_model.Searched = True
file_model.Upgrade = True
file_model.save()
self.logger.hnotice(
"%sSearching for: %s (%s) [tmdbId=%s|id=%s]",
Expand Down
3 changes: 3 additions & 0 deletions qBitrr/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MoviesFilesModel(Model):
MovieFileId = IntegerField()
IsRequest = BooleanField(default=False)
QualityMet = BooleanField(default=False)
Upgrade = BooleanField(default=False)


class EpisodeFilesModel(Model):
Expand All @@ -33,13 +34,15 @@ class EpisodeFilesModel(Model):
Searched = BooleanField(default=False)
IsRequest = BooleanField(default=False)
QualityMet = BooleanField(default=False)
Upgrade = BooleanField(default=False)


class SeriesFilesModel(Model):
EntryId = IntegerField(primary_key=True)
Title = TextField(null=True)
Monitored = BooleanField(null=True)
Searched = BooleanField(default=False)
Upgrade = BooleanField(default=False)


class MovieQueueModel(Model):
Expand Down

0 comments on commit 60874c3

Please sign in to comment.