Skip to content

Commit

Permalink
Added StallUpload and StallDownload status
Browse files Browse the repository at this point in the history
Closes #34.
  • Loading branch information
jerrymakesjelly committed Jun 6, 2019
1 parent 891b995 commit 88e984b
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 12 deletions.
4 changes: 3 additions & 1 deletion autoremovetorrents/client/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def torrent_properties(self, torrent_hash):
torrent['hash'], torrent['name'],
torrent['category'] if 'category' in torrent else torrent['label'],
[tracker['url'] for tracker in trackers],
qBittorrent._judge_status(torrent['state']), torrent['size'], torrent['ratio'],
qBittorrent._judge_status(torrent['state']),
torrent['state'] == 'stalledUP' or torrent['state'] == 'stalledDL',
torrent['size'], torrent['ratio'],
properties['total_uploaded'], properties['addition_date'],
properties['seeding_time'])

Expand Down
6 changes: 4 additions & 2 deletions autoremovetorrents/client/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ def torrents_list(self):
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']}
'fields': ['hashString', 'name', 'trackers', 'status', 'totalSize', 'uploadRatio', 'uploadedEver', 'addedDate', 'secondsSeeding', 'isStalled']}
)
if len(result['torrents']) == 0: # No such torrent
raise NoSuchClient("No such torrent of hash '%s'." % torrent_hash)
torrent = result['torrents'][0]
return Torrent(
torrent['hashString'], torrent['name'], '',
[tracker['announce'] for tracker in torrent['trackers']],
Transmission._judge_status(torrent['status']), torrent['totalSize'], torrent['uploadRatio'],
Transmission._judge_status(torrent['status']),
torrent['isStalled'],
torrent['totalSize'], torrent['uploadRatio'],
torrent['uploadedEver'], torrent['addedDate'], torrent['secondsSeeding'])

# Judge Torrent Status
Expand Down
4 changes: 3 additions & 1 deletion autoremovetorrents/client/utorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def torrent_properties(self, torrent_hash):
# Get torrent's tracker
trackers = self._torrent_job_properties(torrent_hash)['trackers'].split()
return Torrent(
torrent[0], torrent[2], torrent[11], trackers, uTorrent._judge_status(torrent[1], torrent[4]), torrent[3], torrent[7]/1000,
torrent[0], torrent[2], torrent[11], trackers, uTorrent._judge_status(torrent[1], torrent[4]),
False, # uTorrent never has stall status
torrent[3], torrent[7]/1000,
torrent[6], sys.maxsize, -1)
# Not Found
raise NoSuchTorrent('No such torrent.')
Expand Down
36 changes: 29 additions & 7 deletions autoremovetorrents/filter/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,45 @@ def __init__(self, all_status, ac, re):
Filter.__init__(self, all_status, ac, re)

self._logger = logger.Logger.register(__name__) # Register a logger
self._acc_status = self._convert_status(self._accept)
self._rej_status = self._convert_status(self._reject)
self._acc_status, self._acc_stallup, self._acc_stalldown = self._convert_status(self._accept)
self._rej_status, self._rej_stallup, self._rej_stalldown = self._convert_status(self._reject)

def _convert_status(self, status_list):
result = []
stallUp = False
stallDown = False
for status in status_list:
# For StalledUploading and StalledDownloading
if 'stalledupload' == str(status).lower():
stallUp = True
continue
if 'stalleddownload' == str(status).lower():
stallDown = True
continue
try:
result.append(TorrentStatus[str(status).capitalize()])
except KeyError:
self._logger.warning(
"The status '%s' does not exist, so it won't be used."
% str(status)
)
return result
return result, stallUp, stallDown

def apply(self, torrents):
return set([torrent for torrent in torrents
if (self._all or torrent.status in self._acc_status)
and not (torrent.status in self._rej_status)
])
result = set()

for torrent in torrents:
if self._all or torrent.status in self._acc_status:
result.add(torrent)
if self._acc_stallup and torrent.status == TorrentStatus.Uploading and torrent.stalled:
result.add(torrent)
if self._acc_stalldown and torrent.status == TorrentStatus.Downloading and torrent.stalled:
result.add(torrent)
if torrent in result and torrent.status in self._rej_status:
result.remove(torrent)
if torrent in result and self._rej_stallup and torrent.status == TorrentStatus.Uploading and torrent.stalled:
result.remove(torrent)
if torrent in result and self._rej_stalldown and torrent.status == TorrentStatus.Downloading and torrent.stalled:
result.remove(torrent)

return result
1 change: 1 addition & 0 deletions autoremovetorrents/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, name, conf, remove_torrents = True):
'(No Category)',
[],
TorrentStatus.Unknown,
False,
0,
0,
0,
Expand Down
3 changes: 2 additions & 1 deletion autoremovetorrents/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from .torrentstatus import TorrentStatus

