diff --git a/Common.py b/Common.py index fc79d23..d47d502 100644 --- a/Common.py +++ b/Common.py @@ -26,7 +26,12 @@ config = { "l_c": 5, # 错误Log条数 "elc": 10, + # 每一chunk大小 + "c_s": 16 * 1024, + # 每一块视频大小 "p_s": 2141000000, + # 忽略的大小 + "i_s": 2048000, "max": 75, "exp": 1, "dow": "echo 'clean'", @@ -79,7 +84,7 @@ def resetDelay(): def doDelay(): global delay - if -120 < getTimeDelta(datetime.now(), delay) < 60: + if -60 < getTimeDelta(datetime.now(), delay) < 60: delay = datetime.fromtimestamp(0) return True return False diff --git a/liveDownloader.py b/liveDownloader.py index 1c6965b..1d577f0 100644 --- a/liveDownloader.py +++ b/liveDownloader.py @@ -15,37 +15,34 @@ def download(): path = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.flv") try: p = session.get(Common.streamUrl, stream=True, timeout=3) + p.raise_for_status() except Exception as e: Common.appendError("Download >{}< with Exception [{}]".format(path,e.__str__())) break - if p.status_code != 200: - Common.appendDownloadStatus("Download with Response {}".format(p.status_code)) - break Common.appendDownloadStatus("Download >{}< Start".format(path)) f = open(path, "wb") _size = 0 try: - for T in p.iter_content(chunk_size=64 * 1024): + for T in p.iter_content(chunk_size=Common.config["c_s"]): if Common.forceNotDownload: Common.modifyLastDownloadStatus("Force Stop Download".format(path)) - break + return f.write(T) _size += len(T) Common.modifyLastDownloadStatus( "Downloading >{}< @ {:.2f}%".format(path, 100.0 * _size / Common.config["p_s"])) if _size > Common.config["p_s"]: Common.modifyLastDownloadStatus("Download >{}< Exceed MaxSize".format(path)) - break Common.modifyLastDownloadStatus("Download >{}< Finished".format(path)) except Exception as e: Common.appendError("Download >{}< With Exception {}".format(path, e.__str__())) Common.api.updRoomInfo(True) - f.close() - if os.path.getsize(path) < 1024 * 1024: + finally: + f.close() + if os.path.getsize(path) < Common.config["i_s"]: Common.modifyLastDownloadStatus("Downloaded File >{}< is too small, will ignore it".format(path)) - os.remove(path) - continue - Common.encodeQueue.put(path) + else: + Common.encodeQueue.put(path) Common.api.updRoomInfo(True) @@ -68,8 +65,9 @@ def upload(): Common.uploadVideo(i) except Exception as e: Common.appendError(e.__str__()) - time.sleep(120) continue + finally: + time.sleep(120) i = Common.uploadQueue.get() Common.appendUploadStatus("Upload Daemon Quiting") @@ -127,9 +125,8 @@ def run(): Common.api.updRoomInfo() except Exception as e: Common.appendError(e.__str__()) - time.sleep(2) - continue - time.sleep(0.5) + finally: + time.sleep(1) else: try: Common.api.updRoomInfo()