Skip to content

Commit

Permalink
Add avg max_dl_speed and min_ul_speed condition
Browse files Browse the repository at this point in the history
Closes #49.
  • Loading branch information
jerrymakesjelly committed Feb 8, 2020
1 parent 32bf679 commit 44b9884
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 3 deletions.
2 changes: 2 additions & 0 deletions autoremovetorrents/client/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def torrent_properties(self, torrent_hash):
torrent_obj.connected_seeder = properties['seeds']
torrent_obj.leecher = properties['peers_total']
torrent_obj.connected_leecher = properties['peers']
torrent_obj.average_upload_speed = properties['up_speed_avg']
torrent_obj.average_download_speed = properties['dl_speed_avg']
# For qBittorrent 3.x, the last activity field doesn't exist.
# We need to check the existence
if 'last_activity' in torrent:
Expand Down
32 changes: 29 additions & 3 deletions autoremovetorrents/client/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,32 @@ def torrents_list(self):
# Get Torrent Properties
def torrent_properties(self, torrent_hash):
result = self._make_transmission_request('torrent-get',
{'ids': [torrent_hash],
'fields': ['hashString', 'name', 'trackers', 'status', 'totalSize', 'uploadRatio', 'uploadedEver', 'addedDate', 'secondsSeeding', 'isStalled', 'error', 'labels', 'rateDownload', 'rateUpload', 'peersGettingFromUs', 'peersSendingToUs', 'trackerStats', 'activityDate']}
{
'ids': [torrent_hash],
'fields': [
'hashString',
'name',
'trackers',
'status',
'totalSize',
'uploadRatio',
'uploadedEver',
'addedDate',
'secondsSeeding',
'isStalled',
'error',
'labels',
'rateDownload',
'rateUpload',
'peersGettingFromUs',
'peersSendingToUs',
'trackerStats',
'activityDate',
'uploadedEver',
'secondsSeeding',
'downloadedEver',
'secondsDownloading',
]}
)
if len(result['torrents']) == 0: # No such torrent
raise NoSuchClient("No such torrent of hash '%s'." % torrent_hash)
Expand All @@ -101,7 +125,9 @@ def torrent_properties(self, torrent_hash):
torrent_obj.leecher = sum([tracker['leecherCount'] for tracker in torrent['trackerStats']])
torrent_obj.connected_leecher = torrent['peersGettingFromUs']
torrent_obj.last_activity = torrent['activityDate']

torrent_obj.average_upload_speed = torrent['uploadedEver'] / torrent['secondsSeeding']
torrent_obj.average_download_speed = torrent['downloadedEver'] / torrent['secondsDownloading']

return torrent_obj

# Judge Torrent Status
Expand Down
15 changes: 15 additions & 0 deletions autoremovetorrents/condition/avgdownloadspeed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .base import Comparer
from .base import Condition

class AverageDownloadSpeedCondition(Condition):
def __init__(self, avg_dl_speed, comp = Comparer.GT):
Condition.__init__(self) # Initialize remain and remove list
self._avg_dl_speed = avg_dl_speed # In KiB
self._comparer = comp

def apply(self, torrents):
for torrent in torrents:
if self.compare(torrent.average_download_speed, self._avg_dl_speed * 1024, self._comparer):
self.remove.add(torrent)
else:
self.remain.add(torrent)
15 changes: 15 additions & 0 deletions autoremovetorrents/condition/avguploadspeed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .base import Comparer
from .base import Condition

class AverageUploadSpeedCondition(Condition):
def __init__(self, avg_ul_speed, comp = Comparer.LT):
Condition.__init__(self) # Initialize remain and remove list
self._avg_ul_speed = avg_ul_speed # In KiB
self._comparer = comp

