You've already forked XiguaLiveDanmakuHelper
Api使用Android app弹幕协议
This commit is contained in:
23
Gift.py
23
Gift.py
@@ -16,26 +16,27 @@ class Gift:
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User(json)
|
||||
if "Msg" in json:
|
||||
if "present_end_info" in json["Msg"]:
|
||||
self.ID = json["Msg"]['present_end_info']['id']
|
||||
self.count = json["Msg"]['present_end_info']['count']
|
||||
elif "present_info" in json["Msg"]:
|
||||
self.ID = json["Msg"]['present_info']['id']
|
||||
self.count = json["Msg"]['present_info']['repeat_count']
|
||||
if "extra" in json:
|
||||
if "present_info" in json["extra"] and json["extra"]['present_info'] is not None:
|
||||
self.ID = int(json["extra"]['present_info']['id'])
|
||||
self.count = json["extra"]['present_info']['repeat_count']
|
||||
elif "present_end_info" in json["extra"] and json["extra"]['present_end_info'] is not None:
|
||||
self.ID = int(json["extra"]['present_end_info']['id'])
|
||||
self.count = json["extra"]['present_end_info']['count']
|
||||
if self.ID in self.giftList:
|
||||
self.amount = self.giftList[self.ID]["Price"] * self.count
|
||||
|
||||
@staticmethod
|
||||
def update(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()
|
||||
if isinstance(d, int) or "data" not in d:
|
||||
if "gift_info" not in d:
|
||||
print("错误:礼物更新失败")
|
||||
else:
|
||||
for i in d["data"]:
|
||||
Gift.giftList[i["ID"]] = {"Name": i["Name"], "Price": i["DiamondCount"]}
|
||||
for i in d["gift_info"]:
|
||||
_id = int(i["id"])
|
||||
Gift.giftList[_id] = {"Name": i["name"], "Price": i["diamond_count"]}
|
||||
|
||||
def __str__(self):
|
||||
if self.ID in self.giftList:
|
||||
|
||||
Reference in New Issue
Block a user