更新大部分判断,WinMain加入全部显示参数启动
This commit is contained in:
parent
52a49e5e2d
commit
4270612a98
34
WinMain.py
34
WinMain.py
@ -11,6 +11,7 @@ from api import XiGuaLiveApi as Api
|
||||
import msvcrt
|
||||
import ctypes
|
||||
|
||||
SHOW_ALL = False
|
||||
|
||||
def readInput(caption, default, timeout: int = 5):
|
||||
start_time = time.time()
|
||||
@ -126,19 +127,26 @@ class WinMain(Api):
|
||||
resetColor()
|
||||
|
||||
def onSubscribe(self, user: User):
|
||||
return
|
||||
if SHOW_ALL:
|
||||
set_cmd_text_color(FOREGROUND_DARKGRAY)
|
||||
print("用户", user, "关注了主播")
|
||||
resetColor()
|
||||
|
||||
def onEnter(self, msg:MemberMsg):
|
||||
if msg.type > 1:
|
||||
if SHOW_ALL:
|
||||
set_cmd_text_color(FOREGROUND_DARKGRAY)
|
||||
print("提示 : ", msg)
|
||||
print("提示 :", msg)
|
||||
resetColor()
|
||||
|
||||
def onChat(self, chat: Chat):
|
||||
print(chat)
|
||||
if SHOW_ALL:
|
||||
print(chat)
|
||||
|
||||
def onPresent(self, gift: Gift):
|
||||
return
|
||||
if SHOW_ALL:
|
||||
set_cmd_text_color(FOREGROUND_DARKGRAY)
|
||||
print("连击 :", gift)
|
||||
resetColor()
|
||||
|
||||
def onPresentEnd(self, gift: Gift):
|
||||
set_cmd_text_color(BACKGROUND_WHITE | FOREGROUND_BLACK)
|
||||
@ -146,7 +154,10 @@ class WinMain(Api):
|
||||
resetColor()
|
||||
|
||||
def onLike(self, user: User):
|
||||
return
|
||||
if SHOW_ALL:
|
||||
set_cmd_text_color(FOREGROUND_DARKGRAY)
|
||||
print("用户", user, "点了喜欢")
|
||||
resetColor()
|
||||
|
||||
def onLeave(self, json: any):
|
||||
return
|
||||
@ -163,10 +174,15 @@ if __name__ == "__main__":
|
||||
resetColor()
|
||||
print("西瓜直播弹幕助手 by JerryYan")
|
||||
if len(sys.argv) > 1:
|
||||
room = int(sys.argv[1])
|
||||
if sys.argv[-1] == "a":
|
||||
SHOW_ALL = True
|
||||
try:
|
||||
room = int(sys.argv[1])
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
room = int(readInput("请输入房间号,默认为永恒的直播间", room, 3))
|
||||
room = int(readInput("请输入用户ID号,默认为永恒的ID号", room, 3))
|
||||
except ValueError:
|
||||
pass
|
||||
api = WinMain(room)
|
||||
@ -185,6 +201,8 @@ if __name__ == "__main__":
|
||||
warning(e)
|
||||
time.sleep(1)
|
||||
else:
|
||||
set_cmd_text_color(FOREGROUND_RED)
|
||||
print("主播未开播,等待1分钟后重试")
|
||||
resetColor()
|
||||
time.sleep(60)
|
||||
api.updRoomInfo()
|
||||
|
36
api.py
36
api.py
@ -28,15 +28,16 @@ class XiGuaLiveApi:
|
||||
Gift.update(self.roomID)
|
||||
self._enterRoom()
|
||||
|
||||
def notLiveError(self):
|
||||
print("主播未开播")
|
||||
|
||||
def _updateRoomInfo(self, json):
|
||||
if "Msg" in json:
|
||||
if "member_count" in json["Msg"]:
|
||||
self.roomMember = json["Msg"]["member_count"]
|
||||
if "popularity" in json["Msg"]:
|
||||
self.roomPopularity = json["Msg"]["popularity"]
|
||||
elif "data" in json:
|
||||
if "popularity" in json["data"]:
|
||||
self.roomPopularity = json["data"]["popularity"]
|
||||
|
||||
|
||||
def apiChangedError(self, msg: str, *args):
|
||||
print(msg)
|
||||
@ -85,22 +86,19 @@ class XiGuaLiveApi:
|
||||
if DEBUG:
|
||||
print(p.text)
|
||||
d = p.json()
|
||||
if "data" not in d:
|
||||
if "data" not in d or "title" not in d["data"] or "id" not in d["data"]:
|
||||
self.apiChangedError("无法获取RoomID,请与我联系")
|
||||
return
|
||||
self.isValidRoom = True
|
||||
self._rawRoomInfo = d["data"]
|
||||
self.roomLiver = User(d)
|
||||
self.roomTitle = self._rawRoomInfo["title"]
|
||||
if "id" in d["data"]:
|
||||
self.roomID = d["data"]["id"]
|
||||
else:
|
||||
self.apiChangedError("无法获取RoomID,请与我联系")
|
||||
if "FinishTime" in d["data"]:
|
||||
self.isLive = False
|
||||
self.notLiveError()
|
||||
else:
|
||||
self.roomTitle = d["data"]["title"]
|
||||
self.roomID = d["data"]["id"]
|
||||
self._updateRoomInfo(d)
|
||||
if "status" in d["data"] and d["data"]["status"] == 2:
|
||||
self.isLive = True
|
||||
else:
|
||||
self.isLive = False
|
||||
|
||||
def getDanmaku(self):
|
||||
if not self.isValidRoom:
|
||||
@ -111,17 +109,15 @@ class XiGuaLiveApi:
|
||||
cursor=self._cursor
|
||||
))
|
||||
d = p.json()
|
||||
if "data" not in d:
|
||||
self.apiChangedError("数据结构改变,请与我联系", d)
|
||||
return
|
||||
if "Extra" not in d["data"]:
|
||||
self.apiChangedError("数据结构改变,请与我联系", d)
|
||||
return
|
||||
if "Cursor" not in d["data"]["Extra"]:
|
||||
if "data" not in d or "Extra" not in d["data"] or "Cursor" not in d["data"]["Extra"]:
|
||||
if DEBUG:
|
||||
print(d)
|
||||
self.apiChangedError("数据结构改变,请与我联系", d)
|
||||
return
|
||||
else:
|
||||
self._cursor = d["data"]["Extra"]["Cursor"]
|
||||
if DEBUG:
|
||||
print("Cursor",self._cursor)
|
||||
if "LiveMsgs" not in d["data"]:
|
||||
return
|
||||
for i in d['data']['LiveMsgs']:
|
||||
|
Reference in New Issue
Block a user