2023-10-30 22:02:43 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -- coding: utf-8 --
|
|
|
|
|
2023-10-30 23:37:37 +00:00
|
|
|
import db, os
|
2023-10-30 22:02:43 +00:00
|
|
|
from db import *
|
2023-10-31 22:49:17 +00:00
|
|
|
from lang import LANG as msg
|
2023-10-30 22:02:43 +00:00
|
|
|
|
2023-10-31 00:45:12 +00:00
|
|
|
def qbt():
|
|
|
|
url = os.environ['QURL']
|
|
|
|
username = os.environ['QUSER']
|
|
|
|
password = os.environ['QPASS']
|
|
|
|
commands = [
|
|
|
|
f"qbt settings set url {url}",
|
|
|
|
f"qbt settings set username {username}",
|
|
|
|
f"echo {password} | qbt settings set password --no-warn"
|
|
|
|
]
|
|
|
|
for command in commands:
|
|
|
|
os.system(f"bash -c '{command}'")
|
|
|
|
|
2023-10-30 22:02:43 +00:00
|
|
|
def u_auth(id,passwd):
|
|
|
|
list = []
|
|
|
|
if db.check('obj',AUTH_FILE):
|
|
|
|
list = db.read(AUTH_FILE)
|
|
|
|
if id in list:
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('alauth')
|
2023-10-30 22:02:43 +00:00
|
|
|
else:
|
|
|
|
if passwd == os.environ['PASS']:
|
|
|
|
list.append(id)
|
|
|
|
db.write(list,AUTH_FILE)
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('sucauth')
|
2023-10-30 22:02:43 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('wrauth')
|
2023-10-30 22:02:43 +00:00
|
|
|
|
|
|
|
def auth_check(id):
|
|
|
|
if db.check('obj',AUTH_FILE):
|
|
|
|
list = db.read(AUTH_FILE)
|
|
|
|
else:
|
|
|
|
list = []
|
|
|
|
if id in list:
|
|
|
|
return True
|
|
|
|
|
|
|
|
def add_dir(id,dir,path):
|
|
|
|
if auth_check(id):
|
|
|
|
if os.path.exists(path) == False:
|
2023-10-31 22:49:17 +00:00
|
|
|
return str(msg.get('pne')).format(path)
|
2023-10-30 22:02:43 +00:00
|
|
|
if db.check('obj',DIR_FILE):
|
|
|
|
dict = db.read(DIR_FILE)
|
|
|
|
else:
|
|
|
|
dict = {}
|
|
|
|
dict.setdefault(dir,path)
|
|
|
|
db.write(dict,DIR_FILE)
|
2023-10-31 22:49:17 +00:00
|
|
|
return str(msg.get('fsa')).format(dir)
|
2023-10-30 22:02:43 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('adeny')
|
2023-10-30 22:02:43 +00:00
|
|
|
|
|
|
|
def del_dir(id,dir):
|
|
|
|
if auth_check(id):
|
|
|
|
if db.check('obj',DIR_FILE):
|
|
|
|
dict = db.read(DIR_FILE)
|
|
|
|
else:
|
|
|
|
dict = {}
|
|
|
|
if dir in dict:
|
|
|
|
del dict[dir]
|
|
|
|
db.write(dict,DIR_FILE)
|
2023-10-31 22:49:17 +00:00
|
|
|
return str(msg.get('frm')).format(dir)
|
2023-10-30 22:02:43 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
return str(msg.get('fne')).format(dir)
|
2023-10-30 22:02:43 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('adeny')
|
2023-10-30 22:02:43 +00:00
|
|
|
|
|
|
|
def magnet(id,link,dir):
|
|
|
|
if auth_check(id):
|
2023-10-30 23:03:14 +00:00
|
|
|
dict = db.read(DIR_FILE)
|
|
|
|
path = dict[dir]
|
2023-10-31 22:49:17 +00:00
|
|
|
command = f'''qbt torrent add url "{link}" -f "{path}"'''
|
2023-10-30 23:03:14 +00:00
|
|
|
os.system(f"bash -c '{command}'")
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('add')
|
2023-10-30 23:03:14 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('adeny')
|
2023-10-30 22:02:43 +00:00
|
|
|
|
|
|
|
def file(id,file,dir):
|
|
|
|
if auth_check(id):
|
2023-10-30 23:37:37 +00:00
|
|
|
dict = db.read(DIR_FILE)
|
|
|
|
path = dict[dir]
|
|
|
|
command = f'''qbt torrent add file "{file}" -f {path}'''
|
|
|
|
os.system(f"bash -c '{command}'")
|
|
|
|
os.remove(file)
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('add')
|
2023-10-30 23:37:37 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
return msg.get('adeny')
|
2023-10-30 22:02:43 +00:00
|
|
|
|
|
|
|
def dirlist():
|
|
|
|
dirs = {}
|
|
|
|
if db.check('obj',DIR_FILE):
|
|
|
|
dirs = db.read(DIR_FILE)
|
|
|
|
return dirs
|