2022-07-29 16:02:19 -05:00
|
|
|
import qbittorrentapi
|
|
|
|
import pushover
|
2022-11-01 15:33:22 -05:00
|
|
|
from tomllib import load
|
2022-07-29 16:02:19 -05:00
|
|
|
from qlist import *
|
|
|
|
from qlogging import *
|
|
|
|
from qprocess import *
|
2023-05-16 22:05:12 -05:00
|
|
|
from AppriseClient import apprise_notify
|
2022-07-29 16:02:19 -05:00
|
|
|
import time
|
2022-08-01 13:01:00 -05:00
|
|
|
import datetime
|
2022-07-29 16:02:19 -05:00
|
|
|
import logging
|
|
|
|
from collections import Counter
|
2022-08-31 10:56:37 -05:00
|
|
|
import csv
|
2023-05-16 22:05:12 -05:00
|
|
|
import requests as r
|
2023-06-04 13:05:26 -05:00
|
|
|
import os
|
2023-06-05 22:42:00 -05:00
|
|
|
|
2022-07-29 16:02:19 -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
|
2022-08-01 13:01:00 -05:00
|
|
|
self.st = datetime.datetime.now()
|
2023-06-04 13:05:26 -05:00
|
|
|
|
2023-06-05 22:42:00 -05:00
|
|
|
if os.getenv("toml_path"):
|
|
|
|
config_file_path=os.getenv("toml_path")
|
|
|
|
with open(config_file_path, 'rb') as c:
|
|
|
|
self.config = load(c)
|
2023-06-04 13:05:26 -05:00
|
|
|
if os.path.exists('./config.toml'):
|
|
|
|
config_file_path = './config.toml'
|
|
|
|
with open(config_file_path, 'rb') as c:
|
|
|
|
self.config = load(c)
|
|
|
|
|
2022-11-01 15:33:22 -05:00
|
|
|
# # Create the api object
|
2022-07-29 16:02:19 -05:00
|
|
|
self.qbt_client = qbittorrentapi.Client(
|
2022-11-01 15:33:22 -05:00
|
|
|
# qbittorrent
|
|
|
|
host=self.config["qbittorrent"]["host"],
|
|
|
|
port=self.config["qbittorrent"]["port"],
|
|
|
|
username=self.config["qbittorrent"]["username"],
|
|
|
|
password=self.config["qbittorrent"]["password"],
|
2022-07-29 16:02:19 -05:00
|
|
|
)
|
|
|
|
# Create the logging and pushover objects
|
|
|
|
self.tl = logging
|
|
|
|
self.po = pushover
|
|
|
|
self.ct = Counter
|
2022-08-31 10:56:37 -05:00
|
|
|
self.cv = csv
|
2022-11-01 15:33:22 -05:00
|
|
|
# Init config.toml
|
|
|
|
|
|
|
|
# logging
|
|
|
|
self.use_log = self.config["logging"]["use_log"]
|
|
|
|
self.log_path = self.config["logging"]["log_path"]
|
|
|
|
self.log_level = self.config["logging"]["log_level"]
|
|
|
|
|
|
|
|
#app_tags
|
|
|
|
self.tracker_protected_tag = self.config["app_tags"]["protected_tag"]
|
|
|
|
self.tracker_non_protected_tag = self.config["app_tags"]["non_protected_tag"]
|
|
|
|
|
|
|
|
#torrent
|
|
|
|
self.delete_torrents = self.config["torrent"]["delete_torrents"]
|
|
|
|
self.minimum_age = self.config["torrent"]["minimum_age"]
|
|
|
|
self.age = self.config["torrent"]["age"]
|
|
|
|
|
|
|
|
#pushover
|
|
|
|
self.use_pushover = self.config["pushover"]["use_pushover"]
|
|
|
|
self.po_key = self.config["pushover"]["po_key"]
|
|
|
|
self.po_token = self.config["pushover"]["po_token"]
|
|
|
|
|
2023-05-16 22:05:12 -05:00
|
|
|
#apprise
|
|
|
|
self.use_apprise = self.config["apprise"]["use_apprise"]
|
|
|
|
self.apprise_host = self.config["apprise"]["host"]
|
|
|
|
self.apprise_port = self.config["apprise"]["port"]
|
|
|
|
self.apprise_aurls = self.config["apprise"]["aurls"]
|
|
|
|
|
2022-11-01 15:33:22 -05:00
|
|
|
#dragnet
|
|
|
|
self.enable_dragnet = self.config["dragnet"]["enable_dragnet"]
|
|
|
|
self.dragnet_outfile = self.config["dragnet"]["dragnet_outfile"]
|
|
|
|
|
|
|
|
#ignored_categories
|
|
|
|
self.cat_whitelist = self.config["ignored_categories"]
|
|
|
|
|
|
|
|
#ignored_domains
|
|
|
|
self.tracker_whitelist = self.config["ignored_domains"]
|
|
|
|
|
|
|
|
#ignored_tags
|
|
|
|
self.ignored_tags = self.config["ignored_domains"]
|
|
|
|
|
2022-07-29 16:02:19 -05:00
|
|
|
# Calling log and notify functions
|
2022-09-03 15:02:40 -05:00
|
|
|
tor_log(self)
|
|
|
|
tor_notify(self)
|
2022-07-29 16:02:19 -05:00
|
|
|
self.t = time
|
|
|
|
# Pulling domain names to treat carefully
|
|
|
|
self.tracker_list = []
|
|
|
|
self.up_tor_counter = 0
|
|
|
|
self.preme_tor_counter = 0
|
|
|
|
self.ignored_counter = 0
|
|
|
|
self.torrent_hash_delete_list = []
|
|
|
|
if self.use_log:
|
|
|
|
self.tl.debug(self.tracker_whitelist)
|
|
|
|
#logging in
|
|
|
|
try:
|
|
|
|
self.tl.info('Connecting to host.')
|
|
|
|
self.qbt_client.auth_log_in()
|
|
|
|
self.tl.info('Connected.')
|
|
|
|
except qbittorrentapi.APIError as e:
|
|
|
|
self.tl.exception(e)
|
2022-08-12 21:30:18 -05:00
|
|
|
self.po.send_message(e, title="qbit-maid API ERROR")
|
2022-07-29 16:02:19 -05:00
|
|
|
# Pulling all torrent data
|
2022-09-03 15:02:40 -05:00
|
|
|
self.torrent_list = self.qbt_client.torrents_info()
|
2022-07-29 16:02:19 -05:00
|
|
|
#Main process block
|
|
|
|
if self.use_log:
|
2022-09-03 15:02:40 -05:00
|
|
|
list_qbit_api_info(self)
|
|
|
|
list_first_tor(self)
|
|
|
|
build_tor_list(self)
|
|
|
|
process_counts(self)
|
2022-10-01 13:10:42 -05:00
|
|
|
if self.use_log:
|
|
|
|
torrent_count(self)
|
2022-09-03 15:02:40 -05:00
|
|
|
tor_processor(self)
|
2022-07-29 16:02:19 -05:00
|
|
|
if self.use_log:
|
2022-09-03 15:02:40 -05:00
|
|
|
print_processor(self)
|
2022-11-01 15:33:22 -05:00
|
|
|
if self.delete_torrents:
|
2022-09-03 15:02:40 -05:00
|
|
|
tor_delete(self)
|
2022-08-01 13:01:00 -05:00
|
|
|
self.et = datetime.datetime.now()
|
2022-09-03 15:02:40 -05:00
|
|
|
get_script_runtime(self)
|
2022-08-01 13:01:00 -05:00
|
|
|
if self.use_pushover:
|
2022-09-03 15:02:40 -05:00
|
|
|
tor_notify_summary(self)
|
2023-05-16 22:05:12 -05:00
|
|
|
if self.use_apprise:
|
|
|
|
tor_notify_apprise(self, r, apprise_notify)
|
2022-07-29 16:02:19 -05:00
|
|
|
# Run
|
|
|
|
if __name__== "__main__":
|
2022-07-14 19:03:06 -05:00
|
|
|
Qbt()
|