6 Commits

Author SHA1 Message Date
1a5aee5272 Merge pull request #32 from jonbranan/fix_torrent_count
#31 and lots of other changes
2022-10-01 13:10:11 -05:00
8c32f32c85 #31 and lots of other changes 2022-10-01 13:10:42 -05:00
3556382e62 Merge pull request #30 from jonbranan/fix_preme_logging
#28 #26 #25 lots of changes
2022-10-01 12:34:56 -05:00
adc3825396 #28 #26 #25 lots of changes 2022-10-01 12:21:18 -05:00
70b6b3e96a Merge pull request #29 from jonbranan/add_requirements
added requirements.txt
2022-10-01 10:47:13 -05:00
1fbdd5e84d added requirements.txt 2022-10-01 10:45:19 -05:00
6 changed files with 33 additions and 56 deletions

View File

@ -9,11 +9,11 @@
"non_protected_tag": "public", "non_protected_tag": "public",
"age": 2419200, "age": 2419200,
"minimum_age": 432000, "minimum_age": 432000,
"use_pushover": true, "use_pushover": false,
"use_log": true, "use_log": true,
"po_key": "", "po_key": "",
"po_token": "", "po_token": "",
"delete_torrents": false, "delete_torrents": false,
"enable_dragnet": true, "enable_dragnet": true,
"dragnet_outfile": "./orphaned.csv" "dragnet_outfile": "./dragnet.csv"
} }

View File

@ -1,4 +1,3 @@
#The first file shall contain an client to the qbit api and the processing of the torrents.
import qbittorrentapi import qbittorrentapi
import pushover import pushover
from json import load from json import load
@ -34,7 +33,7 @@ class Qbt:
self.po = pushover self.po = pushover
self.ct = Counter self.ct = Counter
self.cv = csv self.cv = csv
# Variables torlog uses from config.json # Init config.json
self.use_pushover = self.config["use_pushover"] self.use_pushover = self.config["use_pushover"]
self.use_log = self.config["use_log"] self.use_log = self.config["use_log"]
self.po_key = self.config["po_key"] self.po_key = self.config["po_key"]

View File

@ -8,40 +8,37 @@ def build_tor_list(self):
while self.torrent_list: while self.torrent_list:
torrent = self.torrent_list.pop() torrent = self.torrent_list.pop()
if self.use_log: 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']): if is_ignored_tag(self.ignored_tags.values(),torrent['tags']):
self.ignored_counter += 1 self.ignored_counter += 1
self.tl.info(f'Ignored tag: ["{torrent["name"][0:20]}..."] tags: {torrent["tags"]} hash: {torrent["hash"]}')
continue continue
# if torrent['added_on'] + self.minimum_age >= self.t.time():
if is_preme(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.preme_tor_counter += 1
self.tl.debug(f'Premature torrent: ["{torrent["name"][0:20]}..."] hash: {torrent["hash"]}')
continue continue
# if torrent['category'] in self.cat_whitelist.values():
if is_cat_ignored(torrent['category'], 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 self.ignored_counter += 1
continue continue
# if torrent['tracker'] == '':
if is_tracker_blank(torrent['tracker']): if is_tracker_blank(torrent['tracker']):
if self.use_log: if self.use_log:
self.tl.warning(f'Torrent doesn\'t have a tracker ["{torrent["name"][0:20]}..."] [{torrent["tracker"]}]hash: {torrent["hash"]}') self.tl.warning(f'Torrent doesn\'t have a tracker ["{torrent["name"][0:20]}..."] [{torrent["tracker"]}]hash: {torrent["hash"]}')
self.ignored_counter += 1 self.ignored_counter += 1
continue 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): def is_preme(added, minage, time):
if added + minage >= time: if added + minage >= time:
@ -56,10 +53,14 @@ def is_tracker_blank(tracker):
return True return True
def is_protected_tracker(tracker, trackerlist): def is_protected_tracker(tracker, trackerlist):
if tracker == '':
return False
if tracker.split('/')[2] in trackerlist: if tracker.split('/')[2] in trackerlist:
return True return True
def is_not_protected_tracker(tracker, trackerlist): def is_not_protected_tracker(tracker, trackerlist):
if tracker == '':
return False
if tracker.split('/')[2] not in trackerlist: if tracker.split('/')[2] not in trackerlist:
return True return True

View File

@ -42,17 +42,6 @@ def tor_notify_summary(self):
Marked for deletion: {len(self.torrent_hash_delete_list)}\n\ Marked for deletion: {len(self.torrent_hash_delete_list)}\n\
{self.extm}", title="--- qbit-maid summary ---") {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): def list_first_tor(self, index=0):
"""Only lists the first torrent""" """Only lists the first torrent"""
self.tl.debug('First torrent in the list:') self.tl.debug('First torrent in the list:')
@ -68,24 +57,12 @@ def list_qbit_api_info(self):
def torrent_count(self): def torrent_count(self):
"""write torrent counts to log file""" """write torrent counts to log file"""
self.tl.debug(f'torrents that are protected {self.tracker_list.count("ipt")}') self.tl.debug(f'*** Torrents with tag["{self.tracker_protected_tag}"] {self.c[self.tracker_protected_tag]} ***')
self.tl.debug(f'torrents that aren\'t protected {self.tracker_list.count("public")}') self.tl.debug(f'*** Torrents with tag["{self.tracker_non_protected_tag}"] {self.c[self.tracker_non_protected_tag]} ***')
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())
def get_script_runtime(self): def get_script_runtime(self):
elapsed_time = self.et - self.st elapsed_time = self.et - self.st
if self.use_log: if self.use_log:
self.tl.info(f'Execution time: [{elapsed_time}]') self.tl.info(f'Execution time: [{elapsed_time}]')
if self.use_pushover: if self.use_pushover:
self.extm = f"Execution time: [{elapsed_time}]" self.extm = f"Execution time: [{elapsed_time}]"
def getobjecttype(object):
print(type(object))

View File

@ -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 If torrent meets criteria for deletion, its infohash_v1 will be appended to self.torrent_hash_delete_list
""" """
for canidate in self.tracker_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 is_downloading(canidate['state']):
if self.use_log: if self.use_log:
self.tl.info(f'["{canidate["name"][0:20]}..."] is still downloading and will be skipped.') self.tl.info(f'["{canidate["name"][0:20]}..."] is still downloading and will be skipped.')
continue 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"]): elif is_protected_under_ratio(canidate['ratio'], 1.05, self.tracker_protected_tag, 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.age <= self.t.time():
if is_old_tor(canidate['added_on'], self.age, self.t.time()): if is_old_tor(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.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.')
# 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"]): elif is_protected_over_ratio(canidate['ratio'], 1.05, self.tracker_protected_tag, canidate["tags"]):
if self.use_log: if self.use_log:
self.tl.debug(f'["{canidate["name"][0:20]}..."] is above a 1.05 ratio({canidate["ratio"]}).') 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']) 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.')
# elif self.tracker_non_protected_tag in canidate["tags"]:
elif is_not_protected_tor(self.tracker_non_protected_tag, canidate["tags"]): elif is_not_protected_tor(self.tracker_non_protected_tag, canidate["tags"]):
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:
@ -48,7 +45,8 @@ def tor_delete(self):
if self.use_log: if self.use_log:
self.tl.debug('Hash list submitted for deletion:') self.tl.debug('Hash list submitted for deletion:')
self.tl.debug(self.torrent_hash_delete_list) 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): def is_downloading(state):
if state == 'downloading': if state == 'downloading':

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
python_pushover==0.4
qbittorrent_api==2022.5.32