Skip to content

Commit

Permalink
Add connected_seeder and connected_leecher condition
Browse files Browse the repository at this point in the history
Closes #62.
  • Loading branch information
jerrymakesjelly committed Feb 8, 2020
1 parent 18cb635 commit 32bf679
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion autoremovetorrents/condition/connectedleecher.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
5 changes: 4 additions & 1 deletion autoremovetorrents/condition/connectedseeder.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
4 changes: 4 additions & 0 deletions autoremovetorrents/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test:
max_connected_seeder: 0
remove:
- Torrent - 1
- Torrent - 12
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions pytest/test_strategies/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32bf679

Please sign in to comment.