添加强制清理功能,添加百度云上传功能,部分逻辑修改
This commit is contained in:
parent
43e161ebb6
commit
f1b4a878a5
61
Common.py
61
Common.py
@ -1,24 +1,27 @@
|
|||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
from api import XiGuaLiveApi
|
from api import XiGuaLiveApi
|
||||||
import json
|
import json
|
||||||
from bilibili import Bilibili
|
from bilibili import Bilibili
|
||||||
import threading
|
import threading
|
||||||
|
from bypy import ByPy
|
||||||
|
|
||||||
_config_fp = open("config.json","r",encoding="utf8")
|
_config_fp = open("config.json", "r", encoding="utf8")
|
||||||
config = json.load(_config_fp)
|
config = json.load(_config_fp)
|
||||||
_config_fp.close()
|
_config_fp.close()
|
||||||
|
bypy = ByPy()
|
||||||
_do_move_time = datetime.now()
|
doCleanTime = datetime.now()
|
||||||
|
|
||||||
network = {
|
network = {
|
||||||
"currentTime": datetime.now(),
|
"currentTime": datetime.now(),
|
||||||
"out":{
|
"out": {
|
||||||
"currentByte":psutil.net_io_counters().bytes_sent,
|
"currentByte": psutil.net_io_counters().bytes_sent,
|
||||||
},
|
},
|
||||||
"in":{
|
"in": {
|
||||||
"currentByte": psutil.net_io_counters().bytes_recv,
|
"currentByte": psutil.net_io_counters().bytes_recv,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,10 +31,10 @@ def updateNetwork():
|
|||||||
global network
|
global network
|
||||||
network = {
|
network = {
|
||||||
"currentTime": datetime.now(),
|
"currentTime": datetime.now(),
|
||||||
"out":{
|
"out": {
|
||||||
"currentByte":psutil.net_io_counters().bytes_sent,
|
"currentByte": psutil.net_io_counters().bytes_sent,
|
||||||
},
|
},
|
||||||
"in":{
|
"in": {
|
||||||
"currentByte": psutil.net_io_counters().bytes_recv,
|
"currentByte": psutil.net_io_counters().bytes_recv,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,16 +46,30 @@ def getTimeDelta(a, b):
|
|||||||
return sec+(ms/100000.0)
|
return sec+(ms/100000.0)
|
||||||
|
|
||||||
|
|
||||||
def _doClean():
|
def _doClean(_force=False):
|
||||||
global _do_move_time
|
global doCleanTime
|
||||||
_disk = psutil.disk_usage(".")
|
_disk = psutil.disk_usage(".")
|
||||||
if _disk.percent > config["max"] and getTimeDelta(datetime.now(), _do_move_time) > 7200:
|
if (_disk.percent > config["max"] and getTimeDelta(datetime.now(), doCleanTime) > 7200) or _force:
|
||||||
_do_move_time = datetime.now()
|
doCleanTime = datetime.now()
|
||||||
|
_list = sorted(glob("*.flv"), key=lambda x: datetime.utcfromtimestamp(os.path.getmtime(x)))
|
||||||
|
for _i in _list:
|
||||||
|
if not os.path.exists(_i):
|
||||||
|
break
|
||||||
|
doCleanTime = datetime.now()
|
||||||
|
if (datetime.now() - datetime.utcfromtimestamp(os.path.getmtime(_i))).days > config["exp"]:
|
||||||
|
if config["dow"] == "bypy":
|
||||||
|
_res = bypy.upload(_i)
|
||||||
|
if _res == 0:
|
||||||
|
os.remove(_i)
|
||||||
|
else:
|
||||||
os.system(config["dow"])
|
os.system(config["dow"])
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
doCleanTime = datetime.now()
|
||||||
|
|
||||||
|
|
||||||
def doClean():
|
def doClean(_force=False):
|
||||||
p = threading.Thread(target=_doClean)
|
p = threading.Thread(target=_doClean, args=(_force,))
|
||||||
p.setDaemon(True)
|
p.setDaemon(True)
|
||||||
p.start()
|
p.start()
|
||||||
|
|
||||||
@ -63,13 +80,13 @@ def getCurrentStatus():
|
|||||||
_delta= getTimeDelta(datetime.now(),network["currentTime"])
|
_delta= getTimeDelta(datetime.now(),network["currentTime"])
|
||||||
_net = psutil.net_io_counters()
|
_net = psutil.net_io_counters()
|
||||||
if 60 > _delta > 0:
|
if 60 > _delta > 0:
|
||||||
_inSpeed = (_net.bytes_recv - network["in"]["currentByte"])/_delta
|
_inSpeed = (_net.bytes_recv - network["in"]["currentByte"]) / _delta
|
||||||
_outSpeed = (_net.bytes_sent - network["out"]["currentByte"])/_delta
|
_outSpeed = (_net.bytes_sent - network["out"]["currentByte"]) / _delta
|
||||||
else:
|
else:
|
||||||
_outSpeed = 0
|
_outSpeed = 0
|
||||||
_inSpeed = 0
|
_inSpeed = 0
|
||||||
updateNetwork()
|
updateNetwork()
|
||||||
if getTimeDelta(datetime.now(), _do_move_time) > 3600:
|
if getTimeDelta(datetime.now(), doCleanTime) > 3600:
|
||||||
doClean()
|
doClean()
|
||||||
return {
|
return {
|
||||||
"memTotal": parseSize(_mem.total),
|
"memTotal": parseSize(_mem.total),
|
||||||
@ -81,6 +98,8 @@ def getCurrentStatus():
|
|||||||
"cpu": psutil.cpu_percent(),
|
"cpu": psutil.cpu_percent(),
|
||||||
"outSpeed": parseSize(_outSpeed),
|
"outSpeed": parseSize(_outSpeed),
|
||||||
"inSpeed": parseSize(_inSpeed),
|
"inSpeed": parseSize(_inSpeed),
|
||||||
|
"doCleanTime": doCleanTime,
|
||||||
|
"fileExpire": config["exp"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +110,7 @@ def reloadConfig():
|
|||||||
_config_fp.close()
|
_config_fp.close()
|
||||||
|
|
||||||
|
|
||||||
dt_format="%Y/%m/%d %H:%M:%S"
|
dt_format = "%Y/%m/%d %H:%M:%S"
|
||||||
|
|
||||||
broadcaster = ""
|
broadcaster = ""
|
||||||
streamUrl = ""
|
streamUrl = ""
|
||||||
@ -130,9 +149,9 @@ def appendOperation(obj):
|
|||||||
|
|
||||||
|
|
||||||
def parseSize(size):
|
def parseSize(size):
|
||||||
K = size/1024.0
|
K = size / 1024.0
|
||||||
if K > 1000:
|
if K > 1000:
|
||||||
M = K/1024.0
|
M = K / 1024.0
|
||||||
if M > 1000:
|
if M > 1000:
|
||||||
return "{:.2f}GB".format(M / 1024.0)
|
return "{:.2f}GB".format(M / 1024.0)
|
||||||
else:
|
else:
|
||||||
|
10
WebMain.py
10
WebMain.py
@ -23,8 +23,6 @@ def index():
|
|||||||
def readConfig():
|
def readConfig():
|
||||||
config = Common.config.copy()
|
config = Common.config.copy()
|
||||||
config.pop("b_p")
|
config.pop("b_p")
|
||||||
config.pop("mtd")
|
|
||||||
config.pop("del")
|
|
||||||
config.pop("mv")
|
config.pop("mv")
|
||||||
return jsonify(config)
|
return jsonify(config)
|
||||||
|
|
||||||
@ -88,6 +86,14 @@ def toggleForceStartUploadThread():
|
|||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/force/start/clean", methods=["POST"])
|
||||||
|
def toggleForceStartUploadThread():
|
||||||
|
Common.doClean(True)
|
||||||
|
Common.appendOperation("强制执行清理程序")
|
||||||
|
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
||||||
|
}})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/encode/insert", methods=["POST"])
|
@app.route("/encode/insert", methods=["POST"])
|
||||||
def insertEncode():
|
def insertEncode():
|
||||||
if "filename" in request.form and os.path.exists(request.form["filename"]):
|
if "filename" in request.form and os.path.exists(request.form["filename"]):
|
||||||
|
@ -67,10 +67,6 @@ def encode():
|
|||||||
os.system("ffmpeg -i {} -c:v copy -c:a copy -f mp4 {} -y".format(i, i[:13] + ".mp4"))
|
os.system("ffmpeg -i {} -c:v copy -c:a copy -f mp4 {} -y".format(i, i[:13] + ".mp4"))
|
||||||
Common.uploadQueue.put(i[:13] + ".mp4")
|
Common.uploadQueue.put(i[:13] + ".mp4")
|
||||||
Common.modifyLastEncodeStatus("Encode >{}< Finished".format(i))
|
Common.modifyLastEncodeStatus("Encode >{}< Finished".format(i))
|
||||||
if Common.config["mv"]:
|
|
||||||
shutil.move(i, Common.config["mtd"])
|
|
||||||
elif Common.config["del"]:
|
|
||||||
os.remove(i)
|
|
||||||
|
|
||||||
|
|
||||||
def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
|
def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
|
||||||
|
@ -15,6 +15,8 @@ function deviceUpdate(){
|
|||||||
$("#cpuP").val(res.data.status.cpu)
|
$("#cpuP").val(res.data.status.cpu)
|
||||||
$("#inSpeed").text(res.data.status.inSpeed)
|
$("#inSpeed").text(res.data.status.inSpeed)
|
||||||
$("#outSpeed").text(res.data.status.outSpeed)
|
$("#outSpeed").text(res.data.status.outSpeed)
|
||||||
|
$("#doCleanTime").text(res.data.status.doCleanTime)
|
||||||
|
$("#fileExpire").text(res.data.status.fileExpire)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -20,5 +20,10 @@
|
|||||||
<td>↓ <span id="inSpeed"></span>/s</td>
|
<td>↓ <span id="inSpeed"></span>/s</td>
|
||||||
<td>↑ <span id="outSpeed"></span>/s</td>
|
<td>↑ <span id="outSpeed"></span>/s</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class='title'>文件清理时间</td>
|
||||||
|
<td>@ <span id="doCleanTime"></span></td>
|
||||||
|
<td>清理超过<span id="fileExpire"></span>天的文件</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<script src="/static/device.js"></script>
|
<script src="/static/device.js"></script>
|
||||||
|
Reference in New Issue
Block a user