mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-09 13:29:15 +08:00
commit
e7b113d29c
4 changed files with 38 additions and 10 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
3.1.4
|
3.1.5
|
|
@ -293,9 +293,10 @@ class Config:
|
||||||
if "cat" in self.data and self.data["cat"] is not None:
|
if "cat" in self.data and self.data["cat"] is not None:
|
||||||
cat_path = self.data["cat"]
|
cat_path = self.data["cat"]
|
||||||
for cat, save_path in cat_path.items():
|
for cat, save_path in cat_path.items():
|
||||||
if save_path in path:
|
if os.path.join(save_path, '') == path:
|
||||||
category = cat
|
category = cat
|
||||||
break
|
break
|
||||||
|
|
||||||
if not category:
|
if not category:
|
||||||
default_cat = path.split('/')[-2]
|
default_cat = path.split('/')[-2]
|
||||||
category = str(default_cat)
|
category = str(default_cat)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import logging, os
|
import logging, os, sys
|
||||||
from qbittorrentapi import Client, LoginFailed, APIConnectionError, NotFound404Error
|
from qbittorrentapi import Client, LoginFailed, APIConnectionError, NotFound404Error, Conflict409Error
|
||||||
from modules import util
|
from modules import util
|
||||||
from modules.util import Failed, print_line, print_multiline, separator
|
from modules.util import Failed, print_line, print_multiline, separator
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
@ -11,6 +11,8 @@ logger = logging.getLogger("qBit Manage")
|
||||||
|
|
||||||
|
|
||||||
class Qbt:
|
class Qbt:
|
||||||
|
SUPPORTED_VERSION = 'v4.3'
|
||||||
|
|
||||||
def __init__(self, config, params):
|
def __init__(self, config, params):
|
||||||
self.config = config
|
self.config = config
|
||||||
config_handler.set_global(bar=None, receipt_text=False)
|
config_handler.set_global(bar=None, receipt_text=False)
|
||||||
|
@ -21,13 +23,28 @@ class Qbt:
|
||||||
try:
|
try:
|
||||||
self.client = Client(host=self.host, username=self.username, password=self.password)
|
self.client = Client(host=self.host, username=self.username, password=self.password)
|
||||||
self.client.auth_log_in()
|
self.client.auth_log_in()
|
||||||
|
logger.debug(f'qBittorrent: {self.client.app.version}')
|
||||||
|
logger.debug(f'qBittorrent Web API: {self.client.app.web_api_version}')
|
||||||
|
logger.debug(f'qbit_manage support version: {self.SUPPORTED_VERSION}')
|
||||||
|
current_version = ".".join(self.client.app.version.split(".")[:2])
|
||||||
|
if current_version > self.SUPPORTED_VERSION:
|
||||||
|
e = f"Qbittorrent Error: qbit_manage is only comaptible with {self.SUPPORTED_VERSION}.* or lower. You are currently on {self.client.app.version}"
|
||||||
|
self.config.notify(e, "Qbittorrent")
|
||||||
|
print_line(e, 'CRITICAL')
|
||||||
|
sys.exit(0)
|
||||||
logger.info("Qbt Connection Successful")
|
logger.info("Qbt Connection Successful")
|
||||||
except LoginFailed:
|
except LoginFailed:
|
||||||
raise Failed("Qbittorrent Error: Failed to login. Invalid username/password.")
|
e = "Qbittorrent Error: Failed to login. Invalid username/password."
|
||||||
|
self.config.notify(e, "Qbittorrent")
|
||||||
|
raise Failed(e)
|
||||||
except APIConnectionError:
|
except APIConnectionError:
|
||||||
raise Failed("Qbittorrent Error: Unable to connect to the client.")
|
e = "Qbittorrent Error: Unable to connect to the client."
|
||||||
|
self.config.notify(e, "Qbittorrent")
|
||||||
|
raise Failed(e)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise Failed("Qbittorrent Error: Unable to connect to the client.")
|
e = "Qbittorrent Error: Unable to connect to the client."
|
||||||
|
self.config.notify(e, "Qbittorrent")
|
||||||
|
raise Failed(e)
|
||||||
separator("Getting Torrent List", space=False, border=False)
|
separator("Getting Torrent List", space=False, border=False)
|
||||||
self.torrent_list = self.get_torrents({'sort': 'added_on'})
|
self.torrent_list = self.get_torrents({'sort': 'added_on'})
|
||||||
|
|
||||||
|
@ -132,7 +149,14 @@ class Qbt:
|
||||||
if torrent.category == '':
|
if torrent.category == '':
|
||||||
new_cat = self.config.get_category(torrent.save_path)
|
new_cat = self.config.get_category(torrent.save_path)
|
||||||
tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith('http')])
|
tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith('http')])
|
||||||
if not dry_run: torrent.set_category(category=new_cat)
|
if not dry_run:
|
||||||
|
try:
|
||||||
|
torrent.set_category(category=new_cat)
|
||||||
|
except Conflict409Error:
|
||||||
|
e = print_line(f'Existing category "{new_cat}" not found for save path {torrent.save_path}, category will be created.', loglevel)
|
||||||
|
self.config.notify(e, 'Update Category', False)
|
||||||
|
self.client.torrent_categories.create_category(name=new_cat, save_path=torrent.save_path)
|
||||||
|
torrent.set_category(category=new_cat)
|
||||||
body = []
|
body = []
|
||||||
body += print_line(util.insert_space(f'Torrent Name: {torrent.name}', 3), loglevel)
|
body += print_line(util.insert_space(f'Torrent Name: {torrent.name}', 3), loglevel)
|
||||||
body += print_line(util.insert_space(f'New Category: {new_cat}', 3), loglevel)
|
body += print_line(util.insert_space(f'New Category: {new_cat}', 3), loglevel)
|
||||||
|
@ -416,6 +440,9 @@ class Qbt:
|
||||||
'RETITLED',
|
'RETITLED',
|
||||||
'TRUNCATED'
|
'TRUNCATED'
|
||||||
]
|
]
|
||||||
|
ignore_msgs = [
|
||||||
|
'YOU HAVE REACHED THE CLIENT LIMIT FOR THIS TORRENT'
|
||||||
|
]
|
||||||
for torrent in self.torrentvalid:
|
for torrent in self.torrentvalid:
|
||||||
check_tags = util.get_list(torrent.tags)
|
check_tags = util.get_list(torrent.tags)
|
||||||
# Remove any potential unregistered torrents Tags that are no longer unreachable.
|
# Remove any potential unregistered torrents Tags that are no longer unreachable.
|
||||||
|
@ -436,7 +463,7 @@ class Qbt:
|
||||||
# Tag any potential unregistered torrents
|
# Tag any potential unregistered torrents
|
||||||
if not any(m in msg_up for m in unreg_msgs) and x.status == 4 and 'issue' not in check_tags:
|
if not any(m in msg_up for m in unreg_msgs) and x.status == 4 and 'issue' not in check_tags:
|
||||||
# Check for unregistered torrents using BHD API if the tracker is BHD
|
# Check for unregistered torrents using BHD API if the tracker is BHD
|
||||||
if 'tracker.beyond-hd.me' in tracker['url'] and self.config.BeyondHD is not None:
|
if 'tracker.beyond-hd.me' in tracker['url'] and self.config.BeyondHD is not None and all(x not in msg_up for x in ignore_msgs):
|
||||||
json = {"info_hash": torrent.hash}
|
json = {"info_hash": torrent.hash}
|
||||||
response = self.config.BeyondHD.search(json)
|
response = self.config.BeyondHD.search(json)
|
||||||
if response['total_results'] <= 1:
|
if response['total_results'] <= 1:
|
||||||
|
|
|
@ -3,4 +3,4 @@ qbittorrent-api==2021.12.26
|
||||||
schedule==1.1.0
|
schedule==1.1.0
|
||||||
retrying==1.3.3
|
retrying==1.3.3
|
||||||
alive_progress==2.1.0
|
alive_progress==2.1.0
|
||||||
requests==2.27.0
|
requests==2.27.1
|
Loading…
Add table
Reference in a new issue