qbit-maid/qprocess.py

54 lines
2.8 KiB
Python
Raw Normal View History

2022-07-14 19:03:06 -05:00
#The fourth file shall be logic to process torrents.
def torprocessor(self):
2022-07-20 11:34:13 -05:00
"""Main logic to sort through both self.tracker_nonprotected_list and self.tracker_protected_list
If torrent meets criteria for deletion, its infohash_v1 will be appended to self.torrent_hash_delete_list
"""
2022-07-14 19:03:06 -05:00
for canidate in self.tracker_nonprotected_list:
if 'ipt' in canidate['tags']:
if self.use_log:
self.tl.warning(f'{canidate["name"]} was in non-protected list.')
2022-07-14 19:03:06 -05:00
break
if canidate['state'] == 'downloading':
if self.use_log:
self.tl.info(f'{canidate["name"]} is still downloading and will be skipped.')
2022-07-14 19:03:06 -05:00
break
else:
self.torrent_hash_delete_list.append(canidate['infohash_v1'])
if self.use_log:
self.tl.info(f'Submitted {canidate["name"]} for deletion.')
2022-07-14 19:03:06 -05:00
for canidate in self.tracker_protected_list:
if canidate['state'] == 'downloading':
if self.use_log:
self.tl.warning(f'{canidate["name"]} is still downloading and will be skipped.')
2022-07-14 19:03:06 -05:00
break
if canidate['ratio'] < float(1.05):
if self.use_log:
self.tl.debug(f'{canidate["name"]} is below a 1.05 ratio({canidate["ratio"]})')
2022-07-14 19:03:06 -05:00
if canidate['added_on'] + self.config["age"] <= self.t.time():
if self.use_log:
self.tl.debug(f'{canidate["name"]} Seconds old: {self.t.time() - self.config["age"] - canidate["added_on"]}')
2022-07-14 19:03:06 -05:00
self.torrent_hash_delete_list.append(canidate['infohash_v1'])
if self.use_log:
self.tl.info(f'Submitted {canidate["name"]} for deletion from the protected list.')
2022-07-14 19:03:06 -05:00
if canidate['ratio'] >= float(1.05):
if self.use_log:
self.tl.debug(f'{canidate["name"]} is above a 1.05 ratio({canidate["ratio"]}).')
2022-07-14 19:03:06 -05:00
self.torrent_hash_delete_list.append(canidate['infohash_v1'])
if self.use_log:
self.tl.info(f'Submitted {canidate["name"]} for deletion from the protected list.')
2022-07-14 19:03:06 -05:00
else:
pass
def printprocessor(self):
2022-07-20 11:34:13 -05:00
"""Print summary of torrents"""
2022-07-14 19:03:06 -05:00
self.tl.info(f'Protected torrents: {len(self.tracker_protected_list)}')
self.tl.info(f'Non-protected torrents: {len(self.tracker_nonprotected_list)}')
self.tl.info(f'Total torrents set for deletion: {len(self.torrent_hash_delete_list)}')
def tordelete(self):
2022-07-20 11:34:13 -05:00
"""Remove torrents, will also delete files, this keeps the filesystem clean.
Only pass self.torrent_hash_delete_list if you would like to keep the files."""
if self.use_log:
self.tl.debug('Hash list submitted for deletion:')
2022-07-20 11:34:13 -05:00
self.tl.debug(self.torrent_hash_delete_list)
2022-07-14 19:03:06 -05:00
self.qbt_client.torrents_delete(True, self.torrent_hash_delete_list)