Api使用Android app弹幕协议
This commit is contained in:
parent
e46e4ec0d7
commit
5da70e81f9
10
Chat.py
10
Chat.py
@ -2,8 +2,8 @@ from User import User
|
|||||||
|
|
||||||
class Chat:
|
class Chat:
|
||||||
|
|
||||||
content:str=""
|
content: str =""
|
||||||
user:User=None
|
user: User=None
|
||||||
|
|
||||||
def __init__(self, json=None):
|
def __init__(self, json=None):
|
||||||
if json:
|
if json:
|
||||||
@ -11,9 +11,9 @@ class Chat:
|
|||||||
|
|
||||||
def parse(self, json):
|
def parse(self, json):
|
||||||
self.user = User(json)
|
self.user = User(json)
|
||||||
if "Msg" in json:
|
if "extra" in json:
|
||||||
if "content" in json["Msg"]:
|
if "content" in json["extra"]:
|
||||||
self.content = json["Msg"]['content']
|
self.content = json["extra"]['content']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} : {}".format(self.user,self.content)
|
return "{} : {}".format(self.user,self.content)
|
||||||
|
23
Gift.py
23
Gift.py
@ -16,26 +16,27 @@ class Gift:
|
|||||||
|
|
||||||
def parse(self, json):
|
def parse(self, json):
|
||||||
self.user = User(json)
|
self.user = User(json)
|
||||||
if "Msg" in json:
|
if "extra" in json:
|
||||||
if "present_end_info" in json["Msg"]:
|
if "present_info" in json["extra"] and json["extra"]['present_info'] is not None:
|
||||||
self.ID = json["Msg"]['present_end_info']['id']
|
self.ID = int(json["extra"]['present_info']['id'])
|
||||||
self.count = json["Msg"]['present_end_info']['count']
|
self.count = json["extra"]['present_info']['repeat_count']
|
||||||
elif "present_info" in json["Msg"]:
|
elif "present_end_info" in json["extra"] and json["extra"]['present_end_info'] is not None:
|
||||||
self.ID = json["Msg"]['present_info']['id']
|
self.ID = int(json["extra"]['present_end_info']['id'])
|
||||||
self.count = json["Msg"]['present_info']['repeat_count']
|
self.count = json["extra"]['present_end_info']['count']
|
||||||
if self.ID in self.giftList:
|
if self.ID in self.giftList:
|
||||||
self.amount = self.giftList[self.ID]["Price"] * self.count
|
self.amount = self.giftList[self.ID]["Price"] * self.count
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update(roomID):
|
def update(roomID):
|
||||||
Gift.roomID = roomID
|
Gift.roomID = roomID
|
||||||
p = requests.get("https://live.ixigua.com/api/gifts/{roomID}".format(roomID= roomID))
|
p = requests.get("https://i.snssdk.com/videolive/gift/get_gift_list?room_id={roomID}".format(roomID= roomID))
|
||||||
d = p.json()
|
d = p.json()
|
||||||
if isinstance(d, int) or "data" not in d:
|
if "gift_info" not in d:
|
||||||
print("错误:礼物更新失败")
|
print("错误:礼物更新失败")
|
||||||
else:
|
else:
|
||||||
for i in d["data"]:
|
for i in d["gift_info"]:
|
||||||
Gift.giftList[i["ID"]] = {"Name": i["Name"], "Price": i["DiamondCount"]}
|
_id = int(i["id"])
|
||||||
|
Gift.giftList[_id] = {"Name": i["name"], "Price": i["diamond_count"]}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.ID in self.giftList:
|
if self.ID in self.giftList:
|
||||||
|
11
MemberMsg.py
11
MemberMsg.py
@ -12,11 +12,11 @@ class MemberMsg:
|
|||||||
|
|
||||||
def parse(self, json):
|
def parse(self, json):
|
||||||
self.user = User(json)
|
self.user = User(json)
|
||||||
if "Msg" in json:
|
if "extra" in json:
|
||||||
if "action" in json["Msg"]:
|
if "action" in json["extra"]:
|
||||||
self.type = json["Msg"]['action']
|
self.type = json["extra"]['action']
|
||||||
elif "content" in json["Msg"]:
|
elif "content" in json["extra"]:
|
||||||
self.content = json["Msg"]['content']
|
self.content = json["extra"]['content']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.type == 3:
|
if self.type == 3:
|
||||||
@ -28,6 +28,7 @@ class MemberMsg:
|
|||||||
elif self.type == 1:
|
elif self.type == 1:
|
||||||
return "{} 进入了房间".format(self.user)
|
return "{} 进入了房间".format(self.user)
|
||||||
else:
|
else:
|
||||||
|
print(self.type)
|
||||||
return self.content.format(self.user)
|
return self.content.format(self.user)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
@ -4,5 +4,9 @@
|
|||||||
因个人能力有限,不懂C#,无法做出界面版,只好用控制台版先顶着
|
因个人能力有限,不懂C#,无法做出界面版,只好用控制台版先顶着
|
||||||
|
|
||||||
### 计划更新:
|
### 计划更新:
|
||||||
- ~~使用android app协议~~ Android协议在未登陆时不显示赠送西瓜礼物及其他多数不显示的内容
|
+ √ 使用android app协议
|
||||||
- 闲的无聊的时候看一看有没有好用的GUI轮子可以用用
|
|
||||||
|
除从用户ID获取roomID及判断是否在播外,其他均改为Android Api
|
||||||
|
- √ 闲的无聊的时候看一看有没有好用的GUI轮子可以用用
|
||||||
|
|
||||||
|
已基于BiliLive_dm制作出初代西瓜直播弹幕姬,api未跟进
|
||||||
|
22
User.py
22
User.py
@ -4,25 +4,33 @@ class User:
|
|||||||
brand: str = ""
|
brand: str = ""
|
||||||
level: int = 0
|
level: int = 0
|
||||||
type: int = 0
|
type: int = 0
|
||||||
|
block: bool = False
|
||||||
|
mute: bool = False
|
||||||
|
|
||||||
def __init__(self, json=None):
|
def __init__(self, json=None):
|
||||||
if json:
|
if json:
|
||||||
self.parse(json)
|
self.parse(json)
|
||||||
|
|
||||||
def parse(self, json):
|
def parse(self, json):
|
||||||
if "Msg" in json:
|
if "extra" in json:
|
||||||
if "user" in json["Msg"]:
|
if "user" in json["extra"] and json["extra"]["user"] is not None:
|
||||||
self.ID = json["Msg"]['user']['user_id']
|
self.ID = json["extra"]['user']['user_id']
|
||||||
self.name = json["Msg"]['user']['name']
|
self.name = json["extra"]['user']['name']
|
||||||
if "discipulus_info" in json["Msg"]:
|
if "im_discipulus_info" in json["extra"] and json["extra"]["im_discipulus_info"] is not None:
|
||||||
self.level = json["Msg"]["discipulus_info"]["level"]
|
self.level = json["extra"]["im_discipulus_info"]["level"]
|
||||||
self.brand = json["Msg"]["discipulus_info"]["discipulus_group_title"]
|
self.brand = json["extra"]["im_discipulus_info"]["discipulus_group_title"]
|
||||||
|
if "user_room_auth_status" in json["extra"] and json["extra"]["user_room_auth_status"] is not None:
|
||||||
|
self.type = json["extra"]["user_room_auth_status"]["user_type"]
|
||||||
|
self.block = json["extra"]["user_room_auth_status"]["is_block"]
|
||||||
|
self.mute = json["extra"]["user_room_auth_status"]["is_silence"]
|
||||||
elif "data" in json:
|
elif "data" in json:
|
||||||
if "anchorInfo" in json["data"]:
|
if "anchorInfo" in json["data"]:
|
||||||
self.ID = json["data"]['anchorInfo']['id']
|
self.ID = json["data"]['anchorInfo']['id']
|
||||||
self.name = json["data"]['anchorInfo']['name']
|
self.name = json["data"]['anchorInfo']['name']
|
||||||
if self.type is None:
|
if self.type is None:
|
||||||
self.type = 0
|
self.type = 0
|
||||||
|
if isinstance(self.level, str):
|
||||||
|
self.level = int(self.level)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.level == 0:
|
if self.level == 0:
|
||||||
|
@ -104,17 +104,13 @@ class WinMain(Api):
|
|||||||
if self._tmp > 10:
|
if self._tmp > 10:
|
||||||
self._tmp = 0
|
self._tmp = 0
|
||||||
if self._tmp < 5 :
|
if self._tmp < 5 :
|
||||||
return "{} {} --弹幕助手 by JerryYan".format(self.roomLiver, "的直播间")
|
return "{} 的直播间 --弹幕助手 by JerryYan".format(self.roomLiver)
|
||||||
else:
|
else:
|
||||||
if self.roomPopularity == 0:
|
if self.roomPopularity == 0:
|
||||||
self._tmp = 0
|
self._tmp = 0
|
||||||
return self.getTitle()
|
return self.getTitle()
|
||||||
else:
|
else:
|
||||||
if self.roomMember > 0:
|
return "人气:{} --弹幕助手 by JerryYan".format(self.roomPopularity)
|
||||||
return "观看:{} 人气:{} --弹幕助手 by JerryYan".format(self.roomMember, self.roomPopularity)
|
|
||||||
else:
|
|
||||||
return "观看:待刷新 人气:{} --弹幕助手 by JerryYan".format(self.roomPopularity)
|
|
||||||
|
|
||||||
|
|
||||||
def onMessage(self, msg: str):
|
def onMessage(self, msg: str):
|
||||||
set_cmd_text_color(FOREGROUND_DARKGRAY)
|
set_cmd_text_color(FOREGROUND_DARKGRAY)
|
||||||
|
59
api.py
59
api.py
@ -21,7 +21,7 @@ class XiGuaLiveApi:
|
|||||||
roomLiver: User = None
|
roomLiver: User = None
|
||||||
roomPopularity: int = 0
|
roomPopularity: int = 0
|
||||||
roomMember: int = 0
|
roomMember: int = 0
|
||||||
_cursor = ""
|
_cursor:str = "0"
|
||||||
|
|
||||||
def __init__(self, room: int):
|
def __init__(self, room: int):
|
||||||
self.room = room
|
self.room = room
|
||||||
@ -30,11 +30,9 @@ class XiGuaLiveApi:
|
|||||||
self._enterRoom()
|
self._enterRoom()
|
||||||
|
|
||||||
def _updateRoomInfo(self, json):
|
def _updateRoomInfo(self, json):
|
||||||
if "Msg" in json:
|
if "extra" in json:
|
||||||
if "member_count" in json["Msg"]:
|
if "member_count" in json["extra"] and json["extra"]["member_count"] > 0:
|
||||||
self.roomMember = json["Msg"]["member_count"]
|
self.roomPopularity = json["extra"]["member_count"]
|
||||||
if "popularity" in json["Msg"]:
|
|
||||||
self.roomPopularity = json["Msg"]["popularity"]
|
|
||||||
elif "data" in json:
|
elif "data" in json:
|
||||||
if "popularity" in json["data"]:
|
if "popularity" in json["data"]:
|
||||||
self.roomPopularity = json["data"]["popularity"]
|
self.roomPopularity = json["data"]["popularity"]
|
||||||
@ -77,7 +75,11 @@ class XiGuaLiveApi:
|
|||||||
def _enterRoom(self):
|
def _enterRoom(self):
|
||||||
if not self.isValidRoom:
|
if not self.isValidRoom:
|
||||||
return
|
return
|
||||||
p = s.post("https://live.ixigua.com/api/room/enter/{roomID}".format(roomID=self.roomID))
|
p = s.post("https://i.snssdk.com/videolive/room/enter&version_code=730"
|
||||||
|
"&device_platform=android",
|
||||||
|
data="room_id={roomID}&version_code=730"
|
||||||
|
"&device_platform=android".format(roomID=self.roomID),
|
||||||
|
headers={"Content-Type":"application/x-www-form-urlencoded"})
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(p.text)
|
print(p.text)
|
||||||
|
|
||||||
@ -103,56 +105,57 @@ class XiGuaLiveApi:
|
|||||||
def getDanmaku(self):
|
def getDanmaku(self):
|
||||||
if not self.isValidRoom:
|
if not self.isValidRoom:
|
||||||
return
|
return
|
||||||
p = s.get("https://live.ixigua.com/api/msg/list/{roomID}?AnchorID={room}&Cursor={cursor}".format(
|
p = s.get("https://i.snssdk.com/videolive/im/get_msg?cursor={cursor}&room_id={roomID}&version_code=730"
|
||||||
roomID=self.roomID,
|
"&device_platform=android".format(
|
||||||
room=self.room,
|
roomID=self.roomID,
|
||||||
cursor=self._cursor
|
cursor=self._cursor
|
||||||
))
|
))
|
||||||
d = p.json()
|
d = p.json()
|
||||||
if "data" not in d or "Extra" not in d["data"] or "Cursor" not in d["data"]["Extra"]:
|
if "data" not in d or "extra" not in d or "cursor" not in d["extra"]:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(d)
|
print(d)
|
||||||
self.apiChangedError("数据结构改变,请与我联系")
|
self.apiChangedError("数据结构改变,请与我联系")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self._cursor = d["data"]["Extra"]["Cursor"]
|
self._cursor = d["extra"]["cursor"]
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print("Cursor", self._cursor)
|
print("Cursor", self._cursor)
|
||||||
if "LiveMsgs" not in d["data"]:
|
if len(d['data']) == 0:
|
||||||
self.updRoomInfo()
|
self.updRoomInfo()
|
||||||
return
|
return
|
||||||
for i in d['data']['LiveMsgs']:
|
for i in d['data']:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(i)
|
print(i)
|
||||||
if "Method" not in i:
|
if "common" not in i and "method" not in i["common"]:
|
||||||
continue
|
continue
|
||||||
if i['Method'] == "VideoLivePresentMessage":
|
if i["common"]['method'] == "VideoLivePresentMessage":
|
||||||
self.onPresent(Gift(i))
|
self.onPresent(Gift(i))
|
||||||
elif i['Method'] == "VideoLivePresentEndTipMessage":
|
elif i["common"]['method'] == "VideoLivePresentEndTipMessage":
|
||||||
self.onPresentEnd(Gift(i))
|
self.onPresentEnd(Gift(i))
|
||||||
elif i['Method'] == "VideoLiveRoomAdMessage":
|
elif i["common"]['method'] == "VideoLiveRoomAdMessage":
|
||||||
self.onAd(i)
|
self.onAd(i)
|
||||||
elif i['Method'] == "VideoLiveChatMessage":
|
elif i["common"]['method'] == "VideoLiveChatMessage":
|
||||||
self.onChat(Chat(i))
|
self.onChat(Chat(i))
|
||||||
elif i['Method'] == "VideoLiveMemberMessage":
|
elif i["common"]['method'] == "VideoLiveMemberMessage":
|
||||||
self._updateRoomInfo(i)
|
self._updateRoomInfo(i)
|
||||||
self.onEnter(MemberMsg(i))
|
self.onEnter(MemberMsg(i))
|
||||||
elif i['Method'] == "VideoLiveSocialMessage":
|
elif i["common"]['method'] == "VideoLiveSocialMessage":
|
||||||
self.onSubscribe(User(i))
|
self.onSubscribe(User(i))
|
||||||
elif i['Method'] == "VideoLiveJoinDiscipulusMessage":
|
elif i["common"]['method'] == "VideoLiveJoinDiscipulusMessage":
|
||||||
self.onJoin(User(i))
|
self.onJoin(User(i))
|
||||||
elif i['Method'] == "VideoLiveControlMessage":
|
elif i["common"]['method'] == "VideoLiveControlMessage":
|
||||||
print("消息:", "主播离开一小会")
|
print("消息:", "主播离开一小会")
|
||||||
elif i['Method'] == "VideoLiveDiggMessage":
|
elif i["common"]['method'] == "VideoLiveDiggMessage":
|
||||||
self.onLike(User(i))
|
self.onLike(User(i))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# room = 97621754276 # 永恒
|
room = 97621754276 # 永恒
|
||||||
# room = 75366565294
|
# room = 75366565294
|
||||||
room = 83940182312 #Dae
|
# room = 83940182312 #Dae
|
||||||
|
# room = 58649240617 #ll
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
if sys.argv[-1] == "d":
|
if sys.argv[-1] == "d":
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
Reference in New Issue
Block a user