From 32bf6793fa740659894516640b09143ee1a1b1ae Mon Sep 17 00:00:00 2001 From: jerrymakesjelly Date: Sat, 8 Feb 2020 16:17:58 +0800 Subject: [PATCH] Add connected_seeder and connected_leecher condition Closes #62. --- autoremovetorrents/condition/connectedleecher.py | 5 ++++- autoremovetorrents/condition/connectedseeder.py | 5 ++++- autoremovetorrents/strategy.py | 4 ++++ .../test_max_connected_seeder.yml | 5 +++++ .../test_min_connected_leecher.yml | 11 +++++++++++ pytest/test_strategies/conftest.py | 2 ++ 6 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 pytest/test_strategies/cases/max_connected_seeder/test_max_connected_seeder.yml create mode 100644 pytest/test_strategies/cases/min_connected_leecher/test_min_connected_leecher.yml diff --git a/autoremovetorrents/condition/connectedleecher.py b/autoremovetorrents/condition/connectedleecher.py index 81cbea5..2f3e0f3 100644 --- a/autoremovetorrents/condition/connectedleecher.py +++ b/autoremovetorrents/condition/connectedleecher.py @@ -1,5 +1,6 @@ from .base import Comparer from .base import Condition +from ..torrentstatus import TorrentStatus class ConnectedLeecherCondition(Condition): def __init__(self, cl, comp = Comparer.LT): @@ -9,7 +10,9 @@ def __init__(self, cl, comp = Comparer.LT): def apply(self, torrents): for torrent in torrents: - if self.compare(torrent.connected_leecher, self._connected_leecher, self._comparer): + # Note: This condition is only available for the uploading and the downloading torrents + if (torrent.status == TorrentStatus.Downloading or torrent.status == TorrentStatus.Uploading) \ + and self.compare(torrent.connected_leecher, self._connected_leecher, self._comparer): self.remove.add(torrent) else: self.remain.add(torrent) \ No newline at end of file diff --git a/autoremovetorrents/condition/connectedseeder.py b/autoremovetorrents/condition/connectedseeder.py index 94269e4..821de01 100644 --- a/autoremovetorrents/condition/connectedseeder.py +++ b/autoremovetorrents/condition/connectedseeder.py @@ -1,5 +1,6 @@ from .base import Comparer from .base import Condition +from ..torrentstatus import TorrentStatus class ConnectedSeederCondition(Condition): def __init__(self, cs, comp = Comparer.GT): @@ -9,7 +10,9 @@ def __init__(self, cs, comp = Comparer.GT): def apply(self, torrents): for torrent in torrents: - if self.compare(torrent.connected_seeder, self._connected_seeder, self._comparer): + # Note: This condition is only available for the uploading and downloading torrents + if (torrent.status == TorrentStatus.Uploading or torrent.status == TorrentStatus.Downloading) and \ + self.compare(torrent.connected_seeder, self._connected_seeder, self._comparer): self.remove.add(torrent) else: self.remain.add(torrent) \ No newline at end of file diff --git a/autoremovetorrents/strategy.py b/autoremovetorrents/strategy.py index 9ecb647..a3152e0 100644 --- a/autoremovetorrents/strategy.py +++ b/autoremovetorrents/strategy.py @@ -7,7 +7,9 @@ from .condition.createtime import CreateTimeCondition from .condition.ratio import RatioCondition from .condition.seeder import SeederCondition +from .condition.connectedseeder import ConnectedSeederCondition from .condition.leecher import LeecherCondition +from .condition.connectedleecher import ConnectedLeecherCondition from .condition.downloadspeed import DownloadSpeedCondition from .condition.uploadspeed import UploadSpeedCondition from .condition.torrentsize import TorrentSizeCondition @@ -73,7 +75,9 @@ def _apply_conditions(self): 'create_time': CreateTimeCondition, 'ratio': RatioCondition, 'max_seeder': SeederCondition, + 'max_connected_seeder': ConnectedSeederCondition, 'min_leecher': LeecherCondition, + 'min_connected_leecher': ConnectedLeecherCondition, 'max_downloadspeed': DownloadSpeedCondition, 'min_uploadspeed': UploadSpeedCondition, 'size': SizeCondition, diff --git a/pytest/test_strategies/cases/max_connected_seeder/test_max_connected_seeder.yml b/pytest/test_strategies/cases/max_connected_seeder/test_max_connected_seeder.yml new file mode 100644 index 0000000..073996d --- /dev/null +++ b/pytest/test_strategies/cases/max_connected_seeder/test_max_connected_seeder.yml @@ -0,0 +1,5 @@ +test: + max_connected_seeder: 0 +remove: + - Torrent - 1 + - Torrent - 12 diff --git a/pytest/test_strategies/cases/min_connected_leecher/test_min_connected_leecher.yml b/pytest/test_strategies/cases/min_connected_leecher/test_min_connected_leecher.yml new file mode 100644 index 0000000..c6b4fec --- /dev/null +++ b/pytest/test_strategies/cases/min_connected_leecher/test_min_connected_leecher.yml @@ -0,0 +1,11 @@ +test: + min_connected_leecher: 50 +remove: + - Torrent - 3 + - Torrent - 4 + - Torrent - 5 + - Torrent - 6 + - Torrent - 7 + - Torrent - 8 + - Torrent - 9 + - Torrent - 10 diff --git a/pytest/test_strategies/conftest.py b/pytest/test_strategies/conftest.py index 8c549e2..c27dc04 100644 --- a/pytest/test_strategies/conftest.py +++ b/pytest/test_strategies/conftest.py @@ -32,7 +32,9 @@ def test_data(): torrent_obj.download_speed = torrent['dlspeed'] torrent_obj.last_activity = torrent['last_activity'] torrent_obj.seeder = torrent['num_complete'] + torrent_obj.connected_seeder = torrent['num_seeds'] torrent_obj.leecher = torrent['num_incomplete'] + torrent_obj.connected_leecher = torrent['num_leechs'] input_torrents.append(torrent_obj) return input_torrents