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