From 348575b2c0054c867e4f4077e4f5427b45a29c74 Mon Sep 17 00:00:00 2001 From: Feramance Date: Mon, 9 Oct 2023 13:23:41 +0200 Subject: [PATCH] [build] Type fix --- qBitrr/arss.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/qBitrr/arss.py b/qBitrr/arss.py index c3c601ad..8038bd97 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -138,13 +138,6 @@ def __init__( self.file_extension_allowlist = CONFIG.get( f"{name}.Torrent.FileExtensionAllowlist", fallback=[] ) - self.logger.debug("file_extension_allowlist: %s", self.file_extension_allowlist) - for ext in self.file_extension_allowlist: - if ext[0] != "\\": - self.file_extension_allowlist[self.file_extension_allowlist.index(ext)] = ( - "\\" + ext - ) - self.logger.debug("file_extension_allowlist: %s", self.file_extension_allowlist) self.auto_delete = CONFIG.get(f"{name}.Torrent.AutoDelete", fallback=False) self.remove_dead_trackers = CONFIG.get( @@ -289,6 +282,9 @@ def __init__( self.file_name_exclusion_regex_re = re.compile( "|".join(self.file_name_exclusion_regex), re.DOTALL ) + self.file_extension_allowlist = re.compile( + "|".join(self.file_extension_allowlist), re.DOTALL + ) else: self.folder_exclusion_regex_re = re.compile( "|".join(self.folder_exclusion_regex), re.IGNORECASE | re.DOTALL @@ -296,6 +292,9 @@ def __init__( self.file_name_exclusion_regex_re = re.compile( "|".join(self.file_name_exclusion_regex), re.IGNORECASE | re.DOTALL ) + self.file_extension_allowlist = re.compile( + "|".join(self.file_extension_allowlist), re.DOTALL + ) self.client = client_cls(host_url=self.uri, api_key=self.apikey) if isinstance(self.client, SonarrAPI): self.type = "sonarr" @@ -2112,9 +2111,8 @@ def folder_cleanup(self, downloads_id: str | None, folder: pathlib.Path): if file.is_dir(): self.logger.trace("Folder Cleanup: File is a folder: %s", file) continue - if ( - file.suffix.lower() in self.file_extension_allowlist - or not self.file_extension_allowlist + if self.file_extension_allowlist and ( + (match := self.file_extension_allowlist.search(file.suffix)) and match.group() ): self.logger.trace("Folder Cleanup: File has an allowed extension: %s", file) if self.file_is_probeable(file): @@ -2938,13 +2936,8 @@ def _process_single_torrent_process_files( ) _remove_files.add(file.id) total -= 1 - elif ( - self.file_extension_allowlist - and ( - (match := self.file_extension_allowlist.search(file_path.suffix)) - and match.group() - ) - # and file_path.suffix.lower() not in self.file_extension_allowlist + elif self.file_extension_allowlist and ( + (match := self.file_extension_allowlist.search(file_path.suffix)) and match.group() ): self.logger.debug( "Removing File: Not allowed | Extension: %s | %s (%s) | %s ",