This repository has been archived on 2022-05-30. You can view files and clone it, but cannot push or open issues or pull requests.
2019-04-07 19:12:03 +08:00

100 lines
2.6 KiB
Python

from time import sleep
from flask_cors import CORS
from flask import Flask, jsonify, request, redirect, url_for
import Common
import threading
from liveDownloader import run as RUN
app = Flask("liveStatus")
app.config['JSON_AS_ASCII'] = False
CORS(app, supports_credentials=True)
url_for('static', filename='index.html')
url_for('static', filename='index.js')
@app.route("/")
def index():
return redirect("/static/index.html")
@app.route("/config", methods=["GET"])
def readConfig():
config = Common.config.copy()
config.pop("b_p")
config.pop("mtd")
config.pop("del")
config.pop("mv")
return jsonify(config)
@app.route("/config", methods=["POST"])
def writeConfig():
# TODO : 完善
return jsonify({"message":"ok","code":200,"status":0,"data":request.form})
@app.route("/stats", methods=["GET"])
def getAllStats():
return jsonify({"message":"ok","code":200,"status":0,"data":{
"download":Common.downloadStatus,
"encode": Common.encodeStatus,
"upload": Common.uploadStatus,
"error": Common.errors,
"broadcast": {
"broadcaster": Common.broadcaster.__str__(),
"isBroadcasting": Common.isBroadcasting,
"streamUrl": Common.streamUrl,
"updateTime": Common.updateTime
}
}})
@app.route("/stats/broadcast", methods=["GET"])
def geBroadcastStats():
return jsonify({"message":"ok","code":200,"status":0,"data":{
"broadcast": {
"broadcaster": Common.broadcaster.__str__(),
"isBroadcasting": Common.isBroadcasting,
"streamUrl": Common.streamUrl,
"updateTime": Common.updateTime
}
}})
@app.route("/stats/download", methods=["GET"])
def geDownloadStats():
return jsonify({"message":"ok","code":200,"status":0,"data":{
"download":Common.downloadStatus,
}})
@app.route("/stats/encode", methods=["GET"])
def getEncodeStats():
return jsonify({"message":"ok","code":200,"status":0,"data":{
"encode": Common.encodeStatus,
}})
@app.route("/stats/upload", methods=["GET"])
def getUploadStats():
return jsonify({"message":"ok","code":200,"status":0,"data":{
"upload": Common.uploadStatus,
}})
def SubThread():
t = threading.Thread(target=RUN, args=(Common.config['l_u'],))
t.setDaemon(True)
t.start()
while True:
if t.is_alive():
sleep(240)
else:
t = threading.Thread(target=RUN, args=(Common.config['l_u'],))
t.setDaemon(True)
t.start()
p = threading.Thread(target = SubThread)
p.setDaemon(True)
p.start()