From 9fb552e6dcc56b0814900571342e173c3813c42b Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Mon, 25 Nov 2019 09:34:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E9=97=B4=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 22 ++++++++++------------ liveDownloader.py | 18 +++++++----------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/api.py b/api.py index 26209aa..5d41f42 100644 --- a/api.py +++ b/api.py @@ -9,6 +9,7 @@ from Struct.Chat import Chat from Struct.Lottery import Lottery import requests import time +from datetime import datetime, timedelta DEBUG = False @@ -24,7 +25,6 @@ class XiGuaLiveApi: roomLiver = None roomPopularity = 0 _cursor = "0" - _updRoomCount = 0 lottery = None s = requests.session() @@ -35,7 +35,8 @@ class XiGuaLiveApi: :param name: 主播名 """ self.name = name - self.updRoomInfo() + self._updRoomAt = datetime.now() + self.updRoomInfo(True) def _updateRoomPopularity(self, _data): """ @@ -215,11 +216,14 @@ class XiGuaLiveApi: self.lottery = l return True - def updRoomInfo(self): + def updRoomInfo(self, force=False): """ 更新房间信息 :return: """ + if not force and self._updRoomAt > (datetime.now() - timedelta(minutes=2)): + return self.isLive + self._updRoomAt = datetime.now() if self.isLive: return self._updateRoomOnly() else: @@ -304,14 +308,13 @@ class XiGuaLiveApi: elif i["common"]['method'] == "VideoLiveControlMessage": print("消息:", "主播离开一小会") # 这个消息代表主播下播了,直接更新房间信息 - self.updRoomInfo() + self.updRoomInfo(True) elif i["common"]['method'] == "VideoLiveDiggMessage": self.onLike(User(i)) else: pass if self.lottery is None or self.lottery.ID == 0: self.lottery = Lottery(i) - self._updRoomCount += 1 # 更新抽奖信息 if self.lottery is not None and self.lottery.ID != 0: self.lottery.update() @@ -319,10 +322,7 @@ class XiGuaLiveApi: self.onLottery(self.lottery) self.lottery = None # 2分钟自动更新下房间信息 - if self._updRoomCount > 120 or len(d['data']) == 0: - self.updRoomInfo() - self._updRoomCount = 0 - return + self.updRoomInfo(len(d['data']) == 0) if __name__ == "__main__": @@ -347,8 +347,6 @@ if __name__ == "__main__": time.sleep(5) except Exception as e: print(e) - time.sleep(1) else: - print("主播未开播,等待1分钟后重试") - time.sleep(60) + print("主播未开播,等待2分钟后重试") api.updRoomInfo() diff --git a/liveDownloader.py b/liveDownloader.py index 7b2f9f1..4d3a831 100644 --- a/liveDownloader.py +++ b/liveDownloader.py @@ -113,7 +113,6 @@ def run(): if not Common.api.isValidRoom: Common.appendError("[{}]房间未找到".format(Common.config["l_u"])) return - _count = 0 while True: if Common.api.isLive and not Common.forceNotBroadcasting: if not Common.forceNotDownload: @@ -122,15 +121,12 @@ def run(): awakeUpload() if not Common.forceNotEncode: awakeEncode() - if _count % 15 == 14: - try: - Common.api.updRoomInfo() - _count = 0 - _count_error = 0 - except Exception as e: - Common.appendError(e.__str__()) - time.sleep(5) - continue + try: + Common.api.updRoomInfo() + except Exception as e: + Common.appendError(e.__str__()) + time.sleep(5) + continue time.sleep(5) else: try: @@ -148,4 +144,4 @@ def run(): Common.forceStartUploadThread = False if Common.doDelay(): Common.uploadQueue.put(True) - time.sleep(60) + time.sleep(15)