pull/109/head
Mr Chen 6 years ago
parent 426354b669
commit f61c060547
  1. 18
      plugins/qbittorrent/index.html
  2. 90
      plugins/qbittorrent/index.py
  3. 44
      plugins/qbittorrent/init.d/qbittorrent.tpl
  4. 272
      plugins/qbittorrent/js/qbittorrent.js

@ -0,0 +1,18 @@
<div class="bt-form">
<div class="bt-w-main">
<div class="bt-w-menu">
<p class="bgw" onclick="pluginService('qbittorrent');">服务</p>
<p onclick="pluginInitD('qbittorrent');">自启动</p>
</div>
<div class="bt-w-con pd15">
<div class="soft-man-con">
</div>
</div>
</div>
</div>
<script type="text/javascript">
pluginService('qbittorrent');
$.getScript( "/plugins/file?name=qbittorrent&f=js/qbittorrent.js");
</script>

@ -17,15 +17,12 @@ if public.isAppleSystem():
def getPluginName():
return 'simdht'
return 'qbittorrent'
def getPluginDir():
return public.getPluginDir() + '/' + getPluginName()
sys.path.append(getPluginDir() + "/class")
import mysql
def getServerDir():
return public.getServerDir() + '/' + getPluginName()
@ -113,7 +110,7 @@ def initDreplace():
def status():
data = public.execShell(
"ps -ef|grep \"python simdht_worker.py\" | grep -v grep | awk '{print $2}'")
"ps -ef|grep qbittorrent-nox-bin | grep -v grep | awk '{print $2}'")
if data[0] == '':
return 'stop'
return 'start'
@ -186,23 +183,6 @@ def initdUinstall():
return 'ok'
def matchData(reg, content):
tmp = re.search(reg, content).groups()
return tmp[0]
def getDbConfInfo():
cfg = getDbConf()
content = public.readFile(cfg)
data = {}
data['DB_HOST'] = matchData("DB_HOST\s*=\s(.*)", content)
data['DB_USER'] = matchData("DB_USER\s*=\s(.*)", content)
data['DB_PORT'] = matchData("DB_PORT\s*=\s(.*)", content)
data['DB_PASS'] = matchData("DB_PASS\s*=\s(.*)", content)
data['DB_NAME'] = matchData("DB_NAME\s*=\s(.*)", content)
return data
def pMysqlDb():
data = getDbConfInfo()
conn = mysql.mysql()
@ -214,58 +194,16 @@ def pMysqlDb():
return conn
def isSqlError(mysqlMsg):
# 检测数据库执行错误
mysqlMsg = str(mysqlMsg)
if "MySQLdb" in mysqlMsg:
return public.returnJson(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python')
if "2002," in mysqlMsg:
return public.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
if "using password:" in mysqlMsg:
return public.returnJson(False, '数据库管理密码错误!')
if "Connection refused" in mysqlMsg:
return public.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
if "1133" in mysqlMsg:
return public.returnJson(False, '数据库用户不存在!')
if "1007" in mysqlMsg:
return public.returnJson(False, '数据库已经存在!')
return None
def getMinData(conn, sec):
time_diff = 0
if public.isAppleSystem():
time_diff = 3 * 60
pre = time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime(time.time() - sec - time_diff))
sql = "select count(id) from search_hash where create_time > '" + pre + "'"
data = conn.query(sql)
return data[0][0]
def getTrendData():
try:
args = getArgs()
data = checkArgs(args, ['interval'])
if not data[0]:
return data[1]
pdb = pMysqlDb()
# interval = int(args['interval'])
result = pdb.execute("show tables")
isError = isSqlError(result)
if isError:
return isError
one = getMinData(pdb, 1)
two = getMinData(pdb, 5)
three = getMinData(pdb, 10)
return public.getJson([one, two, three])
except Exception as e:
print str(e)
return public.getJson([0, 0, 0])
def dhtCmd():
file = initDreplace()
return file+' restart'
def test():
from qbittorrent import Client
qb = Client('http://154.48.251.71:8080/')
qb.login('admin', 'adminadmin')
# magnet_link = "magnet:?xt=urn:btih:57a0ec92a61c60585f1b7a206a75798aa69285a5"
# print qb.download_from_link(magnet_link)
torrents = qb.torrents(filter='downloading')
for torrent in torrents:
print public.returnJson(False, torrent)
if __name__ == "__main__":
func = sys.argv[1]
@ -293,7 +231,7 @@ if __name__ == "__main__":
print getRunLog()
elif func == 'get_trend_data':
print getTrendData()
elif func == 'dht_cmd':
print dhtCmd();
elif func == 'test':
print test()
else:
print 'error'

@ -0,0 +1,44 @@
#!/bin/sh
# chkconfig: 2345 55 25
# description: qbittorrent Service
### BEGIN INIT INFO
# Provides: qbittorrent
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts qbittorrent
# Description: starts the MDW-Web
### END INIT INFO
qb_start(){
cd {$SERVER_PATH}/qbittorrent/workers
nohup python simdht_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
echo "Redis stopped"
}
case "$1" in
start)
qb_start
;;
stop)
qb_stop
;;
restart|reload)
qb_stop
sleep 0.3
qb_start
;;
*)
echo "Please use start or stop as first argument"
;;
esac

@ -0,0 +1,272 @@
function dhtPostMin(method, args, callback){
var req_data = {};
req_data['name'] = 'simdht';
req_data['func'] = method;
if (typeof(args) != 'undefined' && args!=''){
req_data['args'] = JSON.stringify(args);
}
$.post('/plugins/run', req_data, function(data) {
if (!data.status){
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
return;
}
if(typeof(callback) == 'function'){
callback(data);
}
},'json');
}
function dhtPost(method, args, callback){
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
dhtPostMin(method,args,function(data){
layer.close(loadT);
if(typeof(callback) == 'function'){
callback(data);
}
});
}
function dhtTrend(){
var obj = $('#dht_trend');
if (obj.length>0){
console.log('已经加载图表...');
return;
}
var trend = '<div id="dht_trend" style="width:100%;height:330px;"></div>';
$('.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}
]
});
}
render();
renderTick = setInterval(function() {
render();
}, 3000);
checkTick = setInterval(function() {
var obj = $('#dht_trend');
if (obj.length>0){
return;
} else {
console.log('取消定时请求...');
clearInterval(renderTick);
clearInterval(checkTick);
}
}, 300);
}
function dhtRead(){
dhtPost('dht_cmd','', function(data){
console.log(data);
var readme = '<p>* 在手动导入SQL-先把数据表创建</p>';
readme += '<p>* 修改成对应的配置文件</p>';
readme += '<p>* 加入到计划[自行调节]:'+data.data+'</p>';
$('.soft-man-con').html(readme);
});
}
Loading…
Cancel
Save