diff --git a/Common.py b/Common.py index 00138de..0288587 100644 --- a/Common.py +++ b/Common.py @@ -23,7 +23,7 @@ streamUrl = "" isBroadcasting = False updateTime = "" -forceStopDownload = False +forceNotDownload = False forceNotBroadcasting = False forceNotUpload = True forceNotEncode = True @@ -143,7 +143,7 @@ class downloader(XiGuaLiveApi): playlist = None def updRoomInfo(self): - global broadcaster, isBroadcasting, updateTime, forceNotBroadcasting, forceStopDownload + global broadcaster, isBroadcasting, updateTime, forceNotBroadcasting, forceNotDownload super(downloader, self).updRoomInfo() updateTime = datetime.strftime(datetime.now(), dt_format) broadcaster = self.roomLiver @@ -151,7 +151,7 @@ class downloader(XiGuaLiveApi): if self.isLive: self.updPlayList() else: - forceStopDownload = False + forceNotDownload = False forceNotBroadcasting = False self.playlist = False self.files = [] diff --git a/WebMain.py b/WebMain.py index 543d08b..2242873 100644 --- a/WebMain.py +++ b/WebMain.py @@ -36,6 +36,38 @@ def writeConfig(): return jsonify({"message":"ok","code":200,"status":0,"data":request.form}) +@app.route("/force/not/upload", methods=["POST"]) +def toggleForceNotUpload(): + Common.forceNotUpload = not Common.forceNotUpload + return jsonify({"message":"ok","code":200,"status":0,"data":{ + "forceNotUpload": Common.forceNotUpload, + }}) + + +@app.route("/force/not/encode", methods=["POST"]) +def toggleForceNotEncode(): + Common.forceNotEncode = not Common.forceNotEncode + return jsonify({"message":"ok","code":200,"status":0,"data":{ + "forceNotEncode": Common.forceNotEncode, + }}) + + +@app.route("/force/not/download", methods=["POST"]) +def toggleForceNotDownload(): + Common.forceNotDownload = not Common.forceNotDownload + return jsonify({"message":"ok","code":200,"status":0,"data":{ + "forceNotDownload": Common.forceNotDownload, + }}) + + +@app.route("/force/not/broadcast", methods=["POST"]) +def toggleForceNotBroadcast(): + Common.forceNotBroadcasting = not Common.forceNotBroadcasting + return jsonify({"message":"ok","code":200,"status":0,"data":{ + "forceNotBroadcasting": Common.forceNotBroadcasting, + }}) + + @app.route("/encode/insert", methods=["POST"]) def insertEncode(): if "filename" in request.form: @@ -74,7 +106,7 @@ def getAllStats(): }, "config": { "forceNotBroadcasting": Common.forceNotBroadcasting, - "forceStopDownload": Common.forceStopDownload, + "forceNotDownload": Common.forceNotDownload, "forceNotUpload": Common.forceNotUpload, "forceNotEncode": Common.forceNotEncode, }, @@ -115,7 +147,7 @@ def getConfigStats(): return jsonify({"message":"ok","code":200,"status":0,"data":{ "config": { "forceNotBroadcasting": Common.forceNotBroadcasting, - "forceStopDownload": Common.forceStopDownload, + "forceNotDownload": Common.forceNotDownload, "forceNotUpload": Common.forceNotUpload, } }}) diff --git a/liveDownloader.py b/liveDownloader.py index 8828013..c38f20e 100644 --- a/liveDownloader.py +++ b/liveDownloader.py @@ -13,7 +13,7 @@ isDownload = False def download(url): - global isDownload, forceStopDownload + global isDownload, forceNotDownload 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("Downloading >{}< @ {:.2f}%".format(path, 100.0 * _size/config["p_s"])) - if _size > config["p_s"] or forceStopDownload: + if _size > config["p_s"] or forceNotDownload: break modifyLastDownloadStatus("Download >{}< Finished".format(path)) except Exception as e: @@ -36,14 +36,13 @@ def download(url): e.__str__())) f.close() isDownload = False - if os.path.getsize(path) == 0: + if os.path.getsize(path) < 1024 * 1024: os.remove(path) return False - encodeQueue.put(path) - if forceStopDownload: - forceStopDownload = False + if forceNotDownload: return else: + encodeQueue.put(path) download(url) @@ -53,7 +52,8 @@ def encode(): while True: i = encodeQueue.get() if forceNotEncode: - modifyLastEncodeStatus("设置了不编码,所以[{}]不会编码".format(i)) + appendEncodeStatus("设置了不编码,所以[{}]不会编码".format(i)) + uploadQueue.put(i) continue if os.path.exists(i): isEncode = True @@ -73,7 +73,7 @@ def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")): i = uploadQueue.get() while True: if forceNotUpload: - modifyLastUploadStatus("设置了不上传,所以[{}]不会上传了".format(i)) + appendUploadStatus("设置了不上传,所以[{}]不会上传了".format(i)) i = uploadQueue.get() continue if isinstance(i, bool): @@ -119,7 +119,7 @@ def run(name): if api.isLive and not forceNotBroadcasting: if d is None: d = datetime.strftime(datetime.now(), "%Y_%m_%d") - if not t.is_alive() and not forceStopDownload: + if not t.is_alive() and not forceNotDownload: _count_error += 1 _preT = api.playlist t = threading.Thread(target=download, args=(_preT,)) diff --git a/static/index.html b/static/index.html index e84c01b..27f0203 100644 --- a/static/index.html +++ b/static/index.html @@ -40,7 +40,7 @@ 是否设置强制不下载 - + 是否设置强制不上传 diff --git a/static/index.js b/static/index.js index 2fbeda0..879944f 100644 --- a/static/index.js +++ b/static/index.js @@ -7,7 +7,7 @@ function taskUpdate(){ $("#isBroadcasting").text(res.data.broadcast.isBroadcasting) $("#streamUrl").text(res.data.broadcast.streamUrl) $("#forceNotBroadcasting").text(res.data.config.forceNotBroadcasting) - $("#forceStopDownload").text(res.data.config.forceStopDownload) + $("#forceNotDownload").text(res.data.config.forceNotDownload) $("#forceNotUpload").text(res.data.config.forceNotUpload) $("#forceNotEncode").text(res.data.config.forceNotEncode) $("#updateTime").text(res.data.broadcast.updateTime)