| @@ -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"] | ||||
| @@ -77,8 +76,8 @@ class Qbt: | ||||
|             list_first_tor(self) | ||||
|         build_tor_list(self) | ||||
|         process_counts(self) | ||||
|         if self.use_log: | ||||
|             torrent_count(self) | ||||
|         # if self.use_log: | ||||
|         #     torrent_count(self) | ||||
|         tor_processor(self) | ||||
|         if self.use_log: | ||||
|             print_processor(self) | ||||
|   | ||||
							
								
								
									
										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 | ||||
|  | ||||
|   | ||||
| @@ -68,6 +68,7 @@ def list_qbit_api_info(self): | ||||
|  | ||||
| def torrent_count(self): | ||||
|     """write torrent counts to log file""" | ||||
|     #Doesn't work because tracker_list doesn't have a count property. Each object does. List comprehension? | ||||
|     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")}') | ||||
|  | ||||
|   | ||||
| @@ -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:    | ||||
|   | ||||
		Reference in New Issue
	
	Block a user