def apply(self, torrents):
for torrent in torrents:
if self.compare(torrent.average_upload_speed, self._avg_ul_speed * 1024, 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 @@ -10,7 +10,9 @@
from .condition.connectedseeder import ConnectedSeederCondition
from .condition.leecher import LeecherCondition
from .condition.connectedleecher import ConnectedLeecherCondition
from .condition.avgdownloadspeed import AverageDownloadSpeedCondition
from .condition.downloadspeed import DownloadSpeedCondition
from .condition.avguploadspeed import AverageUploadSpeedCondition
from .condition.uploadspeed import UploadSpeedCondition
from .condition.torrentsize import TorrentSizeCondition
from .condition.torrentnumber import TorrentNumberCondition
Expand Down Expand Up @@ -79,7 +81,9 @@ def _apply_conditions(self):
'min_leecher': LeecherCondition,
'min_connected_leecher': ConnectedLeecherCondition,
'max_downloadspeed': DownloadSpeedCondition,
'max_average_downloadspeed': AverageDownloadSpeedCondition,
'min_uploadspeed': UploadSpeedCondition,
'min_average_uploadspeed': AverageUploadSpeedCondition,
'size': SizeCondition,
'last_activity': LastActivityCondition,
'seed_size': TorrentSizeCondition,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test:
max_average_downloadspeed: 5120
remove:
- Torrent - 3
- Torrent - 5
- Torrent - 7
- Torrent - 8
- Torrent - 9
- Torrent - 11
- Torrent - 13
- Torrent - 14
- Torrent - 16
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test:
min_average_uploadspeed: 512
remove:
- Torrent - 1
- Torrent - 3
- Torrent - 6
- Torrent - 10
- Torrent - 12
- Torrent - 14
2 changes: 2 additions & 0 deletions pytest/test_strategies/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def test_data():
torrent_obj.create_time = torrent['added_on']
torrent_obj.seeding_time = torrent['seeding_time']
torrent_obj.upload_speed = torrent['upspeed']
torrent_obj.average_upload_speed = torrent['up_speed_avg']
torrent_obj.download_speed = torrent['dlspeed']
torrent_obj.average_download_speed = torrent['dl_speed_avg']
torrent_obj.last_activity = torrent['last_activity']
torrent_obj.seeder = torrent['num_complete']
torrent_obj.connected_seeder = torrent['num_seeds']
Expand Down
32 changes: 32 additions & 0 deletions pytest/test_strategies/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"completed": 5707223927,
"completion_on": 4294967295,
"dl_limit": 0,
"dl_speed_avg": 499524,
"dlspeed": 2270401,
"downloaded": 5710905998,
"downloaded_session": 5710905998,
Expand Down Expand Up @@ -36,6 +37,7 @@
"https://tracker.site1.com/announce"
],
"up_limit": 0,
"up_speed_avg": 78804,
"uploaded": 8564552428,
"uploaded_session": 8564552428,
"upspeed": 984644
Expand All @@ -46,6 +48,7 @@
"completed": 19054854172,
"completion_on": 4294967295,
"dl_limit": 0,
"dl_speed_avg": 188567,
"dlspeed": 1583918,
"downloaded": 19053990510,
"downloaded_session": 19053990510,
Expand Down Expand Up @@ -77,6 +80,7 @@
"https://www.site2.org/tracker/announce"
],
"up_limit": 0,
"up_speed_avg": 808605,
"uploaded": 51623504177,
"uploaded_session": 51623504177,
"upspeed": 2886504
Expand All @@ -87,6 +91,7 @@
"completed": 347000034,
"completion_on": 1526732525,
"dl_limit": 0,
"dl_speed_avg": 5584975,
"dlspeed": 0,
"downloaded": 347198660,
"downloaded_session": 347198660,
Expand Down Expand Up @@ -118,6 +123,7 @@
"https://www.site2.org/tracker/announce"
],
"up_limit": 0,
"up_speed_avg": 456008,
"uploaded": 812985418,
"uploaded_session": 812985418,
"upspeed": 0
Expand All @@ -128,6 +134,7 @@
"completed": 10152029087,
"completion_on": 1525970677,
"dl_limit": 0,
"dl_speed_avg": 5019202,
"dlspeed": 0,
"downloaded": 0,
"downloaded_session": 0,
Expand Down Expand Up @@ -159,6 +166,7 @@
"http://tracker.site3.com/?action=announce"
],
"up_limit": 0,
"up_speed_avg": 832684,
"uploaded": 43783272788,
"uploaded_session": 0,
"upspeed": 0
Expand All @@ -169,6 +177,7 @@
"completed": 9627866528,
"completion_on": 1526723020,
"dl_limit": 0,
"dl_speed_avg": 7858040,
"dlspeed": 0,
"downloaded": 9628171953,
"downloaded_session": 9628171953,
Expand Down Expand Up @@ -200,6 +209,7 @@
"https://www.site2.org/tracker/announce"
],
"up_limit": 0,
"up_speed_avg": 851779,
"uploaded": 29372377819,
"uploaded_session": 29372377819,
"upspeed": 0
Expand All @@ -211,6 +221,7 @@
"completion_on": 1526736296,
"dl_limit": 0,
"dlspeed": 0,
"dl_speed_avg": 4633382,
"downloaded": 13201638292,
"downloaded_session": 13201638292,
"eta": 8640000,
Expand Down Expand Up @@ -241,6 +252,7 @@
"https://www.site2.org/tracker/announce"
],
"up_limit": 0,
"up_speed_avg": 37146,
"uploaded": 23420454865,
"uploaded_session": 23420454865,
"upspeed": 121201
Expand All @@ -252,6 +264,7 @@
"completion_on": 1526738269,
"dl_limit": 0,
"dlspeed": 0,
"dl_speed_avg": 9855309,
"downloaded": 7240240790,
"downloaded_session": 7240240790,
"eta": 8640000,
Expand Down Expand Up @@ -282,6 +295,7 @@
"https://tracker.site1.com/announce"
],
"up_limit": 0,
"up_speed_avg": 812996,
"uploaded": 18854220629,
"uploaded_session": 18854220629,
"upspeed": 0
Expand All @@ -293,6 +307,7 @@
"completion_on": 1526731123,
"dl_limit": 0,
"dlspeed": 0,
"dl_speed_avg": 7062911,
"downloaded": 7621738011,
"downloaded_session": 7621738011,
"eta": 8640000,
Expand Down Expand Up @@ -323,6 +338,7 @@
"https://www.site2.org/tracker/announce"
],
"up_limit": 0,
"up_speed_avg": 801737,
"uploaded": 32700782429,
"uploaded_session": 32700782429,
"upspeed": 87463
Expand All @@ -333,6 +349,7 @@
"completed": 3022394751,
"completion_on": 1525969428,
"dl_limit": 0,
"dl_speed_avg": 6112945,
"dlspeed": 0,
"downloaded": 0,
"downloaded_session": 0,
Expand Down Expand Up @@ -364,6 +381,7 @@
"http://tracker.site3.com/?action=announce"
],
"up_limit": 0,
"up_speed_avg": 900793,
"uploaded": 6949286694,
"uploaded_session": 26198016,
"upspeed": 0
Expand All @@ -374,6 +392,7 @@
"completed": 14844911534,
"completion_on": 1526735607,
"dl_limit": 0,
"dl_speed_avg": 4306811,
"dlspeed": 0,
"downloaded": 14846696889,
"downloaded_session": 14846696889,
Expand Down Expand Up @@ -405,6 +424,7 @@
"https://www.site2.org/tracker/announce"
],
"up_limit": 0,
"up_speed_avg": 152048,
"uploaded": 32388045222,
"uploaded_session": 32388045222,
"upspeed": 327541
Expand All @@ -415,6 +435,7 @@
"completed": 2321891132,
"completion_on": 4294967295,
"dl_limit": 0,
"dl_speed_avg": 6403655,
"dlspeed": 302084,
"downloaded": 2321882559,
"downloaded_session": 2321882559,
Expand Down Expand Up @@ -446,6 +467,7 @@
"https://tracker.site1.com/announce"
],
"up_limit": 0,
"up_speed_avg": 586125,
"uploaded": 5750836550,
"uploaded_session": 5750836550,
"upspeed": 442042
Expand All @@ -456,6 +478,7 @@
"completed": 1715653161,
"completion_on": 4294967295,
"dl_limit": 0,
"dl_speed_avg": 3792899,
"dlspeed": 269870,
"downloaded": 1716876766,
"downloaded_session": 1716876766,
Expand Down Expand Up @@ -487,6 +510,7 @@
"https://www.site2.org/tracker/announce"
],
"up_limit": 0,
"up_speed_avg": 254117,
"uploaded": 4056422836,
"uploaded_session": 4056422836,
"upspeed": 668038
Expand All @@ -497,6 +521,7 @@
"completed": 1746686185,
"completion_on": 1527342372,
"dl_limit": 0,
"dl_speed_avg": 10211715,
"dlspeed": 0,
"downloaded": 1747429022,
"downloaded_session": 1747429022,
Expand Down Expand Up @@ -528,6 +553,7 @@
"https://tracker.site4.io:2710/"
],
"up_limit": 0,
"up_speed_avg": 661650,
"uploaded": 1898576526,
"uploaded_session": 1898576526,
"upspeed": 0
Expand All @@ -538,6 +564,7 @@
"completed": 312186667,
"completion_on": 1527335960,
"dl_limit": 0,
"dl_speed_avg": 9987804,
"dlspeed": 0,
"downloaded": 312891624,
"downloaded_session": 312891624,
Expand Down Expand Up @@ -569,6 +596,7 @@
"https://tracker.site4.io:2710/"
],
"up_limit": 0,
"up_speed_avg": 482248,
"uploaded": 107814988,
"uploaded_session": 107814988,
"upspeed": 0
Expand All @@ -579,6 +607,7 @@
"completed": 2126568405,
"completion_on": 1527350573,
"dl_limit": 0,
"dl_speed_avg": 2708163,
"dlspeed": 0,
"downloaded": 2127119819,
"downloaded_session": 2127119819,
Expand Down Expand Up @@ -610,6 +639,7 @@
"https://tracker.site4.io:2710/"
],
"up_limit": 0,
"up_speed_avg": 950107,
"uploaded": 3323768148,
"uploaded_session": 3323768148,
"upspeed": 0
Expand All @@ -620,6 +650,7 @@
"completed": 1132013553,
"completion_on": 1527335868,
"dl_limit": 0,
"dl_speed_avg": 7002425,
"dlspeed": 0,
"downloaded": 1139339147,
"downloaded_session": 1139339147,
Expand Down Expand Up @@ -651,6 +682,7 @@
"https://tracker.site4.io:2710/"
],
"up_limit": 0,
"up_speed_avg": 924258,
"uploaded": 395526144,
"uploaded_session": 395526144,
"upspeed": 8055
Expand Down

0 comments on commit 44b9884

Please sign in to comment.