Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
1a5aee5272 | |||
8c32f32c85 | |||
3556382e62 | |||
adc3825396 | |||
70b6b3e96a | |||
1fbdd5e84d |
@ -9,11 +9,11 @@
|
||||
"non_protected_tag": "public",
|
||||
"age": 2419200,
|
||||
"minimum_age": 432000,
|
||||
"use_pushover": true,
|
||||
"use_pushover": false,
|
||||
"use_log": true,
|
||||
"po_key": "",
|
||||
"po_token": "",
|
||||
"delete_torrents": false,
|
||||
"enable_dragnet": true,
|
||||
"dragnet_outfile": "./orphaned.csv"
|
||||
"dragnet_outfile": "./dragnet.csv"
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
#The first file shall contain an client to the qbit api and the processing of the torrents.
|
||||
import qbittorrentapi
|
||||
import pushover
|
||||
from json import load
|
||||
@ -34,7 +33,7 @@ class Qbt:
|
||||
self.po = pushover
|
||||
self.ct = Counter
|
||||
self.cv = csv
|
||||
# Variables torlog uses from config.json
|
||||
# Init config.json
|
||||
self.use_pushover = self.config["use_pushover"]
|
||||
self.use_log = self.config["use_log"]
|
||||
self.po_key = self.config["po_key"]
|
||||
|
41
qlist.py
41
qlist.py
@ -8,40 +8,37 @@ def build_tor_list(self):
|
||||
while self.torrent_list:
|
||||
torrent = self.torrent_list.pop()
|
||||
if self.use_log:
|
||||
self.tl.debug(f'["{torrent["name"][0:20]}..."] {torrent["infohash_v1"]}')
|
||||
self.tl.debug(f'---Analyzing ["{torrent["name"][0:20]}..."] {torrent["infohash_v1"]}---')
|
||||
if is_protected_tracker(torrent['tracker'], self.tracker_whitelist.values()):
|
||||
if is_tag_blank(torrent['tags']):
|
||||
self.qbt_client.torrents_add_tags(self.tracker_protected_tag,torrent['hash'])
|
||||
if self.use_log:
|
||||
self.tl.debug(f'Tagging Protected torrent: ["{torrent["name"][0:20]}..."] {torrent["tracker"]}hash: {torrent["hash"]}')
|
||||
self.tracker_list.append(torrent)
|
||||
if is_not_protected_tracker(torrent['tracker'], self.tracker_whitelist.values()):
|
||||
if is_tag_blank(torrent['tags']):
|
||||
self.qbt_client.torrents_add_tags(self.tracker_non_protected_tag,torrent['hash'])
|
||||
if self.use_log:
|
||||
self.tl.debug(f'Tagging Non-protected torrent: ["{torrent["name"][0:20]}..."] {torrent["tracker"]}hash: {torrent["hash"]}')
|
||||
self.tracker_list.append(torrent)
|
||||
if is_ignored_tag(self.ignored_tags.values(),torrent['tags']):
|
||||
self.ignored_counter += 1
|
||||
self.tl.info(f'Ignored tag: ["{torrent["name"][0:20]}..."] tags: {torrent["tags"]} hash: {torrent["hash"]}')
|
||||
continue
|
||||
# if torrent['added_on'] + self.minimum_age >= self.t.time():
|
||||
if is_preme(torrent['added_on'], self.minimum_age, self.t.time()):
|
||||
self.preme_tor_counter += 1
|
||||
self.tl.debug(f'Premature torrent: ["{torrent["name"][0:20]}..."] hash: {torrent["hash"]}')
|
||||
continue
|
||||
# if torrent['category'] in self.cat_whitelist.values():
|
||||
if is_cat_ignored(torrent['category'], self.cat_whitelist.values()):
|
||||
self.tl.info(f'Ignored torrent:["{torrent["name"][0:20]}..."]')
|
||||
self.tl.info(f'Ignored category: ["{torrent["name"][0:20]}..."] category:[{torrent["category"]}] hash: {torrent["hash"]}')
|
||||
self.ignored_counter += 1
|
||||
continue
|
||||
# if torrent['tracker'] == '':
|
||||
if is_tracker_blank(torrent['tracker']):
|
||||
if self.use_log:
|
||||
self.tl.warning(f'Torrent doesn\'t have a tracker ["{torrent["name"][0:20]}..."] [{torrent["tracker"]}]hash: {torrent["hash"]}')
|
||||
self.ignored_counter += 1
|
||||
continue
|
||||
# if torrent['tracker'].split('/')[2] in self.tracker_whitelist.values():
|
||||
if is_protected_tracker(torrent['tracker'], self.tracker_whitelist.values()):
|
||||
if self.use_log:
|
||||
self.tl.debug(f'Protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
||||
# if torrent['tags'] == '':
|
||||
if is_tag_blank(torrent['tags']):
|
||||
self.qbt_client.torrents_add_tags(self.tracker_protected_tag,torrent['hash'])
|
||||
self.tracker_list.append(torrent)
|
||||
if is_not_protected_tracker(torrent['tracker'], self.tracker_whitelist.values()):
|
||||
if self.use_log:
|
||||
self.tl.debug(f'Non-protected torrent: {torrent["tracker"]}hash: {torrent["hash"]}')
|
||||
# if torrent['tags'] == '':
|
||||
if is_tag_blank(torrent['tags']):
|
||||
self.qbt_client.torrents_add_tags(self.tracker_non_protected_tag,torrent['hash'])
|
||||
self.tracker_list.append(torrent)
|
||||
|
||||
|
||||
def is_preme(added, minage, time):
|
||||
if added + minage >= time:
|
||||
@ -56,10 +53,14 @@ def is_tracker_blank(tracker):
|
||||
return True
|
||||
|
||||
def is_protected_tracker(tracker, trackerlist):
|
||||
if tracker == '':
|
||||
return False
|
||||
if tracker.split('/')[2] in trackerlist:
|
||||
return True
|
||||
|
||||
def is_not_protected_tracker(tracker, trackerlist):
|
||||
if tracker == '':
|
||||
return False
|
||||
if tracker.split('/')[2] not in trackerlist:
|
||||
return True
|
||||
|
||||
|
29
qlogging.py
29
qlogging.py
@ -42,17 +42,6 @@ def tor_notify_summary(self):
|
||||
Marked for deletion: {len(self.torrent_hash_delete_list)}\n\
|
||||
{self.extm}", title="--- qbit-maid summary ---")
|
||||
|
||||
def getunixtimestamp(self):
|
||||
"""Used for debuging and development related to unixtimestamps, not used in main script but useful"""
|
||||
self.uts = self.t.time()
|
||||
self.tl.info(self.uts)
|
||||
|
||||
def writetor(self, filepath='./torrentinfo.json'):
|
||||
"""Write all torrent data to a file.
|
||||
Useful for development of new features.
|
||||
"""
|
||||
pass
|
||||
|
||||
def list_first_tor(self, index=0):
|
||||
"""Only lists the first torrent"""
|
||||
self.tl.debug('First torrent in the list:')
|
||||
@ -68,24 +57,12 @@ def list_qbit_api_info(self):
|
||||
|
||||
def torrent_count(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
|
||||
|
||||
def debugpremecal(self):
|
||||
for torrent in self.torrent_list:
|
||||
if torrent['infohash_v1'] == 'a89b484ea375094af53ce89ecbea14bf086d6284':
|
||||
print(torrent["name"][0:20])
|
||||
print(torrent['added_on'] + self.minimum_age >= self.t.time())
|
||||
self.tl.debug(f'*** Torrents with tag["{self.tracker_protected_tag}"] {self.c[self.tracker_protected_tag]} ***')
|
||||
self.tl.debug(f'*** Torrents with tag["{self.tracker_non_protected_tag}"] {self.c[self.tracker_non_protected_tag]} ***')
|
||||
|
||||
def get_script_runtime(self):
|
||||
elapsed_time = self.et - self.st
|
||||
if self.use_log:
|
||||
self.tl.info(f'Execution time: [{elapsed_time}]')
|
||||
if self.use_pushover:
|
||||
self.extm = f"Execution time: [{elapsed_time}]"
|
||||
|
||||
def getobjecttype(object):
|
||||
print(type(object))
|
||||
self.extm = f"Execution time: [{elapsed_time}]"
|
10
qprocess.py
10
qprocess.py
@ -3,30 +3,27 @@ def tor_processor(self):
|
||||
If torrent meets criteria for deletion, its infohash_v1 will be appended to self.torrent_hash_delete_list
|
||||
"""
|
||||
for canidate in self.tracker_list:
|
||||
# if canidate['state'] == 'downloading':
|
||||
if self.use_log:
|
||||
self.tl.debug(f'---Reviewing canidate: ["{canidate["name"][0:20]}..."] {canidate["infohash_v1"]}---')
|
||||
if is_downloading(canidate['state']):
|
||||
if self.use_log:
|
||||
self.tl.info(f'["{canidate["name"][0:20]}..."] is still downloading and will be skipped.')
|
||||
continue
|
||||
# elif canidate['ratio'] < float(1.05) and self.tracker_protected_tag in canidate["tags"]:
|
||||
elif is_protected_under_ratio(canidate['ratio'], 1.05, self.tracker_protected_tag, canidate["tags"]):
|
||||
if self.use_log:
|
||||
self.tl.debug(f'["{canidate["name"][0:20]}..."] is below a 1.05 ratio({canidate["ratio"]})')
|
||||
# if canidate['added_on'] + self.age <= self.t.time():
|
||||
if is_old_tor(canidate['added_on'], self.age, self.t.time()):
|
||||
if self.use_log:
|
||||
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'])
|
||||
if self.use_log:
|
||||
self.tl.info(f'Submitted ["{canidate["name"][0:20]}..."] for deletion from the protected list.')
|
||||
# elif canidate['ratio'] >= float(1.05) and self.tracker_protected_tag in canidate["tags"]:
|
||||
elif is_protected_over_ratio(canidate['ratio'], 1.05, self.tracker_protected_tag, canidate["tags"]):
|
||||
if self.use_log:
|
||||
self.tl.debug(f'["{canidate["name"][0:20]}..."] is above a 1.05 ratio({canidate["ratio"]}).')
|
||||
self.torrent_hash_delete_list.append(canidate['infohash_v1'])
|
||||
if self.use_log:
|
||||
self.tl.info(f'Submitted ["{canidate["name"][0:20]}..."] for deletion from the protected list.')
|
||||
# elif self.tracker_non_protected_tag in canidate["tags"]:
|
||||
elif is_not_protected_tor(self.tracker_non_protected_tag, canidate["tags"]):
|
||||
self.torrent_hash_delete_list.append(canidate['infohash_v1'])
|
||||
if self.use_log:
|
||||
@ -48,7 +45,8 @@ def tor_delete(self):
|
||||
if self.use_log:
|
||||
self.tl.debug('Hash list submitted for deletion:')
|
||||
self.tl.debug(self.torrent_hash_delete_list)
|
||||
self.qbt_client.torrents_delete(True, self.torrent_hash_delete_list)
|
||||
if self.torrent_hash_delete_list:
|
||||
self.qbt_client.torrents_delete(True, self.torrent_hash_delete_list)
|
||||
|
||||
def is_downloading(state):
|
||||
if state == 'downloading':
|
||||
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
python_pushover==0.4
|
||||
qbittorrent_api==2022.5.32
|
Reference in New Issue
Block a user