From dfdeef8f4c48dd6a16d14be773d52e988d6b18d5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 24 Jan 2019 13:46:43 +0800 Subject: [PATCH] update --- plugins/qbittorrent/index.html | 1 + plugins/qbittorrent/index.py | 33 ++- plugins/qbittorrent/js/qbittorrent.js | 280 +++++--------------------- plugins/qbittorrent/qb.conf | 2 +- 4 files changed, 76 insertions(+), 240 deletions(-) diff --git a/plugins/qbittorrent/index.html b/plugins/qbittorrent/index.html index c05f1b6ac..17931bd32 100755 --- a/plugins/qbittorrent/index.html +++ b/plugins/qbittorrent/index.html @@ -6,6 +6,7 @@

导入SQL

配置

日志

+

列表

diff --git a/plugins/qbittorrent/index.py b/plugins/qbittorrent/index.py index 0a198832c..44d57e69f 100755 --- a/plugins/qbittorrent/index.py +++ b/plugins/qbittorrent/index.py @@ -10,6 +10,11 @@ import sys sys.path.append(os.getcwd() + "/class/core") import public +reload(sys) +sys.setdefaultencoding("utf8") + +sys.path.append('/usr/local/lib/python2.7/site-packages') + app_debug = False if public.isAppleSystem(): @@ -199,6 +204,17 @@ def getDbConfInfo(): return data +def getQbConf(): + cfg = getConf() + content = public.readFile(cfg) + data = {} + data['QB_HOST'] = matchData("QB_HOST\s*=\s(.*)", content) + data['QB_PORT'] = matchData("QB_PORT\s*=\s(.*)", content) + data['QB_USER'] = matchData("QB_USER\s*=\s(.*)", content) + data['QB_PWD'] = matchData("QB_PWD\s*=\s(.*)", content) + return data + + def pMysqlDb(): data = getDbConfInfo() conn = mysql.mysql() @@ -212,13 +228,20 @@ def pMysqlDb(): def pQbClient(): from qbittorrent import Client - qb = Client('http://154.48.251.71:8080/') - qb.login('admin', 'adminadmin') + info = getQbConf() + url = 'http://' + info['QB_HOST'] + ':' + info['QB_PORT'] + '/' + qb = Client(url) + qb.login(info['QB_USER'], info['QB_PWD']) return qb def qbList(): - return '' + try: + qb = pQbClient() + torrents = qb.torrents() + return public.returnJson(True, 'ok', torrents) + except Exception as e: + return public.returnJson(False, str(e)) def test(): @@ -253,8 +276,8 @@ if __name__ == "__main__": print getConf() elif func == 'get_run_Log': print getRunLog() - elif func == 'get_trend_data': - print getTrendData() + elif func == 'qb_list': + print qbList() elif func == 'test': print test() else: diff --git a/plugins/qbittorrent/js/qbittorrent.js b/plugins/qbittorrent/js/qbittorrent.js index 44de2d9b2..b9e9d9670 100755 --- a/plugins/qbittorrent/js/qbittorrent.js +++ b/plugins/qbittorrent/js/qbittorrent.js @@ -1,7 +1,7 @@ -function dhtPostMin(method, args, callback){ +function qbPostMin(method, args, callback){ var req_data = {}; - req_data['name'] = 'simdht'; + req_data['name'] = 'qbittorrent'; req_data['func'] = method; if (typeof(args) != 'undefined' && args!=''){ @@ -20,9 +20,9 @@ function dhtPostMin(method, args, callback){ },'json'); } -function dhtPost(method, args, callback){ +function qbPost(method, args, callback){ var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); - dhtPostMin(method,args,function(data){ + qbPostMin(method,args,function(data){ layer.close(loadT); if(typeof(callback) == 'function'){ callback(data); @@ -30,243 +30,55 @@ function dhtPost(method, args, callback){ }); } - -function dhtTrend(){ - var obj = $('#dht_trend'); - if (obj.length>0){ - console.log('已经加载图表...'); - return; +function qbList(page,search){ + var _data = {}; + if (typeof(page) =='undefined'){ + var page = 1; } - - var trend = '
'; - $('.soft-man-con').html(trend); - dhtTrendRender(); -} - -function dhtTrendData(callback){ - dhtPostMin('get_trend_data',{interval:1},function(data){ - if(typeof(callback) == 'function'){ - callback(data); - } - }); -} - - -function dhtTrendRender() { - var myChartNetwork = echarts.init(document.getElementById('dht_trend')); - var xData = []; - var oneData = []; - var twoData = []; - var threeData = []; - - function getTime() { - var now = new Date(); - var hour = now.getHours(); - var minute = now.getMinutes(); - var second = now.getSeconds(); - if (minute < 10) { - minute = "0" + minute; - } - if (second < 10) { - second = "0" + second; - } - var nowdate = hour + ":" + minute + ":" + second; - return nowdate; - } - - function ts(m) { return m < 10 ? '0' + m : m } - - function format(sjc) { - var time = new Date(sjc); - var h = time.getHours(); - var mm = time.getMinutes(); - var s = time.getSeconds(); - return ts(h) + ':' + ts(mm) + ':' + ts(s); - } - - function addData(data) { - // console.log(data); - var rdata = $.parseJSON(data.data); - xData.push(getTime()); - oneData.push(rdata[0]); - twoData.push(rdata[1]); - threeData.push(rdata[2]); - - xData.shift(); - oneData.shift(); - twoData.shift(); - threeData.shift(); - } - for (var i = 8; i >= 0; i--) { - var time = (new Date()).getTime(); - xData.push(format(time - (i * 5 * 1000))); - oneData.push(0); - twoData.push(0); - threeData.push(0); - } - // 指定图表的配置项和数据 - var option = { - title: { - text: '种子收录趋势', - left: 'center', - textStyle: { - color: '#888888',fontStyle: 'normal', - fontFamily: '宋体',fontSize: 16, - } - }, - tooltip: { - trigger: 'axis' - }, - legend: { - data: ['1s', '5s', '10s'], - bottom: '2%' - }, - xAxis: { - type: 'category', - boundaryGap: false, - data: xData, - axisLine: { - lineStyle: { - color: "#666" - } - } - }, - yAxis: { - name: '单位个数', - splitLine: { - lineStyle: { - color: "#eee" - } - }, - axisLine: { - lineStyle: { - color: "#666" - } - } - }, - series: [{ - name: '1s', - type: 'line', - data: oneData, - smooth: true, - showSymbol: false, - symbol: 'circle', - symbolSize: 6, - areaStyle: { - normal: { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, - [{offset: 0,color: 'rgba(205, 51, 51,0.5)'}, - {offset: 1,color: 'rgba(205, 51, 51,0.8)'}], false) - } - }, - itemStyle: { - normal: {color: '#cd3333'} - }, - lineStyle: { - normal: {width: 1} - } - }, { - name: '5s', - type: 'line', - data: twoData, - smooth: true, - showSymbol: false, - symbol: 'circle', - symbolSize: 6, - areaStyle: { - normal: { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ - offset: 0, - color: 'rgba(30, 144, 255,0.5)' - }, { - offset: 1, - color: 'rgba(30, 144, 255,0.8)' - }], false) - } - }, - itemStyle: { - normal: {color: '#52a9ff'} - }, - lineStyle: { - normal: { - width: 1 - } - } - },{ - name: '10s', - type: 'line', - data: threeData, - smooth: true, - showSymbol: false, - symbol: 'circle', - symbolSize: 6, - areaStyle: { - normal: { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ - offset: 0, - color: 'rgba(30, 144, 255,0.5)' - }, { - offset: 1, - color: 'rgba(30, 144, 255,0.8)' - }], false) - } - }, - itemStyle: { - normal: {color: '#C6E2FF'} - }, - lineStyle: { - normal: { - width: 1 - } - } - }] - }; - - // 使用刚指定的配置项和数据显示图表。 - myChartNetwork.setOption(option); - window.addEventListener("resize", function() { - myChartNetwork.resize(); - }); - - function render(){ - dhtTrendData(function(data){ - addData(data); - }); - myChartNetwork.setOption({ - xAxis: {data: xData}, - series: [ - {name: '1s',data: oneData}, - {name: '5s',data: twoData}, - {name: '10s',data: threeData} - ] - }); + _data['page'] = page; + _data['page_size'] = 10; + if(typeof(search) != 'undefined'){ + _data['search'] = search; } - render(); - renderTick = setInterval(function() { - render(); - }, 3000); + qbPost('qb_list', _data, function(data){ - checkTick = setInterval(function() { - var obj = $('#dht_trend'); - if (obj.length>0){ + + var rdata = $.parseJSON(data.data); + if (!rdata['status']){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); return; - } else { - console.log('取消定时请求...'); - clearInterval(renderTick); - clearInterval(checkTick); } - }, 300); -} + console.log(rdata); + content = ''; + // content += '
'; -function dhtRead(){ - dhtPost('dht_cmd','', function(data){ - console.log(data); - var readme = '

* 在手动导入SQL-先把数据表创建

'; - readme += '

* 修改成对应的配置文件

'; - readme += '

* 加入到计划[自行调节]:'+data.data+'

'; - $('.soft-man-con').html(readme); + content += '
'; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + + content += ''; + + ulist = rdata.data; + for (i in ulist){ + content += ''+ + ''+ + ''; + } + + content += ''; + content += '
种子(hash)状态操作(添加 | 管理)
'+ulist[i]['hash']+''+'下载中'+'删除
'; + + // page = ''; + + // content += page; + + $(".soft-man-con").html(content); }); - } diff --git a/plugins/qbittorrent/qb.conf b/plugins/qbittorrent/qb.conf index eef4532ab..df3315c3b 100755 --- a/plugins/qbittorrent/qb.conf +++ b/plugins/qbittorrent/qb.conf @@ -7,7 +7,7 @@ DB_NAME = qbittorrent [qb] QB_HOST = 127.0.0.1 -QB_PORT = 8081 +QB_PORT = 8080 QB_USER = admin QB_PWD = adminadmin