qbit-maid/qbit-maid.py

85 lines
3.0 KiB
Python
Raw Normal View History

2022-07-14 19:03:06 -05:00
#The first file shall contain an client to the qbit api and the processing of the torrents.
import qbittorrentapi
2022-07-20 09:57:22 -05:00
import pushover
2022-07-14 19:03:06 -05:00
from json import load
from qlist import *
from qlogging import *
from qprocess import *
import time
import logging
from collections import Counter
2022-07-14 19:03:06 -05:00
class Qbt:
def __init__(self):
"""Main object, should be calling functions from qlist.py, qlogging.py and qprocess.py"""
# Open the config. Needs a json file with the data in config.json.example
c = open('./config.json')
self.config = load(c)
2022-07-23 00:42:05 -05:00
w = open('./category-whitelist.json')
2022-07-22 23:46:48 -05:00
self.cat_whitelist = load(w)
2022-07-14 19:03:06 -05:00
# Create the api object
self.qbt_client = qbittorrentapi.Client(
host=self.config["host"],
port=self.config["port"],
username=self.config["username"],
password=self.config["password"],
)
2022-07-20 11:34:13 -05:00
# Create the logging and pushover objects
2022-07-14 19:03:06 -05:00
self.tl = logging
2022-07-20 09:57:22 -05:00
self.po = pushover
self.ct = Counter
2022-07-20 11:34:13 -05:00
# Variables torlog uses from config.json
self.use_pushover = self.config["use_pushover"]
self.use_log = self.config["use_log"]
self.po_key = self.config["po_key"]
self.po_token = self.config["po_token"]
self.logpath = self.config["logpath"]
self.loglevel = self.config["loglevel"]
2022-07-22 15:01:46 -05:00
self.tracker_protected_tag = self.config["protected_tag"]
self.tracker_non_protected_tag = self.config["non_protected_tag"]
self.minimum_age = self.config["minimum_age"]
self.age = self.config["age"]
2022-07-20 11:34:13 -05:00
# Calling log and notify functions
2022-07-14 19:03:06 -05:00
torlog(self)
2022-07-20 09:57:22 -05:00
tornotify(self)
2022-07-14 19:03:06 -05:00
self.t = time
2022-07-20 11:34:13 -05:00
# Pulling domain names to treat carefully
2022-07-14 19:03:06 -05:00
f = open('./tracker-whitelist.json')
self.tracker_whitelist = load(f)
self.tracker_list = []
self.up_tor_counter = 0
self.preme_tor_counter = 0
2022-07-23 16:05:57 -05:00
self.ignored_counter = 0
2022-07-14 19:03:06 -05:00
self.torrent_hash_delete_list = []
if self.use_log:
self.tl.debug(self.tracker_whitelist)
2022-07-20 11:34:13 -05:00
#logging in
2022-07-14 19:03:06 -05:00
try:
self.tl.info('Connecting to host.')
self.qbt_client.auth_log_in()
self.tl.info('Connected.')
except qbittorrentapi.APIError as e:
2022-07-14 19:03:06 -05:00
self.tl.exception(e)
self.poc.send_message(e, title="qbit-maid API ERROR")
2022-07-14 19:03:06 -05:00
self.torrentlist = {}
2022-07-20 11:34:13 -05:00
# Pulling all torrent data
2022-07-14 19:03:06 -05:00
self.torrentlist = self.qbt_client.torrents_info()
2022-07-20 11:34:13 -05:00
#Main process block
if self.use_log:
listqbitapiinfo(self)
listfirsttor(self)
2022-07-14 19:03:06 -05:00
buildtorlist(self)
2022-07-22 17:24:27 -05:00
#tordeletetags(self)
if self.use_log:
torrentcount(self)
2022-07-14 19:03:06 -05:00
torprocessor(self)
if self.use_log:
printprocessor(self)
if self.use_pushover:
tornotifysummary(self)
if self.config["delete_torrents"]:
tordelete(self)
2022-07-22 17:24:27 -05:00
2022-07-20 11:34:13 -05:00
# Run
2022-07-14 19:03:06 -05:00
if __name__== "__main__":
Qbt()