From 6d4127c90ba6386d950cac145353c1ae1eb60cbe Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 3 Jan 2020 09:19:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E6=8B=A8=E6=8A=95=E7=A8=BF=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common.py | 26 ++++++++++---------------- liveDownloader.py | 6 +----- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Common.py b/Common.py index 93be8e9..4ff9260 100644 --- a/Common.py +++ b/Common.py @@ -1,7 +1,6 @@ import os import queue from datetime import datetime, timedelta -from glob import glob import psutil from api import XiGuaLiveApi @@ -37,10 +36,10 @@ config = { "dly": 30, "enc": "ffmpeg -i {f} -c:v copy -c:a copy -f mp4 {t} -y" } -doCleanTime = datetime.now() -loginTime = datetime.now() +doCleanTime = datetime.fromtimestamp(0) +loginTime = datetime.fromtimestamp(0) _clean_flag = None -delay = datetime.now() +delay = datetime.fromtimestamp(0) b = Bilibili() network = [{ @@ -77,11 +76,11 @@ def resetDelay(): def doDelay(): - global delay, isBroadcasting, isEncode, isUpload - if isBroadcasting or isEncode or isUpload: + global delay, isBroadcasting + if isBroadcasting: resetDelay() return False - return datetime.now() > delay + return (datetime.now() - delay).seconds < 120 def updateNetwork(): @@ -299,7 +298,7 @@ def appendError(obj): def loginBilibili(force=False): if config["dlO"] is False or forceNotUpload is False: global loginTime - if not force and getTimeDelta(datetime.now(), loginTime) < 86400 * 5: + if not force and getTimeDelta(datetime.now(), loginTime) < 86400 * 10: return False res = b.login(config["b_u"], config["b_p"]) loginTime = datetime.now() @@ -364,14 +363,14 @@ def uploadVideo(name): def publishVideo(date): - global isUpload if forceNotUpload is False: b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"], source=config["src"], no_reprint=0) b.clear() + global delay + delay = datetime.fromtimestamp(0) else: - appendUploadStatus("设置了不上传,所以[{}]的录播不会上传了".format(date)) - isUpload = False + appendUploadStatus("设置了不上传,所以[{}]的录播不会投了".format(date)) def encodeVideo(name): @@ -384,8 +383,6 @@ def encodeVideo(name): if os.path.getsize(name) < 8 * 1024 * 1024: appendEncodeStatus("Encoded File >{}< is too small, will ignore it".format(name)) return False - global isEncode - isEncode = True appendEncodeStatus("Encoding >{}< Start".format(name)) _new_name = os.path.splitext(name)[0] + ".mp4" _code = os.system(config["enc"].format(f=name, t=_new_name)) @@ -394,7 +391,4 @@ def encodeVideo(name): return False Common.modifyLastEncodeStatus("Encode >{}< Finished".format(name)) uploadQueue.put(_new_name) - isEncode = False - -loginBilibili(True) diff --git a/liveDownloader.py b/liveDownloader.py index 41bb1f7..885a1a3 100644 --- a/liveDownloader.py +++ b/liveDownloader.py @@ -1,5 +1,3 @@ -import shutil -import sys import time from datetime import datetime import threading @@ -111,7 +109,7 @@ def awakeUpload(): def run(): Common.refreshDownloader() if not Common.api.isValidUser: - Common.appendError("[{}]房间未找到".format(Common.config["l_u"])) + Common.appendError("[{}]用户未找到".format(Common.api.name)) return while True: if Common.api.isLive and not Common.forceNotBroadcasting: @@ -144,6 +142,4 @@ def run(): Common.forceStartUploadThread = False if Common.doDelay(): Common.uploadQueue.put(True) - Common.isEncode = True - Common.isUpload = True time.sleep(5)