added min tor time, large performance improvement #12
@ -65,7 +65,9 @@ You will need a category-whitelist.json in the root directory. This will ignore
|
|||||||
| non_protected_tag | we don't care about these torrents |
|
| non_protected_tag | we don't care about these torrents |
|
||||||
| logpath | will write a log in root directory if left as is other wise specify other path using forward slashes |
|
| logpath | will write a log in root directory if left as is other wise specify other path using forward slashes |
|
||||||
| age | number, seconds for how long we keep torrents from IPTORRENTS |
|
| age | number, seconds for how long we keep torrents from IPTORRENTS |
|
||||||
|
| minimum_age | age in seconds torrents should reached before they are removed |
|
||||||
| use_pushover | true or false to enable or disable pushover notification summary |
|
| use_pushover | true or false to enable or disable pushover notification summary |
|
||||||
| use_log | true or false to enable or disable writing to alog file |
|
| use_log | true or false to enable or disable writing to alog file |
|
||||||
| po_key | pushover key |
|
| po_key | pushover key |
|
||||||
| po_token | pushover api token |
|
| po_token | pushover api token |
|
||||||
|
| delete_torrents | true or false to enable or disable deletion. Useful for dry-runs |
|
@ -8,8 +8,10 @@
|
|||||||
"protected_tag": "ipt",
|
"protected_tag": "ipt",
|
||||||
"non_protected_tag": "public",
|
"non_protected_tag": "public",
|
||||||
"age": 2419200,
|
"age": 2419200,
|
||||||
|
"minimum_age": 432000,
|
||||||
"use_pushover": true,
|
"use_pushover": true,
|
||||||
"use_log": true,
|
"use_log": true,
|
||||||
"po_key": "",
|
"po_key": "",
|
||||||
"po_token": ""
|
"po_token": "",
|
||||||
|
"delete_torrents": false
|
||||||
}
|
}
|
@ -37,6 +37,8 @@ class Qbt:
|
|||||||
self.loglevel = self.config["loglevel"]
|
self.loglevel = self.config["loglevel"]
|
||||||
self.tracker_protected_tag = self.config["protected_tag"]
|
self.tracker_protected_tag = self.config["protected_tag"]
|
||||||
self.tracker_non_protected_tag = self.config["non_protected_tag"]
|
self.tracker_non_protected_tag = self.config["non_protected_tag"]
|
||||||
|
self.minimum_age = self.config["minimum_age"]
|
||||||
|
self.age = self.config["age"]
|
||||||
# Calling log and notify functions
|
# Calling log and notify functions
|
||||||
torlog(self)
|
torlog(self)
|
||||||
tornotify(self)
|
tornotify(self)
|
||||||
@ -46,6 +48,7 @@ class Qbt:
|
|||||||
self.tracker_whitelist = load(f)
|
self.tracker_whitelist = load(f)
|
||||||
self.tracker_list = []
|
self.tracker_list = []
|
||||||
self.up_tor_counter = 0
|
self.up_tor_counter = 0
|
||||||
|
self.preme_tor_counter = 0
|
||||||
self.torrent_hash_delete_list = []
|
self.torrent_hash_delete_list = []
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
self.tl.debug(self.tracker_whitelist)
|
self.tl.debug(self.tracker_whitelist)
|
||||||
|
37
qlist.py
37
qlist.py
@ -9,6 +9,9 @@ def buildtorlist(self):
|
|||||||
torrent = self.torrentlist.pop()
|
torrent = self.torrentlist.pop()
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
self.tl.debug(f'["{torrent["name"][0:20]}..."] {torrent["infohash_v1"]}')
|
self.tl.debug(f'["{torrent["name"][0:20]}..."] {torrent["infohash_v1"]}')
|
||||||
|
if torrent['added_on'] + self.minimum_age <= self.t.time():
|
||||||
|
self.preme_tor_counter += 1
|
||||||
|
continue
|
||||||
if torrent['category'] in self.cat_whitelist.values():
|
if torrent['category'] in self.cat_whitelist.values():
|
||||||
self.tl.info(f'Ignored torrent:["{torrent["name"][0:20]}..."]')
|
self.tl.info(f'Ignored torrent:["{torrent["name"][0:20]}..."]')
|
||||||
continue
|
continue
|
||||||
@ -27,36 +30,4 @@ def buildtorlist(self):
|
|||||||
self.tl.debug(f'Non-protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
self.tl.debug(f'Non-protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
||||||
if torrent['tags'] == '':
|
if torrent['tags'] == '':
|
||||||
self.qbt_client.torrents_add_tags(self.tracker_non_protected_tag,torrent['hash'])
|
self.qbt_client.torrents_add_tags(self.tracker_non_protected_tag,torrent['hash'])
|
||||||
self.tracker_list.append(torrent)
|
self.tracker_list.append(torrent)
|
||||||
|
|
||||||
def writetor(self, filepath='./torrentinfo.txt'):
|
|
||||||
"""Write all torrent data to a file.
|
|
||||||
Useful for development of new features.
|
|
||||||
"""
|
|
||||||
with open(filepath, 'w') as fp:
|
|
||||||
fp.write(str(self.torrentlist))
|
|
||||||
|
|
||||||
def listfirsttor(self, index=0):
|
|
||||||
"""Only lists the first torrent"""
|
|
||||||
self.tl.debug('First torrent in the list:')
|
|
||||||
torrent = self.torrentlist[index]
|
|
||||||
for k,v in torrent.items():
|
|
||||||
self.tl.debug(f'{k}: {v}')
|
|
||||||
self.tl.debug('\n')
|
|
||||||
|
|
||||||
def listqbitapiinfo(self):
|
|
||||||
"""Writes torrent info to log file"""
|
|
||||||
self.tl.debug(f'qBittorrent: {self.qbt_client.app.version}')
|
|
||||||
self.tl.debug(f'qBittorrent Web API: {self.qbt_client.app.web_api_version}')
|
|
||||||
|
|
||||||
def torrentcount(self):
|
|
||||||
"""write torrent counts to log file"""
|
|
||||||
self.tl.debug(f'torrents that are protected {self.tracker_list.count("ipt")}')
|
|
||||||
self.tl.debug(f'torrents that aren\'t protected {self.tracker_list.count("public")}')
|
|
||||||
|
|
||||||
def tordeletetags(self):
|
|
||||||
tag_list = [self.tracker_protected_tag, self.tracker_non_protected_tag]
|
|
||||||
self.qbt_client.torrents_delete_tags(tag_list)
|
|
||||||
|
|
||||||
def torlisttags(self):
|
|
||||||
pass
|
|
43
qlogging.py
43
qlogging.py
@ -19,12 +19,53 @@ def tornotifytest(self):
|
|||||||
def tornotifysummary(self):
|
def tornotifysummary(self):
|
||||||
"""Main notification method when the app is used in an automated fashion"""
|
"""Main notification method when the app is used in an automated fashion"""
|
||||||
self.poc.send_message(f" Total: {self.total_torrents}\n\
|
self.poc.send_message(f" Total: {self.total_torrents}\n\
|
||||||
|
Premature: {self.preme_tor_counter}\n\
|
||||||
Protected: {self.c[self.tracker_protected_tag]}\n\
|
Protected: {self.c[self.tracker_protected_tag]}\n\
|
||||||
Non-protected: {self.c[self.tracker_non_protected_tag]}\n\
|
Non-protected: {self.c[self.tracker_non_protected_tag]}\n\
|
||||||
Marked for deletion: {len(self.torrent_hash_delete_list)}\n\
|
Marked for deletion: {len(self.torrent_hash_delete_list)}\n\
|
||||||
Orphaned: {self.up_tor_counter}", title="--- qbit-maid summary ---")
|
Orphaned: {self.up_tor_counter}", title="--- qbit-maid summary ---")
|
||||||
|
|
||||||
|
def printprocessor(self):
|
||||||
|
"""Print summary of torrents"""
|
||||||
|
self.c = self.ct()
|
||||||
|
for item in self.tracker_list:
|
||||||
|
self.c[item["tags"]] += 1
|
||||||
|
self.tl.info(f'Total: {self.total_torrents}')
|
||||||
|
self.tl.info(f'Premature: {self.preme_tor_counter}')
|
||||||
|
self.tl.info(f'Protected: {self.c[self.tracker_protected_tag]}')
|
||||||
|
self.tl.info(f'Non-protected: {self.c[self.tracker_non_protected_tag]}')
|
||||||
|
self.tl.info(f'Orphaned: {self.up_tor_counter}')
|
||||||
|
self.tl.info(f'Marked for deletion: {len(self.torrent_hash_delete_list)}')
|
||||||
|
|
||||||
def getunixtimestamp(self):
|
def getunixtimestamp(self):
|
||||||
"""Used for debuging and development related to unixtimestamps, not used in main script but useful"""
|
"""Used for debuging and development related to unixtimestamps, not used in main script but useful"""
|
||||||
self.uts = self.t.time()
|
self.uts = self.t.time()
|
||||||
self.tl.info(self.uts)
|
self.tl.info(self.uts)
|
||||||
|
|
||||||
|
def writetor(self, filepath='./torrentinfo.txt'):
|
||||||
|
"""Write all torrent data to a file.
|
||||||
|
Useful for development of new features.
|
||||||
|
"""
|
||||||
|
with open(filepath, 'w') as fp:
|
||||||
|
fp.write(str(self.torrentlist))
|
||||||
|
|
||||||
|
def listfirsttor(self, index=0):
|
||||||
|
"""Only lists the first torrent"""
|
||||||
|
self.tl.debug('First torrent in the list:')
|
||||||
|
torrent = self.torrentlist[index]
|
||||||
|
for k,v in torrent.items():
|
||||||
|
self.tl.debug(f'{k}: {v}')
|
||||||
|
self.tl.debug('\n')
|
||||||
|
|
||||||
|
def listqbitapiinfo(self):
|
||||||
|
"""Writes torrent info to log file"""
|
||||||
|
self.tl.debug(f'qBittorrent: {self.qbt_client.app.version}')
|
||||||
|
self.tl.debug(f'qBittorrent Web API: {self.qbt_client.app.web_api_version}')
|
||||||
|
|
||||||
|
def torrentcount(self):
|
||||||
|
"""write torrent counts to log file"""
|
||||||
|
self.tl.debug(f'torrents that are protected {self.tracker_list.count("ipt")}')
|
||||||
|
self.tl.debug(f'torrents that aren\'t protected {self.tracker_list.count("public")}')
|
||||||
|
|
||||||
|
def torlisttags(self):
|
||||||
|
pass
|
17
qprocess.py
17
qprocess.py
@ -10,9 +10,9 @@ def torprocessor(self):
|
|||||||
elif canidate['ratio'] < float(1.05) and self.tracker_protected_tag in canidate["tags"]:
|
elif canidate['ratio'] < float(1.05) and self.tracker_protected_tag in canidate["tags"]:
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
self.tl.debug(f'["{canidate["name"][0:20]}..."] is below a 1.05 ratio({canidate["ratio"]})')
|
self.tl.debug(f'["{canidate["name"][0:20]}..."] is below a 1.05 ratio({canidate["ratio"]})')
|
||||||
if canidate['added_on'] + self.config["age"] <= self.t.time():
|
if canidate['added_on'] + self.age <= self.t.time():
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
self.tl.debug(f'["{canidate["name"][0:20]}..."] Seconds old: {self.t.time() - self.config["age"] - canidate["added_on"]}')
|
self.tl.debug(f'["{canidate["name"][0:20]}..."] Seconds old: {self.t.time() - self.age - canidate["added_on"]}')
|
||||||
self.torrent_hash_delete_list.append(canidate['infohash_v1'])
|
self.torrent_hash_delete_list.append(canidate['infohash_v1'])
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
self.tl.info(f'Submitted ["{canidate["name"][0:20]}..."] for deletion from the protected list.')
|
self.tl.info(f'Submitted ["{canidate["name"][0:20]}..."] for deletion from the protected list.')
|
||||||
@ -31,16 +31,9 @@ def torprocessor(self):
|
|||||||
self.up_tor_counter += 1
|
self.up_tor_counter += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def printprocessor(self):
|
def tordeletetags(self):
|
||||||
"""Print summary of torrents"""
|
tag_list = [self.tracker_protected_tag, self.tracker_non_protected_tag]
|
||||||
self.c = self.ct()
|
self.qbt_client.torrents_delete_tags(tag_list)
|
||||||
for item in self.tracker_list:
|
|
||||||
self.c[item["tags"]] += 1
|
|
||||||
self.tl.info(f'Total: {self.total_torrents}')
|
|
||||||
self.tl.info(f'Protected: {self.c[self.tracker_protected_tag]}')
|
|
||||||
self.tl.info(f'Non-protected: {self.c[self.tracker_non_protected_tag]}')
|
|
||||||
self.tl.info(f'Orphaned: {self.up_tor_counter}')
|
|
||||||
self.tl.info(f'Marked for deletion: {len(self.torrent_hash_delete_list)}')
|
|
||||||
|
|
||||||
def tordelete(self):
|
def tordelete(self):
|
||||||
"""Remove torrents, will also delete files, this keeps the filesystem clean.
|
"""Remove torrents, will also delete files, this keeps the filesystem clean.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user