Added comments for the functions
This commit is contained in:
parent
1375bc36ce
commit
08cbf7f445
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
qbit-maid.py
11
qbit-maid.py
@ -21,28 +21,32 @@ class Qbt:
|
|||||||
username=self.config["username"],
|
username=self.config["username"],
|
||||||
password=self.config["password"],
|
password=self.config["password"],
|
||||||
)
|
)
|
||||||
# Create the logging object
|
# Create the logging and pushover objects
|
||||||
self.tl = logging
|
self.tl = logging
|
||||||
self.po = pushover
|
self.po = pushover
|
||||||
|
# Variables torlog uses from 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"]
|
||||||
self.po_token = self.config["po_token"]
|
self.po_token = self.config["po_token"]
|
||||||
# Variables torlog uses from config.json
|
|
||||||
self.logpath = self.config["logpath"]
|
self.logpath = self.config["logpath"]
|
||||||
self.loglevel = self.config["loglevel"]
|
self.loglevel = self.config["loglevel"]
|
||||||
|
# Calling log and notify functions
|
||||||
torlog(self)
|
torlog(self)
|
||||||
tornotify(self)
|
tornotify(self)
|
||||||
self.t = time
|
self.t = time
|
||||||
|
# Pulling domain names to treat carefully
|
||||||
f = open('./tracker-whitelist.json')
|
f = open('./tracker-whitelist.json')
|
||||||
self.tracker_whitelist = load(f)
|
self.tracker_whitelist = load(f)
|
||||||
self.tracker_protected_list = []
|
self.tracker_protected_list = []
|
||||||
self.tracker_nonprotected_list = []
|
self.tracker_nonprotected_list = []
|
||||||
|
# Setting values of the tags
|
||||||
self.tracker_protected_tag = 'ipt'
|
self.tracker_protected_tag = 'ipt'
|
||||||
self.tracker_non_protected_tag = 'public'
|
self.tracker_non_protected_tag = 'public'
|
||||||
self.torrent_hash_delete_list = []
|
self.torrent_hash_delete_list = []
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
self.tl.debug(self.tracker_whitelist)
|
self.tl.debug(self.tracker_whitelist)
|
||||||
|
#logging in
|
||||||
try:
|
try:
|
||||||
self.tl.info('Connecting to host.')
|
self.tl.info('Connecting to host.')
|
||||||
self.qbt_client.auth_log_in()
|
self.qbt_client.auth_log_in()
|
||||||
@ -51,7 +55,9 @@ class Qbt:
|
|||||||
self.tl.exception(e)
|
self.tl.exception(e)
|
||||||
self.poc.send_message(e, title="qbit-maid API ERROR")
|
self.poc.send_message(e, title="qbit-maid API ERROR")
|
||||||
self.torrentlist = {}
|
self.torrentlist = {}
|
||||||
|
# Pulling all torrent data
|
||||||
self.torrentlist = self.qbt_client.torrents_info()
|
self.torrentlist = self.qbt_client.torrents_info()
|
||||||
|
#Main process block
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
listqbitapiinfo(self)
|
listqbitapiinfo(self)
|
||||||
listfirsttor(self)
|
listfirsttor(self)
|
||||||
@ -65,5 +71,6 @@ class Qbt:
|
|||||||
tornotifysummary(self)
|
tornotifysummary(self)
|
||||||
tordelete(self)
|
tordelete(self)
|
||||||
|
|
||||||
|
# Run
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
Qbt()
|
Qbt()
|
10
qlist.py
10
qlist.py
@ -1,6 +1,10 @@
|
|||||||
#The second file shall contain functions to build out a list of torrents.
|
#The second file shall contain functions to build out a list of torrents.
|
||||||
def buildtorlist(self):
|
def buildtorlist(self):
|
||||||
"""builds multiple lists of torrents to be sorted."""
|
"""Builds multiple lists of torrents to be sorted. Also adds tags to the torents.
|
||||||
|
There are more effecient ways of doing things but I did this rather quickly.
|
||||||
|
V2 will certainly be more performant. The reason two lists were used was so that torrents
|
||||||
|
that are in public trackers woudln't be around as long as torrents from a private tracker.
|
||||||
|
"""
|
||||||
self.protected_count = 0
|
self.protected_count = 0
|
||||||
self.nonprotected_count = 0
|
self.nonprotected_count = 0
|
||||||
while self.torrentlist:
|
while self.torrentlist:
|
||||||
@ -37,6 +41,9 @@ def buildtorlist(self):
|
|||||||
self.tracker_nonprotected_list.append(torrent)
|
self.tracker_nonprotected_list.append(torrent)
|
||||||
|
|
||||||
def writetor(self, filepath='./torrentinfo.txt'):
|
def writetor(self, filepath='./torrentinfo.txt'):
|
||||||
|
"""Write all torrent data to a file.
|
||||||
|
Useful for development of new features.
|
||||||
|
"""
|
||||||
with open(filepath, 'w') as fp:
|
with open(filepath, 'w') as fp:
|
||||||
fp.write(str(self.torrentlist))
|
fp.write(str(self.torrentlist))
|
||||||
|
|
||||||
@ -54,5 +61,6 @@ def listqbitapiinfo(self):
|
|||||||
self.tl.debug(f'qBittorrent Web API: {self.qbt_client.app.web_api_version}')
|
self.tl.debug(f'qBittorrent Web API: {self.qbt_client.app.web_api_version}')
|
||||||
|
|
||||||
def torrentcount(self):
|
def torrentcount(self):
|
||||||
|
"""write torrent counts to log file"""
|
||||||
self.tl.debug(f'torrents that are protected {self.protected_count}')
|
self.tl.debug(f'torrents that are protected {self.protected_count}')
|
||||||
self.tl.debug(f"torrents that aren't protected {self.nonprotected_count}")
|
self.tl.debug(f"torrents that aren't protected {self.nonprotected_count}")
|
@ -1,6 +1,7 @@
|
|||||||
#The third file shall contain logging and email communication.
|
#The third file shall contain logging and email communication.
|
||||||
|
|
||||||
def torlog(self):
|
def torlog(self):
|
||||||
|
"""Setting up the log file, if self.use_log is set to true and self.loglevel is DEBUG OR INFO"""
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
if self.loglevel == 'DEBUG':
|
if self.loglevel == 'DEBUG':
|
||||||
self.tl.basicConfig(filename=self.logpath, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.DEBUG)
|
self.tl.basicConfig(filename=self.logpath, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.DEBUG)
|
||||||
@ -8,18 +9,22 @@ def torlog(self):
|
|||||||
self.tl.basicConfig(filename=self.logpath, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.INFO)
|
self.tl.basicConfig(filename=self.logpath, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.INFO)
|
||||||
|
|
||||||
def tornotify(self):
|
def tornotify(self):
|
||||||
|
"""Seting up to use pushover, if self.use_pushover is set to true and
|
||||||
|
if valid self.po_key and self.po_token is provided in the config file"""
|
||||||
if self.use_pushover:
|
if self.use_pushover:
|
||||||
self.poc = self.po.Client(self.po_key, api_token=self.po_token)
|
self.poc = self.po.Client(self.po_key, api_token=self.po_token)
|
||||||
|
|
||||||
def tornotifytest(self):
|
def tornotifytest(self):
|
||||||
|
"""Used to make sure tornotify is working and messages are getting to the client"""
|
||||||
self.poc.send_message("Test Message", title="qbit-maid")
|
self.poc.send_message("Test Message", title="qbit-maid")
|
||||||
|
|
||||||
def tornotifysummary(self):
|
def tornotifysummary(self):
|
||||||
|
"""Main notification method when the app is used in an automated fashion"""
|
||||||
self.poc.send_message(f' Protected torrents: {len(self.tracker_protected_list)}\n\
|
self.poc.send_message(f' Protected torrents: {len(self.tracker_protected_list)}\n\
|
||||||
Non-protected torrents: {len(self.tracker_nonprotected_list)}\n\
|
Non-protected torrents: {len(self.tracker_nonprotected_list)}\n\
|
||||||
Total torrents set for deletion: {len(self.torrent_hash_delete_list)}', title="qbit-maid summary")
|
Total torrents set for deletion: {len(self.torrent_hash_delete_list)}', title="qbit-maid summary")
|
||||||
|
|
||||||
|
|
||||||
def getunixtimestamp(self):
|
def getunixtimestamp(self):
|
||||||
|
"""Used for debuging and development related to unixtimestamps, not used in main script but useful"""
|
||||||
self.uts = self.t.time()
|
self.uts = self.t.time()
|
||||||
self.tl.info(self.uts)
|
self.tl.info(self.uts)
|
@ -1,5 +1,8 @@
|
|||||||
#The fourth file shall be logic to process torrents.
|
#The fourth file shall be logic to process torrents.
|
||||||
def torprocessor(self):
|
def torprocessor(self):
|
||||||
|
"""Main logic to sort through both self.tracker_nonprotected_list and self.tracker_protected_list
|
||||||
|
If torrent meets criteria for deletion, its infohash_v1 will be appended to self.torrent_hash_delete_list
|
||||||
|
"""
|
||||||
for canidate in self.tracker_nonprotected_list:
|
for canidate in self.tracker_nonprotected_list:
|
||||||
if 'ipt' in canidate['tags']:
|
if 'ipt' in canidate['tags']:
|
||||||
if self.use_log:
|
if self.use_log:
|
||||||
@ -37,12 +40,15 @@ def torprocessor(self):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def printprocessor(self):
|
def printprocessor(self):
|
||||||
|
"""Print summary of torrents"""
|
||||||
self.tl.info(f'Protected torrents: {len(self.tracker_protected_list)}')
|
self.tl.info(f'Protected torrents: {len(self.tracker_protected_list)}')
|
||||||
self.tl.info(f'Non-protected torrents: {len(self.tracker_nonprotected_list)}')
|
self.tl.info(f'Non-protected torrents: {len(self.tracker_nonprotected_list)}')
|
||||||
self.tl.info(f'Total torrents set for deletion: {len(self.torrent_hash_delete_list)}')
|
self.tl.info(f'Total torrents set for deletion: {len(self.torrent_hash_delete_list)}')
|
||||||
|
|
||||||
def tordelete(self):
|
def tordelete(self):
|
||||||
|
"""Remove torrents, will also delete files, this keeps the filesystem clean.
|
||||||
|
Only pass self.torrent_hash_delete_list if you would like to keep the files."""
|
||||||
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)
|
self.qbt_client.torrents_delete(True, self.torrent_hash_delete_list)
|
Loading…
x
Reference in New Issue
Block a user