修复Api更改导致的未开播时报错问题
This commit is contained in:
parent
5f949ccf34
commit
3c872b0484
36
api.py
36
api.py
@ -53,7 +53,8 @@ class XiGuaLiveApi:
|
||||
:param args:
|
||||
"""
|
||||
print(msg)
|
||||
print(*args)
|
||||
if DEBUG:
|
||||
print(*args)
|
||||
|
||||
def onPresent(self, gift: Gift):
|
||||
"""
|
||||
@ -143,13 +144,22 @@ class XiGuaLiveApi:
|
||||
"&device_platform=android".format(roomID=self.roomID),
|
||||
headers={"Content-Type":"application/x-www-form-urlencoded"})
|
||||
d = p.json()
|
||||
except:
|
||||
except Exception as e:
|
||||
if DEBUG:
|
||||
print("ReqError@UpdRoomInfo")
|
||||
print(e.__str__())
|
||||
if p:
|
||||
print(p.status_code)
|
||||
print(p.text)
|
||||
return False
|
||||
self.isValidRoom = d["base_resp"]["status_code"] == 0
|
||||
if d["base_resp"]["status_code"] != 0:
|
||||
if DEBUG:
|
||||
print("CodeIsnot0@UpdRoomInfo")
|
||||
print(d)
|
||||
return False
|
||||
if "room" not in d and d["room"] is None:
|
||||
self.apiChangedError("Api发生改变,请及时联系我")
|
||||
self.apiChangedError("Api发生改变,请及时联系我", d)
|
||||
return False
|
||||
self._rawRoomInfo = d["room"]
|
||||
self.isLive = d["room"]["status"] == 2
|
||||
@ -161,12 +171,16 @@ class XiGuaLiveApi:
|
||||
self.lottery = l
|
||||
return True
|
||||
else:
|
||||
p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android"
|
||||
"&format=json&keyword={}".format(self.name))
|
||||
try:
|
||||
p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android"
|
||||
"&format=json&keyword={}".format(self.name))
|
||||
d = p.json()
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
print(p.text)
|
||||
if DEBUG:
|
||||
print(e.__str__())
|
||||
if p:
|
||||
print(p.status_code)
|
||||
print(p.text)
|
||||
return
|
||||
if "data" in d and d["data"] is not None:
|
||||
for i in d["data"]:
|
||||
@ -175,8 +189,14 @@ class XiGuaLiveApi:
|
||||
if len(i["cells"]) == 0:
|
||||
return
|
||||
self.isValidRoom = True
|
||||
self.isLive = i["cells"][0]["anchor"]["user_info"]["is_living"]
|
||||
self.roomID = int(i["cells"][0]["anchor"]["room_id"])
|
||||
if "is_living" in i["cells"][0]["anchor"]["user_info"]:
|
||||
self.isLive = i["cells"][0]["anchor"]["user_info"]["is_living"]
|
||||
else:
|
||||
self.isLive = False
|
||||
if "room_id" in i["cells"][0]["anchor"]:
|
||||
self.roomID = int(i["cells"][0]["anchor"]["room_id"])
|
||||
else:
|
||||
self.isLive = False
|
||||
self.roomLiver = User(i["cells"][0])
|
||||
if self.isLive:
|
||||
return self.updRoomInfo()
|
||||
|
@ -156,18 +156,18 @@ if __name__ == "__main__":
|
||||
et.setDaemon(True)
|
||||
et.start()
|
||||
_count = 0
|
||||
_count_error = 0
|
||||
while True:
|
||||
if api.isLive:
|
||||
if d is None:
|
||||
d = datetime.strftime(datetime.now(), "%Y_%m_%d")
|
||||
if not t.is_alive():
|
||||
_count = 0
|
||||
_count_error += 1
|
||||
_preT = api.playlist
|
||||
t = threading.Thread(target=download, args=(_preT,))
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
if not ut.is_alive():
|
||||
_count = 0
|
||||
ut = threading.Thread(target=upload, args=(d,))
|
||||
ut.setDaemon(True)
|
||||
ut.start()
|
||||
@ -179,11 +179,14 @@ if __name__ == "__main__":
|
||||
try:
|
||||
api.updRoomInfo()
|
||||
_count = 0
|
||||
_count_error = 0
|
||||
except Exception as e:
|
||||
print(e.__str__())
|
||||
time.sleep(10)
|
||||
_count += 1
|
||||
_count_error += 1
|
||||
continue
|
||||
if _count_error > 15:
|
||||
api.isLive = False
|
||||
_count += 1
|
||||
time.sleep(20)
|
||||
else:
|
||||
@ -196,4 +199,7 @@ if __name__ == "__main__":
|
||||
from config import config
|
||||
# print("主播未开播,等待1分钟后重试")
|
||||
time.sleep(60)
|
||||
api.updRoomInfo()
|
||||
try:
|
||||
api.updRoomInfo()
|
||||
except Exception as e:
|
||||
print(e.__str__())
|
||||
|
Reference in New Issue
Block a user