class Torrent(object):
def __init__(self, hash_value, name, category, tracker, status, size, ratio,
def __init__(self, hash_value, name, category, tracker, status, stalled, size, ratio,
uploaded, create_time, seeding_time):
# Save Properties
self.hash = hash_value
self.name = name
self.category = category
self.tracker = tracker
self.status = status
self.stalled = stalled
self.size = size
self.ratio = ratio
self.uploaded = uploaded
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test:
status: Downloading
excluded_status: StalledDownload
remain:
- Torrent - 2
- Torrent - 11
- Torrent - 12
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test:
status: Downloading
remain:
- Torrent - 1
- Torrent - 2
- Torrent - 11
- Torrent - 12
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test:
status: StalledDownload
remain:
- Torrent - 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test:
status: StalledUpload
remain:
- Torrent - 3
- Torrent - 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test:
status: Uploading
excluded_status: StalledUpload
remain:
- Torrent - 4
- Torrent - 6
- Torrent - 7
- Torrent - 8
- Torrent - 9
- Torrent - 10
11 changes: 11 additions & 0 deletions pytest/test_strategies/cases/status/test_uploading_status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test:
status: Uploading
remain:
- Torrent - 3
- Torrent - 4
- Torrent - 5
- Torrent - 6
- Torrent - 7
- Torrent - 8
- Torrent - 9
- Torrent - 10
1 change: 1 addition & 0 deletions pytest/test_strategies/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_data():
torrent['category'],
torrent['tracker'],
TorrentStatus[str(torrent['state']).capitalize()],
torrent['is_stalled'],
torrent['size'],
torrent['ratio'],
torrent['uploaded'],
Expand Down
16 changes: 16 additions & 0 deletions pytest/test_strategies/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "ce982ec3de112990914c470ad4b392db13bda1b5",
"is_stalled": true,
"last_activity": 1526742631,
"name": "Torrent - 1",
"num_complete": 1,
Expand Down Expand Up @@ -52,6 +53,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "0f350a203e22a26650762bd84306371e7795a125",
"is_stalled": false,
"last_activity": 1526742631,
"name": "Torrent - 2",
"num_complete": 1,
Expand Down Expand Up @@ -92,6 +94,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "31e70cfeb84bd9ad03958e5a466bbda3c45f65ae",
"is_stalled": true,
"last_activity": 1526742212,
"name": "Torrent - 3",
"num_complete": 40,
Expand Down Expand Up @@ -132,6 +135,7 @@
"f_l_piece_prio": false,
"force_start": true,
"hash": "589d65494cc1772dc3e7ae8ed67526200a385b87",
"is_stalled": false,
"last_activity": 1526614323,
"name": "Torrent - 4",
"num_complete": 9,
Expand Down Expand Up @@ -172,6 +176,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "6665ce0c042c75ae04e136d6bf7296f91d5e6cc8",
"is_stalled": true,
"last_activity": 1526742178,
"name": "Torrent - 5",
"num_complete": 36,
Expand Down Expand Up @@ -212,6 +217,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "c1a80bb2773479579d8316e12fa512e4bc7d6c78",
"is_stalled": false,
"last_activity": 1526742631,
"name": "Torrent - 6",
"num_complete": 73,
Expand Down Expand Up @@ -252,6 +258,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "0c58b1a4ed68991ea4ffaad377613399772e720a",
"is_stalled": false,
"last_activity": 1526742523,
"name": "Torrent - 7",
"num_complete": 74,
Expand Down Expand Up @@ -292,6 +299,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "077f987b5bbd40d654714e3229c63afc9b8cb1f5",
"is_stalled": false,
"last_activity": 1526742631,
"name": "Torrent - 8",
"num_complete": 70,
Expand Down Expand Up @@ -332,6 +340,7 @@
"f_l_piece_prio": false,
"force_start": true,
"hash": "bfa64b01321d7a25f6ea8014ad97c614b3cec66b",
"is_stalled": false,
"last_activity": 1526730151,
"name": "Torrent - 9",
"num_complete": 8,
Expand Down Expand Up @@ -372,6 +381,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "afdebdd83334a798c1004580305c5f604f2388aa",
"is_stalled": false,
"last_activity": 1526742631,
"name": "Torrent - 10",
"num_complete": 115,
Expand Down Expand Up @@ -412,6 +422,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "8a174331016e27d2b1796c66eaf17d83421a141c",
"is_stalled": false,
"last_activity": 1526742631,
"name": "Torrent - 11",
"num_complete": 1,
Expand Down Expand Up @@ -452,6 +463,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "911084986f01fd53ecad48278840115d1efccbe2",
"is_stalled": false,
"last_activity": 1526742631,
"name": "Torrent - 12",
"num_complete": 1,
Expand Down Expand Up @@ -492,6 +504,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "14fb6c76dd9fe09e5a5d40662e1799e2fe6d9a5c",
"is_stalled": false,
"last_activity": 1527351767,
"name": "Torrent - 13",
"num_complete": 57,
Expand Down Expand Up @@ -532,6 +545,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "eb16d385d60a4b6ddbf761e1038d3d50621d8a24",
"is_stalled": false,
"last_activity": 1527350136,
"name": "Torrent - 14",
"num_complete": 28,
Expand Down Expand Up @@ -572,6 +586,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "a3fc358ab7f5a907501229c6a3a40690cd86d184",
"is_stalled": false,
"last_activity": 1527351309,
"name": "Torrent - 15",
"num_complete": 1,
Expand Down Expand Up @@ -612,6 +627,7 @@
"f_l_piece_prio": false,
"force_start": false,
"hash": "b55ec068772d0c91b5af542d56306049c69ab6f7",
"is_stalled": false,
"last_activity": 1527352055,
"name": "Torrent - 16",
"num_complete": 72,
Expand Down

0 comments on commit 88e984b

Please sign in to comment.