优化逻辑
This commit is contained in:
parent
cf169021c6
commit
0fc33fccff
22
Common.py
22
Common.py
@ -32,7 +32,9 @@ config = {
|
||||
"exp": 1,
|
||||
"dow": "echo 'clean'",
|
||||
# 仅下载
|
||||
"dlO": True
|
||||
"dlO": True,
|
||||
# 下播延迟投稿
|
||||
"dly": 30
|
||||
}
|
||||
|
||||
_config_fp = open("config.json", "r", encoding="utf8")
|
||||
@ -41,7 +43,7 @@ _config_fp.close()
|
||||
del _config_fp
|
||||
doCleanTime = datetime.now()
|
||||
_clean_flag = None
|
||||
|
||||
delay = 30
|
||||
b = Bilibili()
|
||||
|
||||
network = [{
|
||||
@ -63,6 +65,20 @@ network = [{
|
||||
}]
|
||||
|
||||
|
||||
def resetDelay():
|
||||
global delay
|
||||
delay = config['dly']
|
||||
|
||||
|
||||
def doDelay():
|
||||
global delay
|
||||
if delay < 0:
|
||||
resetDelay()
|
||||
sleep(60)
|
||||
delay -= 1
|
||||
return delay < 0
|
||||
|
||||
|
||||
def updateNetwork():
|
||||
global network
|
||||
network.append({
|
||||
@ -356,6 +372,8 @@ def refreshDownloader():
|
||||
|
||||
|
||||
def uploadVideo(name):
|
||||
if not os.path.exists(name):
|
||||
Common.appendError("Upload File Not Exist {}".format(name))
|
||||
if forceNotUpload is False:
|
||||
b.preUpload(VideoPart(name, os.path.basename(name)))
|
||||
else:
|
||||
|
@ -133,13 +133,15 @@ def getAllStats():
|
||||
"broadcaster": Common.broadcaster.__str__(),
|
||||
"isBroadcasting": Common.isBroadcasting,
|
||||
"streamUrl": Common.streamUrl,
|
||||
"updateTime": Common.updateTime
|
||||
"updateTime": Common.updateTime,
|
||||
"delayTime": Common.delay
|
||||
},
|
||||
"config": {
|
||||
"forceNotBroadcasting": Common.forceNotBroadcasting,
|
||||
"forceNotDownload": Common.forceNotDownload,
|
||||
"forceNotUpload": Common.forceNotUpload,
|
||||
"forceNotEncode": Common.forceNotEncode,
|
||||
"downloadOnly": Common.config['dlO'],
|
||||
},
|
||||
}})
|
||||
|
||||
@ -158,7 +160,8 @@ def getBroadcastStats():
|
||||
"broadcaster": Common.broadcaster.__str__(),
|
||||
"isBroadcasting": Common.isBroadcasting,
|
||||
"streamUrl": Common.streamUrl,
|
||||
"updateTime": Common.updateTime
|
||||
"updateTime": Common.updateTime,
|
||||
"delayTime": Common.delay
|
||||
}
|
||||
}})
|
||||
|
||||
@ -171,6 +174,7 @@ def getConfigStats():
|
||||
"forceNotDownload": Common.forceNotDownload,
|
||||
"forceNotUpload": Common.forceNotUpload,
|
||||
"forceNotEncode": Common.forceNotEncode,
|
||||
"downloadOnly": Common.config['dlO'],
|
||||
}
|
||||
}})
|
||||
|
||||
|
@ -61,12 +61,12 @@ def encode():
|
||||
if Common.forceNotEncode:
|
||||
Common.appendEncodeStatus("设置了不编码,所以[{}]不会编码".format(i))
|
||||
elif os.path.exists(i):
|
||||
isEncode = True
|
||||
if os.path.getsize(i) < 8 * 1024 * 1024:
|
||||
Common.appendEncodeStatus("Encoded File >{}< is too small, will ignore it".format(i))
|
||||
continue
|
||||
else:
|
||||
Common.appendEncodeStatus("Encoding >{}< Start".format(i))
|
||||
isEncode = True
|
||||
_code = os.system("ffmpeg -i {} -c:v copy -c:a copy -f mp4 {} -y".format(i, i[:13] + ".mp4"))
|
||||
if _code != 0:
|
||||
Common.appendError("Encode {} with Non-Zero Return.".format(i))
|
||||
@ -88,15 +88,11 @@ def upload():
|
||||
if i is True:
|
||||
Common.publishVideo(date)
|
||||
break
|
||||
if not os.path.exists(i):
|
||||
Common.appendError("Upload File Not Exist {}".format(i))
|
||||
else:
|
||||
try:
|
||||
Common.uploadVideo(i)
|
||||
except Exception as e:
|
||||
Common.appendError(e.__str__())
|
||||
continue
|
||||
|
||||
try:
|
||||
Common.uploadVideo(i)
|
||||
except Exception as e:
|
||||
Common.appendError(e.__str__())
|
||||
continue
|
||||
i = Common.uploadQueue.get()
|
||||
Common.appendUploadStatus("Upload Daemon Quiting")
|
||||
|
||||
@ -143,16 +139,15 @@ def run():
|
||||
if not Common.api.isValidRoom:
|
||||
Common.appendError("[{}]房间未找到".format(Common.config["l_u"]))
|
||||
return
|
||||
awakeEncode()
|
||||
_count = 0
|
||||
_firstDown = 0
|
||||
while True:
|
||||
if Common.api.isLive and not Common.forceNotBroadcasting:
|
||||
_firstDown = 0
|
||||
if not Common.forceNotDownload:
|
||||
awakeDownload()
|
||||
awakeUpload()
|
||||
awakeEncode()
|
||||
if not Common.forceNotUpload:
|
||||
awakeUpload()
|
||||
if not Common.forceNotEncode:
|
||||
awakeEncode()
|
||||
if _count % 15 == 14:
|
||||
try:
|
||||
Common.api.updRoomInfo()
|
||||
@ -177,14 +172,8 @@ def run():
|
||||
if Common.forceStartUploadThread:
|
||||
awakeUpload()
|
||||
Common.forceStartUploadThread = False
|
||||
if not isEncode and not isDownload:
|
||||
# 防抖,避免主播因特殊情况下播导致直接投递了
|
||||
if _firstDown < 30:
|
||||
_firstDown += 1
|
||||
sleep(60)
|
||||
continue
|
||||
if not isEncode and not isDownload and Common.doDelay():
|
||||
Common.uploadQueue.put(True)
|
||||
_firstDown = 0
|
||||
isEncode = True
|
||||
isDownload = True
|
||||
time.sleep(60)
|
||||
|
@ -6,10 +6,12 @@ function taskUpdate(){
|
||||
$("#broadcaster").text(res.data.broadcast.broadcaster)
|
||||
$("#isBroadcasting").text(res.data.broadcast.isBroadcasting)
|
||||
$("#streamUrl").text(res.data.broadcast.streamUrl)
|
||||
$("#delayTime").text(res.data.broadcast.delayTime)
|
||||
$("#forceNotBroadcasting").text(res.data.config.forceNotBroadcasting)
|
||||
$("#forceNotDownload").text(res.data.config.forceNotDownload)
|
||||
$("#forceNotUpload").text(res.data.config.forceNotUpload)
|
||||
$("#forceNotEncode").text(res.data.config.forceNotEncode)
|
||||
$("#downloadOnly").text(res.data.config.downloadOnly)
|
||||
$("#updateTime").text(res.data.broadcast.updateTime)
|
||||
$("#encodeQueueSize").text(res.data.encodeQueueSize)
|
||||
$("#uploadQueueSize").text(res.data.uploadQueueSize)
|
||||
@ -54,4 +56,4 @@ function taskUpdate(){
|
||||
}
|
||||
|
||||
taskUpdate()
|
||||
setInterval(taskUpdate,10000)
|
||||
setInterval(taskUpdate,8000)
|
||||
|
@ -24,6 +24,10 @@
|
||||
<td>信息更新时间</td>
|
||||
<td><span id="updateTime"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>延迟投稿时间</td>
|
||||
<td><span id="delayTime"></span></td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr/>
|
||||
<h1>特殊设置</h1>
|
||||
@ -44,6 +48,10 @@
|
||||
<td>是否设置强制不转码</td>
|
||||
<td><span id="forceNotEncode"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>是否设置为仅下载(不上传不转码)</td>
|
||||
<td><span id="downloadOnly"></span></td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr/>
|
||||
<h1>当前状态</h1>
|
||||
|
Reference in New Issue
Block a user