From b73ab06e25e394ea5109b87a737f48388ae7363e Mon Sep 17 00:00:00 2001 From: Feramance Date: Mon, 24 Jun 2024 13:58:26 +0200 Subject: [PATCH] Added new fields `AllowStalled` and `StalledDelay` --- config.example.toml | 24 ++++++++++++++++++++++++ qBitrr/arss.py | 35 ++++++++++++++++++++++++----------- qBitrr/gen_config.py | 2 ++ 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/config.example.toml b/config.example.toml index 5d3ed7c5..fbbb3800 100644 --- a/config.example.toml +++ b/config.example.toml @@ -214,6 +214,12 @@ MaximumDeletablePercentage = 0.99 # Ignore slow torrents. DoNotRemoveSlow = true +# Allow stalled torrents +AllowStalled = false + +# Maximum allowed time for allowed stalled torrents +StalledDelay = 0 + [Sonarr-TV.Torrent.SeedingMode] # Set the maximum allowed download rate for torrents @@ -411,6 +417,12 @@ MaximumDeletablePercentage = 0.99 # Ignore slow torrents. DoNotRemoveSlow = true +# Allow stalled torrents +AllowStalled = false + +# Maximum allowed time for allowed stalled torrents +StalledDelay = 0 + [Sonarr-Anime.Torrent.SeedingMode] # Set the maximum allowed download rate for torrents @@ -604,6 +616,12 @@ MaximumDeletablePercentage = 0.99 # Ignore slow torrents. DoNotRemoveSlow = true +# Allow stalled torrents +AllowStalled = false + +# Maximum allowed time for allowed stalled torrents +StalledDelay = 0 + [Radarr-1080.Torrent.SeedingMode] # Set the maximum allowed download rate for torrents @@ -810,6 +828,12 @@ MaximumDeletablePercentage = 0.99 # Ignore slow torrents. DoNotRemoveSlow = true +# Allow stalled torrents +AllowStalled = false + +# Maximum allowed time for allowed stalled torrents +StalledDelay = 0 + [Radarr-4K.Torrent.SeedingMode] # Set the maximum allowed download rate for torrents diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 0b8beba2..b83f1f07 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -222,6 +222,8 @@ def __init__( ) self.do_not_remove_slow = CONFIG.get(f"{name}.Torrent.DoNotRemoveSlow", fallback=False) + self.allow_stalled = CONFIG.get(f"{name}.Torrent.AllowStalled", fallback=False) + self.stalled_delay = CONFIG.get(f"{name}.Torrent.StalledDelay", fallback=0) self.search_current_year = None if self.search_in_reverse: self._delta = 1 @@ -491,7 +493,8 @@ def __init__( [ "qBitrr-allowed_seeding", "qBitrr-ignored", - "qbitrr-imported", + "qBitrr-imported", + "qBitrr-allow_stalled" ] ) self.search_setup_completed = False @@ -3777,16 +3780,11 @@ def _should_leave_alone( seeding_time_limit = max(seeding_time_limit_dat, seeding_time_limit_tor) ratio_limit = max(ratio_limit_dat, ratio_limit_tor) - if self.seeding_mode_global_remove_torrent != -1 and self.remove_torrent( - torrent, seeding_time_limit, ratio_limit - ): - remove_torrent = True - return_value = False + if self.seeding_mode_global_remove_torrent != -1: + remove_torrent = self.torrent_limit_check(torrent, seeding_time_limit, ratio_limit) else: - if torrent.ratio >= ratio_limit and ratio_limit != -5: - return_value = False # Seeding ratio met - Can be cleaned up. - if torrent.seeding_time >= seeding_time_limit and seeding_time_limit != -5: - return_value = False # Seeding time met - Can be cleaned up. + remove_torrent = False + return_value = not self.torrent_limit_check(torrent, seeding_time_limit, ratio_limit) if data_settings.get("super_seeding", False) or data_torrent.get("super_seeding", False): return_value = True if "qBitrr-free_space_paused" in torrent.tags: @@ -3978,6 +3976,11 @@ def _process_single_torrent(self, torrent: qbittorrentapi.TorrentDictionary): "qBitrr-free_space_paused", ] ) + if ( + "qBitrr-allow_stalled" in torrent.tags + and torrent.added_on >= int(time.time()+(self.stalled_delay*60)) + ): + torrent.remove_tags(["qBitrr-allow_stalled"]) if ( self.custom_format_unmet_search and self.custom_format_unmet_check(torrent) @@ -4003,6 +4006,7 @@ def _process_single_torrent(self, torrent: qbittorrentapi.TorrentDictionary): ) and "qBitrr-ignored" not in torrent.tags and "qBitrr-free_space_paused" not in torrent.tags + and "qBitrr-allow_stalled" not in torrent.tags ): self._process_single_torrent_stalled_torrent(torrent, "Stalled State") elif ( @@ -4023,6 +4027,7 @@ def _process_single_torrent(self, torrent: qbittorrentapi.TorrentDictionary): and self.is_complete_state(torrent) is False and "qBitrr-ignored" not in torrent.tags and "qBitrr-free_space_paused" not in torrent.tags + and "qBitrr-allow_stalled" not in torrent.tags ) and torrent.hash in self.cleaned_torrents: self._process_single_torrent_percentage_threshold(torrent, maximum_eta) # Resume monitored downloads which have been paused. @@ -4078,6 +4083,7 @@ def _process_single_torrent(self, torrent: qbittorrentapi.TorrentDictionary): and not self.do_not_remove_slow and "qBitrr-ignored" not in torrent.tags and "qBitrr-free_space_paused" not in torrent.tags + and "qBitrr-allow_stalled" not in torrent.tags ): self._process_single_torrent_delete_slow(torrent) # Process uncompleted torrents @@ -4094,6 +4100,7 @@ def _process_single_torrent(self, torrent: qbittorrentapi.TorrentDictionary): and self.is_downloading_state(torrent) and "qBitrr-ignored" not in torrent.tags and "qBitrr-free_space_paused" not in torrent.tags + and "qBitrr-allow_stalled" not in torrent.tags ): self._process_single_torrent_stalled_torrent(torrent, "Unavailable") else: @@ -4224,7 +4231,7 @@ def custom_format_unmet_check(self, torrent: qbittorrentapi.TorrentDictionary) - except KeyError: pass - def remove_torrent( + def torrent_limit_check( self, torrent: qbittorrentapi.TorrentDictionary, seeding_time_limit, ratio_limit ) -> bool: if ( @@ -4244,6 +4251,12 @@ def remove_torrent( return True elif self.seeding_mode_global_remove_torrent == 1 and torrent.ratio >= ratio_limit: return True + elif ( + self.seeding_mode_global_remove_torrent == -1 + and (torrent.ratio >= ratio_limit + or torrent.seeding_time >= seeding_time_limit) + ): + return True else: return False diff --git a/qBitrr/gen_config.py b/qBitrr/gen_config.py index ff87631f..a72f8280 100755 --- a/qBitrr/gen_config.py +++ b/qBitrr/gen_config.py @@ -338,6 +338,8 @@ def _gen_default_torrent_table(category: str, cat_default: Table): 0.99, ) _gen_default_line(torrent_table, "Ignore slow torrents.", "DoNotRemoveSlow", True) + _gen_default_line(torrent_table, "Allow stalled torrents", "AllowStalled", False) + _gen_default_line(torrent_table, "Maximum allowed time for allowed stalled torrents", "StalledDelay", 0) _gen_default_seeding_table(category, torrent_table) _gen_default_tracker_tables(category, torrent_table)