修正因未开播而导致的Queue内占满了False的BUG

This commit is contained in:
2019-01-26 18:54:41 +08:00
parent cf8cbaae8c
commit 82b076df3f

View File

@ -12,7 +12,7 @@ q = queue.Queue()
base_uri = "" base_uri = ""
isUpload = False isUpload = False
uq = queue.Queue() uq = queue.Queue()
d = datetime.strftime(datetime.now(),"%Y_%m_%d")
class downloader(XiGuaLiveApi): class downloader(XiGuaLiveApi):
files = [] files = []
@ -32,24 +32,34 @@ class downloader(XiGuaLiveApi):
def onLike(self, user): def onLike(self, user):
pass pass
def onAd(self, i): def onAd(self, i):
pass pass
def onChat(self, chat): def onChat(self, chat):
pass pass
def onEnter(self, msg): def onEnter(self, msg):
pass pass
def onJoin(self, user): def onJoin(self, user):
pass pass
def onLeave(self, json): def onLeave(self, json):
self.updRoomInfo() self.updRoomInfo()
def onMessage(self, msg): def onMessage(self, msg):
pass pass
def onPresent(self, gift): def onPresent(self, gift):
pass pass
def onPresentEnd(self, gift): def onPresentEnd(self, gift):
pass pass
def onSubscribe(self, user): def onSubscribe(self, user):
pass pass
def preDownload(self): def preDownload(self):
global base_uri global base_uri
if self.playlist: if self.playlist:
@ -63,16 +73,17 @@ class downloader(XiGuaLiveApi):
if i not in self.files: if i not in self.files:
self.files.append(i) self.files.append(i)
print("{} : Add Sequence {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), print("{} : Add Sequence {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"),
len(self.files))) len(self.files)))
q.put(i) q.put(i)
self.genNewName() self.genNewName()
def genNewName(self): def genNewName(self):
if len(self.files) > 800: if len(self.files) > 800:
q.put(True) q.put(True)
self.files.clear() self.files.clear()
def download(path=datetime.strftime(datetime.now(),"%Y%m%d_%H%M.ts")): def download(path=datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts")):
global isUpload global isUpload
print("{} : Download Daemon Starting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"))) print("{} : Download Daemon Starting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
n = False n = False
@ -84,31 +95,31 @@ def download(path=datetime.strftime(datetime.now(),"%Y%m%d_%H%M.ts")):
break break
print("{} : Download {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i)) print("{} : Download {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
try: try:
_p = requests.get("{}{}".format(base_uri,i)) _p = requests.get("{}{}".format(base_uri, i))
except: except:
continue continue
f = open(path, "ab") f = open(path, "ab")
f.write(_p.content) f.write(_p.content)
f.close() f.close()
n=True n = True
i = q.get() i = q.get()
if n: if n:
isUpload = True
uq.put(path) uq.put(path)
print("{} : Download Daemon Quiting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"))) print("{} : Download Daemon Quiting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
isUpload = True
def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
def upload(date = datetime.strftime(datetime.now(), "%Y_%m_%d")):
print("{} : Upload Daemon Starting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"))) print("{} : Upload Daemon Starting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
i = uq.get() i = uq.get()
while True: while True:
if isinstance(i, bool): if isinstance(i, bool):
print("{} : Upload Daemon Receive Command {}"
.format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
if i is True: if i is True:
print("自动投稿中,请稍后") print("自动投稿中,请稍后")
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= "https://live.ixigua.com/userlive/97621754276", no_reprint= 0) source="https://live.ixigua.com/userlive/97621754276", no_reprint=0)
print("{} : Upload Daemon Receive Command {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
break break
print("{} : Upload {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i)) print("{} : Upload {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
try: try:
@ -140,6 +151,7 @@ if __name__ == "__main__":
input("房间不存在") input("房间不存在")
sys.exit() sys.exit()
print("=" * 30) print("=" * 30)
d = datetime.strftime(datetime.now(), "%Y_%m_%d")
_preT = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts") _preT = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts")
t = threading.Thread(target=download, args=(_preT,)) t = threading.Thread(target=download, args=(_preT,))
ut = threading.Thread(target=upload, args=(d,)) ut = threading.Thread(target=upload, args=(d,))
@ -162,7 +174,9 @@ if __name__ == "__main__":
pass pass
time.sleep(3) time.sleep(3)
else: else:
q.put(False) if d is not None:
q.put(False)
d = None
if isUpload: if isUpload:
uq.put(True) uq.put(True)
isUpload = False isUpload = False
@ -170,5 +184,4 @@ if __name__ == "__main__":
pass pass
# print("主播未开播,等待1分钟后重试") # print("主播未开播,等待1分钟后重试")
time.sleep(60) time.sleep(60)
d=None
api.updRoomInfo() api.updRoomInfo()