From 7fb6870faac1acf243b98512bde4b0936f213d55 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 22 Jan 2019 19:57:27 +0800 Subject: [PATCH] update --- plugins/qbittorrent/conf/qb.conf | 2 +- plugins/qbittorrent/index.html | 1 + plugins/qbittorrent/init.d/qbittorrent.tpl | 5 ++- plugins/qbittorrent/qb.conf | 12 ++++++ plugins/qbittorrent/workers/dl_worker.py | 65 ++++++++++++++++++++++++------ 5 files changed, 69 insertions(+), 16 deletions(-) create mode 100755 plugins/qbittorrent/qb.conf diff --git a/plugins/qbittorrent/conf/qb.conf b/plugins/qbittorrent/conf/qb.conf index b29646350..b49c3f8f4 100755 --- a/plugins/qbittorrent/conf/qb.conf +++ b/plugins/qbittorrent/conf/qb.conf @@ -1,7 +1,7 @@ [db] DB_HOST = 127.0.0.1 -DB_USER = qbittorrent DB_PORT = 3306 +DB_USER = qbittorrent DB_PASS = qbittorrent DB_NAME = qbittorrent diff --git a/plugins/qbittorrent/index.html b/plugins/qbittorrent/index.html index 6b210a093..f9000af1d 100755 --- a/plugins/qbittorrent/index.html +++ b/plugins/qbittorrent/index.html @@ -5,6 +5,7 @@

自启动

导入SQL

配置

+

日志

diff --git a/plugins/qbittorrent/init.d/qbittorrent.tpl b/plugins/qbittorrent/init.d/qbittorrent.tpl index 5f0d5e5a6..1e2ca0672 100644 --- a/plugins/qbittorrent/init.d/qbittorrent.tpl +++ b/plugins/qbittorrent/init.d/qbittorrent.tpl @@ -15,12 +15,13 @@ qb_start(){ cd {$SERVER_PATH}/qbittorrent/workers - nohup python simdht_worker.py > {$SERVER_PATH}/qbittorrent/logs.pl 2>&1 & + nohup python dl_worker.py > {$SERVER_PATH}/qbittorrent/logs.pl 2>&1 & } qb_stop(){ echo "Stopping ..." - ps -ef | grep qbittorrent-nox-bin | grep -v grep | awk '{print $2}' | xargs kill + #ps -ef | grep qbittorrent-nox-bin | grep -v grep | awk '{print $2}' | xargs kill + ps -ef | grep "python dl_worker.py" | grep -v grep | awk '{print $2}' | xargs kill echo "Redis stopped" } diff --git a/plugins/qbittorrent/qb.conf b/plugins/qbittorrent/qb.conf new file mode 100755 index 000000000..ffaf85283 --- /dev/null +++ b/plugins/qbittorrent/qb.conf @@ -0,0 +1,12 @@ +[db] +DB_HOST = 127.0.0.1 +DB_PORT = 3306 +DB_USER = qbittorrent +DB_PASS = qbittorrent +DB_NAME = qbittorrent + +[qb] +QB_HOST = 127.0.0.1 +QB_PORT = 8081 +QB_USER = admin +QB_PWD = adminadmin diff --git a/plugins/qbittorrent/workers/dl_worker.py b/plugins/qbittorrent/workers/dl_worker.py index 90d2fa651..6b582d8b3 100755 --- a/plugins/qbittorrent/workers/dl_worker.py +++ b/plugins/qbittorrent/workers/dl_worker.py @@ -32,15 +32,53 @@ sys.path.append('/usr/local/lib/python2.7/site-packages') import MySQLdb as mdb -# from configparser import ConfigParser -# cp = ConfigParser() -# cp.read("../db.cfg") -# section_db = cp.sections()[0] -# DB_HOST = cp.get(section_db, "DB_HOST") -# DB_USER = cp.get(section_db, "DB_USER") -# DB_PORT = cp.getint(section_db, "DB_PORT") -# DB_PASS = cp.get(section_db, "DB_PASS") -# DB_NAME = cp.get(section_db, "DB_NAME") +from configparser import ConfigParser +cp = ConfigParser() +cp.read("../qb.conf") +section_db = cp.sections()[0] +DB_HOST = cp.get(section_db, "DB_HOST") +DB_USER = cp.get(section_db, "DB_USER") +DB_PORT = cp.getint(section_db, "DB_PORT") +DB_PASS = cp.get(section_db, "DB_PASS") +DB_NAME = cp.get(section_db, "DB_NAME") + + +section_qb = cp.sections()[1] +QB_HOST = cp.get(section_qb, "QB_HOST") +QB_PORT = cp.get(section_qb, "QB_PORT") +QB_USER = cp.get(section_qb, "QB_USER") +QB_PWD = cp.get(section_qb, "QB_PWD") + + +class downloadBT(Thread): + + def __init__(self): + Thread.__init__(self) + self.setDaemon(True) + self.dbconn = mdb.connect( + DB_HOST, DB_USER, DB_PASS, DB_NAME, port=DB_PORT, charset='utf8') + self.dbconn.autocommit(False) + self.dbcurr = self.dbconn.cursor() + self.dbcurr.execute('SET NAMES utf8') + self.qb = self.qb() + + def query(self, sql): + self.dbcurr.execute(sql) + result = self.dbcurr.fetchall() + data = map(list, result) + return data + + def qb(self): + from qbittorrent import Client + url = 'http://' + QB_HOST + ':' + QB_PORT + '/' + qb = Client(url) + qb.login(QB_USER, QB_PWD) + return qb + + def proccess(self): + while True: + print 123123 + time.sleep(1) def checkDL(): @@ -51,9 +89,10 @@ def checkDL(): if __name__ == "__main__": - # import threading - # t = threading.Thread(target=checkDL) - # t.setDaemon(True) - # t.start() + dl = downloadBT() + + import threading + t = threading.Thread(target=dl.proccess) + t.start() checkDL()