support change while running

This commit is contained in:
Jerry Yan 2019-04-07 22:26:21 +08:00 committed by JerryYan
parent 16c68e5ceb
commit ce819185eb
4 changed files with 39 additions and 6 deletions

View File

@ -6,6 +6,14 @@ import json
_config_fp = open("config.json","r",encoding="utf8")
config = json.load(_config_fp)
_config_fp.close()
def reloadConfig():
global config, _config_fp
_config_fp = open("config.json", "r", encoding="utf8")
config = json.load(_config_fp)
_config_fp.close()
dt_format="%Y/%m/%d %H:%M:%S"
@ -14,6 +22,8 @@ streamUrl = ""
isBroadcasting = False
updateTime = ""
forceStopDownload = False
uploadQueue = queue.Queue()
encodeQueue = queue.Queue()

View File

@ -8,8 +8,8 @@ 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')
# url_for('static', filename='index.html')
# url_for('static', filename='index.js')
@app.route("/")
@ -29,9 +29,30 @@ def readConfig():
@app.route("/config", methods=["POST"])
def writeConfig():
# TODO : 完善
Common.reloadConfig()
return jsonify({"message":"ok","code":200,"status":0,"data":request.form})
@app.route("/encode/insert", methods=["POST"])
def insertEncode():
if "filename" in request.form:
Common.encodeQueue.put(request.form["filename"])
return jsonify({"message":"ok","code":200,"status":0})
@app.route("/upload/insert", methods=["POST"])
def insertUpload():
if "filename" in request.form:
Common.uploadQueue.put(request.form["filename"])
return jsonify({"message":"ok","code":200,"status":0})
@app.route("/upload/finish", methods=["POST"])
def finishUpload():
Common.uploadQueue.put(True)
return jsonify({"message":"ok","code":200,"status":0})
@app.route("/stats", methods=["GET"])
def getAllStats():
return jsonify({"message":"ok","code":200,"status":0,"data":{

View File

@ -313,6 +313,7 @@ class Bilibili:
"""
if len(self.videos) == 0:
return
appendUploadStatus("[{}]投稿中,请稍后".format(title))
self.session.headers['Content-Type'] = 'application/json; charset=utf-8'
copyright = 2 if source else 1
r = self.session.post('https://member.bilibili.com/x/vu/web/add?csrf=' + self.csrf,

View File

@ -13,7 +13,7 @@ isDownload = False
def download(url):
global isDownload
global isDownload, forceStopDownload
path = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.flv")
p = requests.get(url, stream=True)
if p.status_code != 200:
@ -28,7 +28,7 @@ def download(url):
f.write(t)
_size = os.path.getsize(path)
modifyLastDownloadStatus("Download >{}< @ {:.2f}%".format(path, 100.0 * _size/config["p_s"]))
if _size > config["p_s"]:
if _size > config["p_s"] or forceStopDownload:
break
modifyLastDownloadStatus("Finished Download >{}<".format(path))
except Exception as e:
@ -40,7 +40,9 @@ def download(url):
os.remove(path)
return False
encodeQueue.put(path)
download(url)
if forceStopDownload:
download(url)
forceStopDownload = False
def encode():
@ -65,7 +67,6 @@ def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
while True:
if isinstance(i, bool):
if i is True:
appendUploadStatus("[{}]自动投稿中,请稍后".format(config["t_t"].format(date)))
b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"],
source=config["src"], no_reprint=0)
b.clear()