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