下拨投稿逻辑

This commit is contained in:
Jerry Yan 2020-01-03 09:19:45 +08:00
parent c335e45852
commit 6d4127c90b
2 changed files with 11 additions and 21 deletions

View File

@ -1,7 +1,6 @@
import os import os
import queue import queue
from datetime import datetime, timedelta from datetime import datetime, timedelta
from glob import glob
import psutil import psutil
from api import XiGuaLiveApi from api import XiGuaLiveApi
@ -37,10 +36,10 @@ config = {
"dly": 30, "dly": 30,
"enc": "ffmpeg -i {f} -c:v copy -c:a copy -f mp4 {t} -y" "enc": "ffmpeg -i {f} -c:v copy -c:a copy -f mp4 {t} -y"
} }
doCleanTime = datetime.now() doCleanTime = datetime.fromtimestamp(0)
loginTime = datetime.now() loginTime = datetime.fromtimestamp(0)
_clean_flag = None _clean_flag = None
delay = datetime.now() delay = datetime.fromtimestamp(0)
b = Bilibili() b = Bilibili()
network = [{ network = [{
@ -77,11 +76,11 @@ def resetDelay():
def doDelay(): def doDelay():
global delay, isBroadcasting, isEncode, isUpload global delay, isBroadcasting
if isBroadcasting or isEncode or isUpload: if isBroadcasting:
resetDelay() resetDelay()
return False return False
return datetime.now() > delay return (datetime.now() - delay).seconds < 120
def updateNetwork(): def updateNetwork():
@ -299,7 +298,7 @@ def appendError(obj):
def loginBilibili(force=False): def loginBilibili(force=False):
if config["dlO"] is False or forceNotUpload is False: if config["dlO"] is False or forceNotUpload is False:
global loginTime global loginTime
if not force and getTimeDelta(datetime.now(), loginTime) < 86400 * 5: if not force and getTimeDelta(datetime.now(), loginTime) < 86400 * 10:
return False return False
res = b.login(config["b_u"], config["b_p"]) res = b.login(config["b_u"], config["b_p"])
loginTime = datetime.now() loginTime = datetime.now()
@ -364,14 +363,14 @@ def uploadVideo(name):
def publishVideo(date): def publishVideo(date):
global isUpload
if forceNotUpload is False: if forceNotUpload is False:
b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"], b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"],
source=config["src"], no_reprint=0) source=config["src"], no_reprint=0)
b.clear() b.clear()
global delay
delay = datetime.fromtimestamp(0)
else: else:
appendUploadStatus("设置了不上传,所以[{}]的录播不会上传了".format(date)) appendUploadStatus("设置了不上传,所以[{}]的录播不会投了".format(date))
isUpload = False
def encodeVideo(name): def encodeVideo(name):
@ -384,8 +383,6 @@ def encodeVideo(name):
if os.path.getsize(name) < 8 * 1024 * 1024: if os.path.getsize(name) < 8 * 1024 * 1024:
appendEncodeStatus("Encoded File >{}< is too small, will ignore it".format(name)) appendEncodeStatus("Encoded File >{}< is too small, will ignore it".format(name))
return False return False
global isEncode
isEncode = True
appendEncodeStatus("Encoding >{}< Start".format(name)) appendEncodeStatus("Encoding >{}< Start".format(name))
_new_name = os.path.splitext(name)[0] + ".mp4" _new_name = os.path.splitext(name)[0] + ".mp4"
_code = os.system(config["enc"].format(f=name, t=_new_name)) _code = os.system(config["enc"].format(f=name, t=_new_name))
@ -394,7 +391,4 @@ def encodeVideo(name):
return False return False
Common.modifyLastEncodeStatus("Encode >{}< Finished".format(name)) Common.modifyLastEncodeStatus("Encode >{}< Finished".format(name))
uploadQueue.put(_new_name) uploadQueue.put(_new_name)
isEncode = False
loginBilibili(True)

View File

@ -1,5 +1,3 @@
import shutil
import sys
import time import time
from datetime import datetime from datetime import datetime
import threading import threading
@ -111,7 +109,7 @@ def awakeUpload():
def run(): def run():
Common.refreshDownloader() Common.refreshDownloader()
if not Common.api.isValidUser: if not Common.api.isValidUser:
Common.appendError("[{}]房间未找到".format(Common.config["l_u"])) Common.appendError("[{}]用户未找到".format(Common.api.name))
return return
while True: while True:
if Common.api.isLive and not Common.forceNotBroadcasting: if Common.api.isLive and not Common.forceNotBroadcasting:
@ -144,6 +142,4 @@ def run():
Common.forceStartUploadThread = False Common.forceStartUploadThread = False
if Common.doDelay(): if Common.doDelay():
Common.uploadQueue.put(True) Common.uploadQueue.put(True)
Common.isEncode = True
Common.isUpload = True
time.sleep(5) time.sleep(5)