From d5c6810ada03b8b48f6671aa5e115e3188d4536d Mon Sep 17 00:00:00 2001 From: Feramance Date: Wed, 16 Oct 2024 13:26:32 +0200 Subject: [PATCH 01/16] Temporarily removed catch statement for testing --- .github/workflows/Dependabot Auto-approve.yml | 23 ------- .github/workflows/branch_nightly.yml | 69 ------------------- qBitrr/arss.py | 28 ++++---- 3 files changed, 14 insertions(+), 106 deletions(-) delete mode 100644 .github/workflows/Dependabot Auto-approve.yml delete mode 100644 .github/workflows/branch_nightly.yml diff --git a/.github/workflows/Dependabot Auto-approve.yml b/.github/workflows/Dependabot Auto-approve.yml deleted file mode 100644 index af2dbacb..00000000 --- a/.github/workflows/Dependabot Auto-approve.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Dependabot Auto-approve -on: pull_request_target - -permissions: - contents: write - pull-requests: write - -jobs: - dependabot: - runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} - steps: - - name: Dependabot metadata - id: metadata - uses: dependabot/fetch-metadata@v2.2.0 - with: - github-token: ${{ secrets.PAT }} - - name: Enable auto-merge for Dependabot PRs - if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} - run: gh pr merge --auto --merge "$PR_URL" - env: - PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{secrets.PAT}} diff --git a/.github/workflows/branch_nightly.yml b/.github/workflows/branch_nightly.yml deleted file mode 100644 index 17a8b558..00000000 --- a/.github/workflows/branch_nightly.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Branch Nightly - -on: - push: - branches: - - '*' - - '!master' - -defaults: - run: - shell: bash - -env: - project-name: qBitrr - -jobs: - docker_image: - name: Build Docker Image - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - if: ${{ ! startsWith(github.event.head_commit.message, '[patch]') && ! startsWith(github.event.head_commit.message, '[minor]') && ! startsWith(github.event.head_commit.message, '[major]') }} - steps: - - id: string - uses: ASzc/change-string-case-action@v6 - with: - string: ${{ github.repository }} - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.ref_name }} - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to Container registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.REG_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: | - feramance/qbitrr - ghcr.io/${{ steps.string.outputs.lowercase }} - tags: | - type=ref,event=branch - - name: Build and push Docker images - env: - DOCKER_BUILDKIT: 1 - uses: docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/qBitrr/arss.py b/qBitrr/arss.py index a547dd75..88856878 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -5304,20 +5304,20 @@ def build_arr_instances(self): call_cls = RadarrAPI else: call_cls = None - try: - managed_object = Arr(name, self, client_cls=call_cls) - self.groups.add(name) - self.uris.add(managed_object.uri) - self.managed_objects[managed_object.category] = managed_object - self.arr_categories.add(managed_object.category) - except KeyError as e: - self.logger.critical(e) - except ValueError as e: - self.logger.exception(e) - except SkipException: - continue - except (OSError, TypeError) as e: - self.logger.exception(e) + # try: + managed_object = Arr(name, self, client_cls=call_cls) + self.groups.add(name) + self.uris.add(managed_object.uri) + self.managed_objects[managed_object.category] = managed_object + self.arr_categories.add(managed_object.category) + # except KeyError as e: + # self.logger.critical(e) + # except ValueError as e: + # self.logger.exception(e) + # except SkipException: + # continue + # except (OSError, TypeError) as e: + # self.logger.exception(e) if FREE_SPACE != "-1" and AUTO_PAUSE_RESUME: managed_object = FreeSpaceManager(self.arr_categories, self) self.managed_objects["FreeSpaceManager"] = managed_object From 385cb7f6de88e4f09698cf350e768abb55d69897 Mon Sep 17 00:00:00 2001 From: Feramance Date: Wed, 16 Oct 2024 15:29:42 +0200 Subject: [PATCH 02/16] Updated category check logic --- qBitrr/arss.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 88856878..af6ae038 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -107,8 +107,8 @@ def __init__( self.logger.addHandler(fh) run_logs(self.logger) categories = self.manager.qbit_manager.client.torrent_categories.categories - categ = categories[self.category] - if categ: + try: + categ = categories[self.category] path = categ["savePath"] if path: self.logger.trace("Category exists with save path [%s]", path) @@ -118,9 +118,11 @@ def __init__( self.completed_folder = pathlib.Path(COMPLETED_DOWNLOAD_FOLDER).joinpath( self.category ) - else: - self.manager.qbit_manager.client.torrent_categories.createCategory(self.category) + except KeyError: self.completed_folder = pathlib.Path(COMPLETED_DOWNLOAD_FOLDER).joinpath(self.category) + self.manager.qbit_manager.client.torrent_categories.create_category( + self.category, save_path=self.completed_folder + ) if not self.completed_folder.exists() and not SEARCH_ONLY: try: self.completed_folder.mkdir(parents=True, exist_ok=True) @@ -5304,20 +5306,20 @@ def build_arr_instances(self): call_cls = RadarrAPI else: call_cls = None - # try: - managed_object = Arr(name, self, client_cls=call_cls) - self.groups.add(name) - self.uris.add(managed_object.uri) - self.managed_objects[managed_object.category] = managed_object - self.arr_categories.add(managed_object.category) - # except KeyError as e: - # self.logger.critical(e) - # except ValueError as e: - # self.logger.exception(e) - # except SkipException: - # continue - # except (OSError, TypeError) as e: - # self.logger.exception(e) + try: + managed_object = Arr(name, self, client_cls=call_cls) + self.groups.add(name) + self.uris.add(managed_object.uri) + self.managed_objects[managed_object.category] = managed_object + self.arr_categories.add(managed_object.category) + except KeyError as e: + self.logger.critical("Key Error: %s", e) + except ValueError as e: + self.logger.exception("Value Error: %s", e) + except SkipException: + continue + except (OSError, TypeError) as e: + self.logger.exception(e) if FREE_SPACE != "-1" and AUTO_PAUSE_RESUME: managed_object = FreeSpaceManager(self.arr_categories, self) self.managed_objects["FreeSpaceManager"] = managed_object From c0085f6ae431a276c51e074cfadefb453a517fa3 Mon Sep 17 00:00:00 2001 From: Feramance Date: Wed, 16 Oct 2024 16:53:56 +0200 Subject: [PATCH 03/16] Adjust code --- qBitrr/arss.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index af6ae038..98d9787e 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -5306,20 +5306,20 @@ def build_arr_instances(self): call_cls = RadarrAPI else: call_cls = None - try: - managed_object = Arr(name, self, client_cls=call_cls) - self.groups.add(name) - self.uris.add(managed_object.uri) - self.managed_objects[managed_object.category] = managed_object - self.arr_categories.add(managed_object.category) - except KeyError as e: - self.logger.critical("Key Error: %s", e) - except ValueError as e: - self.logger.exception("Value Error: %s", e) - except SkipException: - continue - except (OSError, TypeError) as e: - self.logger.exception(e) + # try: + managed_object = Arr(name, self, client_cls=call_cls) + self.groups.add(name) + self.uris.add(managed_object.uri) + self.managed_objects[managed_object.category] = managed_object + self.arr_categories.add(managed_object.category) + # except KeyError as e: + # self.logger.critical("Key Error: %s", e) + # except ValueError as e: + # self.logger.exception("Value Error: %s", e) + # except SkipException: + # continue + # except (OSError, TypeError) as e: + # self.logger.exception(e) if FREE_SPACE != "-1" and AUTO_PAUSE_RESUME: managed_object = FreeSpaceManager(self.arr_categories, self) self.managed_objects["FreeSpaceManager"] = managed_object From d724b19d5d77117418c763a426bc604f50e64f60 Mon Sep 17 00:00:00 2001 From: Feramance Date: Thu, 17 Oct 2024 10:02:25 +0200 Subject: [PATCH 04/16] Re-add exception handling --- qBitrr/arss.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 98d9787e..cfe22d69 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -5306,20 +5306,18 @@ def build_arr_instances(self): call_cls = RadarrAPI else: call_cls = None - # try: - managed_object = Arr(name, self, client_cls=call_cls) - self.groups.add(name) - self.uris.add(managed_object.uri) - self.managed_objects[managed_object.category] = managed_object - self.arr_categories.add(managed_object.category) - # except KeyError as e: - # self.logger.critical("Key Error: %s", e) - # except ValueError as e: - # self.logger.exception("Value Error: %s", e) - # except SkipException: - # continue - # except (OSError, TypeError) as e: - # self.logger.exception(e) + try: + managed_object = Arr(name, self, client_cls=call_cls) + self.groups.add(name) + self.uris.add(managed_object.uri) + self.managed_objects[managed_object.category] = managed_object + self.arr_categories.add(managed_object.category) + except ValueError as e: + self.logger.exception("Value Error: %s", e) + except SkipException: + continue + except (OSError, TypeError) as e: + self.logger.exception(e) if FREE_SPACE != "-1" and AUTO_PAUSE_RESUME: managed_object = FreeSpaceManager(self.arr_categories, self) self.managed_objects["FreeSpaceManager"] = managed_object From dcb860624f96a7355c085c0781d4eb7f2cd09cae Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 14:20:32 +0100 Subject: [PATCH 05/16] Search logs --- qBitrr/arss.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index cfe22d69..4a5954ef 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1457,6 +1457,7 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None ) for i1, i2, i3 in self._search_todays(condition): if i1 is not None: + self.logger.trace("Adding %s to search list", i1.Title) entries.append([i1, i2, i3]) if not self.do_upgrade_search: condition = self.series_file_model.Searched is False @@ -1468,6 +1469,7 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None .order_by(self.series_file_model.EntryId.asc()) .execute() ): + self.logger.trace("Adding %s to search list", entry_.Title) entries.append([entry_, False, False]) return entries @@ -1533,9 +1535,11 @@ def db_get_files_episodes(self) -> list[list[EpisodeFilesModel, bool, bool]] | N .order_by(self.model_file.EpisodeFileId.asc()) .execute() ): + self.logger.trace("Adding %s to search list", entry.Title) entries.append([entry, False, False]) for i1, i2, i3 in self._search_todays(today_condition): if i1 is not None: + self.logger.trace("Adding %s to search list", i1.Title) entries.append([i1, i2, i3]) return entries @@ -1576,6 +1580,7 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None .order_by(self.model_file.MovieFileId.asc()) .execute() ): + self.logger.trace("Adding %s to search list", entry.Title) entries.append([entry, False, False]) return entries From 00709f1f2b3ac30534f6e894bf44b8935cb57ecb Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 14:35:55 +0100 Subject: [PATCH 06/16] Removing yield test --- qBitrr/arss.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 4a5954ef..0f71f9d9 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1300,21 +1300,25 @@ def _search_todays(self, condition): def db_get_files( self, - ) -> Iterable[ - tuple[MoviesFilesModel | EpisodeFilesModel | SeriesFilesModel, bool, bool, bool, int] - ]: + ) -> list[list[MoviesFilesModel | EpisodeFilesModel | SeriesFilesModel, bool, bool, bool, int]] | None: + entries = [] + self.logger.trace("Getting files to search") if self.type == "sonarr" and self.series_search: serieslist = self.db_get_files_series() for series in serieslist: - yield series[0], series[1], series[2], series[2] is not True, len(serieslist) + entries.append([series[0], series[1], series[2], series[2] is not True, len(serieslist)]) + # yield series[0], series[1], series[2], series[2] is not True, len(serieslist) elif self.type == "sonarr" and not self.series_search: episodelist = self.db_get_files_episodes() for episodes in episodelist: - yield episodes[0], episodes[1], episodes[2], False, len(episodelist) + entries.append([episodes[0], episodes[1], episodes[2], False, len(episodelist)]) + # yield episodes[0], episodes[1], episodes[2], False, len(episodelist) elif self.type == "radarr": movielist = self.db_get_files_movies() for movies in movielist: - yield movies[0], movies[1], movies[2], False, len(movielist) + entries.append([movies[0], movies[1], movies[2], False, len(movielist)]) + # yield movies[0], movies[1], movies[2], False, len(movielist) + return entries def db_maybe_reset_entry_searched_state(self): if self.type == "sonarr": @@ -4744,7 +4748,7 @@ def run_search_loop(self) -> NoReturn: commands, ) in self.db_get_files(): if totcommands == -1: - totcommands = commands + totcommands = entry[4] self.logger.info("Starting search for %s items", totcommands) if SEARCH_LOOP_DELAY == -1: loop_delay = 30 @@ -4752,10 +4756,10 @@ def run_search_loop(self) -> NoReturn: loop_delay = SEARCH_LOOP_DELAY while ( self.maybe_do_search( - entry, - todays=todays, - bypass_limit=limit_bypass, - series_search=series_search, + entry[0], + todays=entry[1], + bypass_limit=entry[2], + series_search=entry[3], commands=totcommands, ) ) is False: From 05107e9335490890dbc52443e7c968e03bacc37b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:36:13 +0000 Subject: [PATCH 07/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qBitrr/arss.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 0f71f9d9..75a13fd1 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1300,13 +1300,18 @@ def _search_todays(self, condition): def db_get_files( self, - ) -> list[list[MoviesFilesModel | EpisodeFilesModel | SeriesFilesModel, bool, bool, bool, int]] | None: + ) -> ( + list[list[MoviesFilesModel | EpisodeFilesModel | SeriesFilesModel, bool, bool, bool, int]] + | None + ): entries = [] self.logger.trace("Getting files to search") if self.type == "sonarr" and self.series_search: serieslist = self.db_get_files_series() for series in serieslist: - entries.append([series[0], series[1], series[2], series[2] is not True, len(serieslist)]) + entries.append( + [series[0], series[1], series[2], series[2] is not True, len(serieslist)] + ) # yield series[0], series[1], series[2], series[2] is not True, len(serieslist) elif self.type == "sonarr" and not self.series_search: episodelist = self.db_get_files_episodes() From 0e1db8cb294823dd1e1f93061dd72b4077eec4f0 Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 14:47:56 +0100 Subject: [PATCH 08/16] More logging --- qBitrr/arss.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 0f71f9d9..b9ac9028 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1318,6 +1318,7 @@ def db_get_files( for movies in movielist: entries.append([movies[0], movies[1], movies[2], False, len(movielist)]) # yield movies[0], movies[1], movies[2], False, len(movielist) + self.logger.trace("Returning %s entries", len(entries) if entries else 0) return entries def db_maybe_reset_entry_searched_state(self): From 8680a61e34c8b06d1fab148c22aa12e7305e221c Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 14:56:17 +0100 Subject: [PATCH 09/16] More logging --- qBitrr/arss.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 6976bbc5..60007024 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1560,19 +1560,23 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None if self.type == "radarr": condition = self.model_file.Year.is_null(False) if self.do_upgrade_search: + self.logger.trace("Condition 1") condition &= self.model_file.Upgrade is False else: if self.quality_unmet_search and not self.custom_format_unmet_search: + self.logger.trace("Condition 2") condition &= ( self.model_file.Searched == False | self.model_file.QualityMet is False ) elif not self.quality_unmet_search and self.custom_format_unmet_search: + self.logger.trace("Condition 3") condition &= ( self.model_file.Searched == False | self.model_file.CustomFormatMet is False ) elif self.quality_unmet_search and self.custom_format_unmet_search: + self.logger.trace("Condition 4") condition &= ( self.model_file.Searched == False | self.model_file.QualityMet @@ -1580,9 +1584,11 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None is False ) else: + self.logger.trace("Condition 5") condition &= self.model_file.MovieFileId == 0 condition &= self.model_file.Searched is False if self.search_by_year: + self.logger.trace("Condition 6") condition &= self.model_file.Year == self.search_current_year for entry in ( self.model_file.select() From b8055ae7e1985117ccb679b2f7245e8bc96eeab3 Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 15:01:53 +0100 Subject: [PATCH 10/16] Remove file id check --- qBitrr/arss.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 60007024..adebef2e 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1444,7 +1444,6 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None is False ) else: - condition &= self.model_file.EpisodeFileId == 0 condition &= self.model_file.Searched is False todays_condition = copy(condition) todays_condition &= self.model_file.AirDateUtc > ( @@ -1512,7 +1511,6 @@ def db_get_files_episodes(self) -> list[list[EpisodeFilesModel, bool, bool]] | N is False ) else: - condition &= self.model_file.EpisodeFileId == 0 condition &= self.model_file.Searched is False today_condition = copy(condition) today_condition &= self.model_file.AirDateUtc > ( @@ -1585,7 +1583,6 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None ) else: self.logger.trace("Condition 5") - condition &= self.model_file.MovieFileId == 0 condition &= self.model_file.Searched is False if self.search_by_year: self.logger.trace("Condition 6") From 6a2ef445fa279bd0028f35b37065abdda1514fdb Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 15:29:24 +0100 Subject: [PATCH 11/16] Query logic update --- qBitrr/arss.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index adebef2e..22137dc5 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1472,12 +1472,13 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None condition = self.series_file_model.Searched is False else: condition = self.series_file_model.Upgrade is False - for entry_ in ( + query = ( self.series_file_model.select() .where(condition) .order_by(self.series_file_model.EntryId.asc()) .execute() - ): + ) + for entry_ in query: self.logger.trace("Adding %s to search list", entry_.Title) entries.append([entry_, False, False]) return entries @@ -1531,7 +1532,7 @@ def db_get_files_episodes(self) -> list[list[EpisodeFilesModel, bool, bool]] | N self.model_file.AirDateUtc <= datetime(month=12, day=31, year=int(self.search_current_year)).date() ) - for entry in ( + query = ( self.model_file.select() .where(condition) .order_by( @@ -1542,7 +1543,8 @@ def db_get_files_episodes(self) -> list[list[EpisodeFilesModel, bool, bool]] | N .group_by(self.model_file.SeriesId) .order_by(self.model_file.EpisodeFileId.asc()) .execute() - ): + ) + for entry in query: self.logger.trace("Adding %s to search list", entry.Title) entries.append([entry, False, False]) for i1, i2, i3 in self._search_todays(today_condition): @@ -1587,12 +1589,11 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None if self.search_by_year: self.logger.trace("Condition 6") condition &= self.model_file.Year == self.search_current_year - for entry in ( - self.model_file.select() + query = (self.model_file.select() .where(condition) .order_by(self.model_file.MovieFileId.asc()) - .execute() - ): + .execute()) + for entry in query: self.logger.trace("Adding %s to search list", entry.Title) entries.append([entry, False, False]) return entries From 08171b26509fac1d71bb374c02b19f97287a2bb7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:29:38 +0000 Subject: [PATCH 12/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qBitrr/arss.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 22137dc5..392a905c 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1589,10 +1589,12 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None if self.search_by_year: self.logger.trace("Condition 6") condition &= self.model_file.Year == self.search_current_year - query = (self.model_file.select() + query = ( + self.model_file.select() .where(condition) .order_by(self.model_file.MovieFileId.asc()) - .execute()) + .execute() + ) for entry in query: self.logger.trace("Adding %s to search list", entry.Title) entries.append([entry, False, False]) From ca6fc4295d284eb86b30ba513cb74063d7ef91d6 Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 16:25:10 +0100 Subject: [PATCH 13/16] Adjusted boolean checks --- qBitrr/arss.py | 76 +++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 392a905c..cd8c6b30 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1424,27 +1424,27 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None if not self.search_specials: condition &= self.model_file.SeasonNumber != 0 if self.do_upgrade_search: - condition &= self.model_file.Upgrade is False + condition &= self.model_file.Upgrade == False else: if self.quality_unmet_search and not self.custom_format_unmet_search: condition &= ( - self.model_file.Searched == False | self.model_file.QualityMet is False + self.model_file.Searched == False | self.model_file.QualityMet == False ) elif not self.quality_unmet_search and self.custom_format_unmet_search: condition &= ( self.model_file.Searched == False | self.model_file.CustomFormatMet - is False + == False ) elif self.quality_unmet_search and self.custom_format_unmet_search: condition &= ( self.model_file.Searched == False | self.model_file.QualityMet == False | self.model_file.CustomFormatMet - is False + == False ) else: - condition &= self.model_file.Searched is False + condition &= self.model_file.Searched == False todays_condition = copy(condition) todays_condition &= self.model_file.AirDateUtc > ( datetime.now(timezone.utc) - timedelta(days=1) @@ -1469,9 +1469,9 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None self.logger.trace("Adding %s to search list", i1.Title) entries.append([i1, i2, i3]) if not self.do_upgrade_search: - condition = self.series_file_model.Searched is False + condition = self.series_file_model.Searched == False else: - condition = self.series_file_model.Upgrade is False + condition = self.series_file_model.Upgrade == False query = ( self.series_file_model.select() .where(condition) @@ -1492,27 +1492,27 @@ def db_get_files_episodes(self) -> list[list[EpisodeFilesModel, bool, bool]] | N if not self.search_specials: condition &= self.model_file.SeasonNumber != 0 if self.do_upgrade_search: - condition &= self.model_file.Upgrade is False + condition &= self.model_file.Upgrade == False else: if self.quality_unmet_search and not self.custom_format_unmet_search: condition &= ( - self.model_file.Searched == False | self.model_file.QualityMet is False + self.model_file.Searched == False | self.model_file.QualityMet == False ) elif not self.quality_unmet_search and self.custom_format_unmet_search: condition &= ( self.model_file.Searched == False | self.model_file.CustomFormatMet - is False + == False ) elif self.quality_unmet_search and self.custom_format_unmet_search: condition &= ( self.model_file.Searched == False | self.model_file.QualityMet == False | self.model_file.CustomFormatMet - is False + == False ) else: - condition &= self.model_file.Searched is False + condition &= self.model_file.Searched == False today_condition = copy(condition) today_condition &= self.model_file.AirDateUtc > ( datetime.now(timezone.utc) - timedelta(days=1) @@ -1561,19 +1561,19 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None condition = self.model_file.Year.is_null(False) if self.do_upgrade_search: self.logger.trace("Condition 1") - condition &= self.model_file.Upgrade is False + condition &= self.model_file.Upgrade == False else: if self.quality_unmet_search and not self.custom_format_unmet_search: self.logger.trace("Condition 2") condition &= ( - self.model_file.Searched == False | self.model_file.QualityMet is False + self.model_file.Searched == False | self.model_file.QualityMet == False ) elif not self.quality_unmet_search and self.custom_format_unmet_search: self.logger.trace("Condition 3") condition &= ( self.model_file.Searched == False | self.model_file.CustomFormatMet - is False + == False ) elif self.quality_unmet_search and self.custom_format_unmet_search: self.logger.trace("Condition 4") @@ -1581,11 +1581,11 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None self.model_file.Searched == False | self.model_file.QualityMet == False | self.model_file.CustomFormatMet - is False + == False ) else: self.logger.trace("Condition 5") - condition &= self.model_file.Searched is False + condition &= self.model_file.Searched == False if self.search_by_year: self.logger.trace("Condition 6") condition &= self.model_file.Year == self.search_current_year @@ -1608,28 +1608,28 @@ def db_get_request_files(self) -> Iterable[MoviesFilesModel | EpisodeFilesModel] elif self.type == "sonarr": condition = self.model_file.IsRequest is True if self.do_upgrade_search: - condition &= self.model_file.Upgrade is False + condition &= self.model_file.Upgrade == False else: if self.quality_unmet_search and not self.custom_format_unmet_search: condition &= ( - self.model_file.Searched == False | self.model_file.QualityMet is False + self.model_file.Searched == False | self.model_file.QualityMet == False ) elif not self.quality_unmet_search and self.custom_format_unmet_search: condition &= ( self.model_file.Searched == False | self.model_file.CustomFormatMet - is False + == False ) elif self.quality_unmet_search and self.custom_format_unmet_search: condition &= ( self.model_file.Searched == False | self.model_file.QualityMet == False | self.model_file.CustomFormatMet - is False + == False ) else: condition &= self.model_file.EpisodeFileId == 0 - condition &= self.model_file.Searched is 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) @@ -1650,24 +1650,24 @@ def db_get_request_files(self) -> Iterable[MoviesFilesModel | EpisodeFilesModel] condition = self.model_file.Year <= datetime.now().year condition &= self.model_file.Year > 0 if self.do_upgrade_search: - condition &= self.model_file.Upgrade is False + condition &= self.model_file.Upgrade == False else: if self.quality_unmet_search and not self.custom_format_unmet_search: condition &= ( - self.model_file.Searched == False | self.model_file.QualityMet is False + self.model_file.Searched == False | self.model_file.QualityMet == False ) elif not self.quality_unmet_search and self.custom_format_unmet_search: condition &= ( self.model_file.Searched == False | self.model_file.CustomFormatMet - is False + == False ) elif self.quality_unmet_search and self.custom_format_unmet_search: condition &= ( self.model_file.Searched == False | self.model_file.QualityMet == False | self.model_file.CustomFormatMet - is False + == False ) else: condition &= self.model_file.MovieFileId == 0 @@ -2199,7 +2199,7 @@ def minimum_availability_check(self, db_entry: JsonObject) -> bool: def db_update_single_series( self, db_entry: JsonObject = None, request: bool = False, series: bool = False ): - if self.search_missing is False: + if not self.search_missing: return try: searched = False @@ -2802,7 +2802,7 @@ def file_is_probeable(self, file: pathlib.Path) -> bool: return False def folder_cleanup(self, downloads_id: str | None, folder: pathlib.Path): - if self.auto_delete is False: + if not self.auto_delete: return self.logger.debug("Folder Cleanup: %s", folder) all_files_in_folder = list(absolute_file_paths(folder)) @@ -2887,11 +2887,11 @@ def remove_and_maybe_blocklist(self, downloads_id: str | None, file_or_folder: p ) def all_folder_cleanup(self) -> None: - if self.auto_delete is False: + if not self.auto_delete: return self._update_bad_queue_items() self.post_file_cleanup() - if self.needs_cleanup is False: + if not self.needs_cleanup: return folder = self.completed_folder self.folder_cleanup(None, folder) @@ -3182,7 +3182,7 @@ def process_torrents(self): torrents = [t for t in torrents if hasattr(t, "category")] if not len(torrents): raise DelayLoopException(length=LOOP_SLEEP_TIMER, type="no_downloads") - if has_internet() is False: + if not has_internet(): self.manager.qbit_manager.should_delay_torrent_scan = True raise DelayLoopException(length=NO_INTERNET_SLEEP_TIMER, type="internet") if self.manager.qbit_manager.should_delay_torrent_scan: @@ -4211,7 +4211,7 @@ def _process_single_torrent(self, torrent: qbittorrentapi.TorrentDictionary): self._process_single_torrent_queued_upload(torrent, leave_alone) elif ( torrent.progress >= self.maximum_deletable_percentage - and self.is_complete_state(torrent) is False + and not self.is_complete_state(torrent) and not self.in_tags(torrent, "qBitrr-ignored") and not self.in_tags(torrent, "qBitrr-free_space_paused") and not stalled_ignore @@ -4522,7 +4522,7 @@ def parse_quality_profiles(self) -> tuple[int, int]: def register_search_mode(self): if self.search_setup_completed: return - if self.search_missing is False: + if not self.search_missing: self.search_setup_completed = True return @@ -4605,7 +4605,7 @@ def run_request_search(self): self.db_request_update() try: for entry in self.db_get_request_files(): - while self.maybe_do_search(entry, request=True) is False: + while not self.maybe_do_search(entry, request=True): time.sleep(30) self.request_search_timer = time.time() return @@ -4766,7 +4766,7 @@ def run_search_loop(self) -> NoReturn: loop_delay = 30 else: loop_delay = SEARCH_LOOP_DELAY - while ( + while not ( self.maybe_do_search( entry[0], todays=entry[1], @@ -4774,7 +4774,7 @@ def run_search_loop(self) -> NoReturn: series_search=entry[3], commands=totcommands, ) - ) is False: + ): self.logger.debug("Waiting for active search commands") time.sleep(loop_delay) if SEARCH_LOOP_DELAY != -1: @@ -5051,7 +5051,7 @@ def process_torrents(self): torrents = [t for t in torrents if hasattr(t, "category")] if not len(torrents): raise DelayLoopException(length=LOOP_SLEEP_TIMER, type="no_downloads") - if has_internet() is False: + if not has_internet(): self.manager.qbit_manager.should_delay_torrent_scan = True raise DelayLoopException(length=NO_INTERNET_SLEEP_TIMER, type="internet") if self.manager.qbit_manager.should_delay_torrent_scan: @@ -5252,7 +5252,7 @@ def process_torrents(self): torrents = [t for t in torrents if "qBitrr-ignored" not in t.tags] if not len(torrents): raise DelayLoopException(length=LOOP_SLEEP_TIMER, type="no_downloads") - if has_internet() is False: + if not has_internet(): self.manager.qbit_manager.should_delay_torrent_scan = True raise DelayLoopException(length=NO_INTERNET_SLEEP_TIMER, type="internet") if self.manager.qbit_manager.should_delay_torrent_scan: From 1679bee1ed7802d757726e32f14184a35b2be34a Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 17:04:50 +0100 Subject: [PATCH 14/16] Search testing --- qBitrr/arss.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index cd8c6b30..e1b6d234 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1300,31 +1300,21 @@ def _search_todays(self, condition): def db_get_files( self, - ) -> ( - list[list[MoviesFilesModel | EpisodeFilesModel | SeriesFilesModel, bool, bool, bool, int]] - | None - ): - entries = [] - self.logger.trace("Getting files to search") + ) -> Iterable[ + tuple[MoviesFilesModel | EpisodeFilesModel | SeriesFilesModel, bool, bool, bool, int] + ]: if self.type == "sonarr" and self.series_search: serieslist = self.db_get_files_series() for series in serieslist: - entries.append( - [series[0], series[1], series[2], series[2] is not True, len(serieslist)] - ) - # yield series[0], series[1], series[2], series[2] is not True, len(serieslist) + yield series[0], series[1], series[2], series[2] is not True, len(serieslist) elif self.type == "sonarr" and not self.series_search: episodelist = self.db_get_files_episodes() for episodes in episodelist: - entries.append([episodes[0], episodes[1], episodes[2], False, len(episodelist)]) - # yield episodes[0], episodes[1], episodes[2], False, len(episodelist) + yield episodes[0], episodes[1], episodes[2], False, len(episodelist) elif self.type == "radarr": movielist = self.db_get_files_movies() for movies in movielist: - entries.append([movies[0], movies[1], movies[2], False, len(movielist)]) - # yield movies[0], movies[1], movies[2], False, len(movielist) - self.logger.trace("Returning %s entries", len(entries) if entries else 0) - return entries + yield movies[0], movies[1], movies[2], False, len(movielist) def db_maybe_reset_entry_searched_state(self): if self.type == "sonarr": @@ -4760,18 +4750,18 @@ def run_search_loop(self) -> NoReturn: commands, ) in self.db_get_files(): if totcommands == -1: - totcommands = entry[4] + totcommands = commands self.logger.info("Starting search for %s items", totcommands) if SEARCH_LOOP_DELAY == -1: loop_delay = 30 else: loop_delay = SEARCH_LOOP_DELAY - while not ( + while ( self.maybe_do_search( - entry[0], - todays=entry[1], - bypass_limit=entry[2], - series_search=entry[3], + entry, + todays=todays, + bypass_limit=limit_bypass, + series_search=series_search, commands=totcommands, ) ): From ba53dc847cec32fc9b4d928431548239d9305c40 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:05:03 +0000 Subject: [PATCH 15/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- qBitrr/arss.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index e1b6d234..81b9b685 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -4756,14 +4756,12 @@ def run_search_loop(self) -> NoReturn: loop_delay = 30 else: loop_delay = SEARCH_LOOP_DELAY - while ( - self.maybe_do_search( - entry, - todays=todays, - bypass_limit=limit_bypass, - series_search=series_search, - commands=totcommands, - ) + while self.maybe_do_search( + entry, + todays=todays, + bypass_limit=limit_bypass, + series_search=series_search, + commands=totcommands, ): self.logger.debug("Waiting for active search commands") time.sleep(loop_delay) From 0e0e55b30c8cefc9c5d7778d1fdf3f69e0d45bd8 Mon Sep 17 00:00:00 2001 From: Feramance Date: Sun, 27 Oct 2024 17:06:36 +0100 Subject: [PATCH 16/16] Reverted condition changes --- qBitrr/arss.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index e1b6d234..68d81873 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -1434,6 +1434,7 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None == False ) else: + condition &= self.model_file.EpisodeFileId == 0 condition &= self.model_file.Searched == False todays_condition = copy(condition) todays_condition &= self.model_file.AirDateUtc > ( @@ -1456,7 +1457,6 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None ) for i1, i2, i3 in self._search_todays(condition): if i1 is not None: - self.logger.trace("Adding %s to search list", i1.Title) entries.append([i1, i2, i3]) if not self.do_upgrade_search: condition = self.series_file_model.Searched == False @@ -1469,7 +1469,6 @@ def db_get_files_series(self) -> list[list[SeriesFilesModel, bool, bool]] | None .execute() ) for entry_ in query: - self.logger.trace("Adding %s to search list", entry_.Title) entries.append([entry_, False, False]) return entries @@ -1502,6 +1501,7 @@ def db_get_files_episodes(self) -> list[list[EpisodeFilesModel, bool, bool]] | N == False ) else: + condition &= self.model_file.EpisodeFileId == 0 condition &= self.model_file.Searched == False today_condition = copy(condition) today_condition &= self.model_file.AirDateUtc > ( @@ -1535,11 +1535,9 @@ def db_get_files_episodes(self) -> list[list[EpisodeFilesModel, bool, bool]] | N .execute() ) for entry in query: - self.logger.trace("Adding %s to search list", entry.Title) entries.append([entry, False, False]) for i1, i2, i3 in self._search_todays(today_condition): if i1 is not None: - self.logger.trace("Adding %s to search list", i1.Title) entries.append([i1, i2, i3]) return entries @@ -1575,6 +1573,7 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None ) else: self.logger.trace("Condition 5") + condition &= self.model_file.MovieFileId == 0 condition &= self.model_file.Searched == False if self.search_by_year: self.logger.trace("Condition 6") @@ -1586,7 +1585,6 @@ def db_get_files_movies(self) -> list[list[MoviesFilesModel, bool, bool]] | None .execute() ) for entry in query: - self.logger.trace("Adding %s to search list", entry.Title) entries.append([entry, False, False]) return entries