主动更新礼物
This commit is contained in:
parent
107309c043
commit
ee9556548d
@ -25,7 +25,7 @@ class Gift:
|
|||||||
_message.ParseFromString(raw)
|
_message.ParseFromString(raw)
|
||||||
self.user = User(_message.user)
|
self.user = User(_message.user)
|
||||||
self.ID = _message.giftId
|
self.ID = _message.giftId
|
||||||
self.count = _message.combo
|
self.count = _message.repeated
|
||||||
self.isFinished = _message.isFinished
|
self.isFinished = _message.isFinished
|
||||||
self.backupName = _message.commonInfo.displayText.params.gifts.gift.name
|
self.backupName = _message.commonInfo.displayText.params.gifts.gift.name
|
||||||
|
|
||||||
@ -43,12 +43,12 @@ class Gift:
|
|||||||
self.ID = int(json["extra"]['present_end_info']['id'])
|
self.ID = int(json["extra"]['present_end_info']['id'])
|
||||||
self.count = json["extra"]['present_end_info']['count']
|
self.count = json["extra"]['present_end_info']['count']
|
||||||
if self.ID != 0 and self.ID in self.giftList:
|
if self.ID != 0 and self.ID in self.giftList:
|
||||||
self.amount = self.giftList[self.ID]["Price"] * self.count
|
self.amount = self.giftList[self.ID]['diamond_count'] * self.count
|
||||||
else:
|
else:
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def update():
|
def update(cls):
|
||||||
p = requests.get("https://i.snssdk.com/videolive/gift/get_gift_list?room_id={roomID}"
|
p = requests.get("https://i.snssdk.com/videolive/gift/get_gift_list?room_id={roomID}"
|
||||||
"&version_code=800&device_platform=android".format(roomID=Gift.roomID))
|
"&version_code=800&device_platform=android".format(roomID=Gift.roomID))
|
||||||
d = p.json()
|
d = p.json()
|
||||||
@ -56,15 +56,21 @@ class Gift:
|
|||||||
print("错误:礼物更新失败")
|
print("错误:礼物更新失败")
|
||||||
else:
|
else:
|
||||||
for i in d["gift_info"]:
|
for i in d["gift_info"]:
|
||||||
_id = int(i["id"])
|
cls.addGift(i)
|
||||||
Gift.giftList[_id] = {"Name": i["name"], "Price": i["diamond_count"], "Type": i["type"]}
|
|
||||||
|
|
||||||
def isAnimate(self):
|
def isAnimate(self):
|
||||||
return self.ID != 0 and self.ID in self.giftList and self.giftList[self.ID]["Type"] == 2
|
if self.ID != 0 and self.ID in self.giftList:
|
||||||
|
if 'combo' in self.giftList[self.ID]:
|
||||||
|
return self.giftList[self.ID]["combo"] == False
|
||||||
|
elif 'meta' in self.giftList[self.ID] and 'combo' in self.giftList[self.ID]['meta']:
|
||||||
|
return self.giftList[self.ID]['meta']["combo"] == False
|
||||||
|
elif 'type' in self.giftList[self.ID]:
|
||||||
|
return self.giftList[self.ID]["type"] == 2
|
||||||
|
return False
|
||||||
|
|
||||||
def _getGiftName(self):
|
def _getGiftName(self):
|
||||||
if self.ID in self.giftList:
|
if self.ID in self.giftList:
|
||||||
return self.giftList[self.ID]["Name"]
|
return self.giftList[self.ID]["name"]
|
||||||
elif self.backupName is not None:
|
elif self.backupName is not None:
|
||||||
return self.backupName
|
return self.backupName
|
||||||
else:
|
else:
|
||||||
@ -78,3 +84,10 @@ class Gift:
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "西瓜礼物【{}(ID:{})】".format(self._getGiftName(), self.ID)
|
return "西瓜礼物【{}(ID:{})】".format(self._getGiftName(), self.ID)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def addGift(cls, _gift):
|
||||||
|
if 'id' not in _gift:
|
||||||
|
return
|
||||||
|
_id = int(_gift["id"])
|
||||||
|
cls.giftList[_id] = _gift
|
||||||
|
@ -203,6 +203,12 @@ if __name__ == "__main__":
|
|||||||
print("OK")
|
print("OK")
|
||||||
else:
|
else:
|
||||||
print("FAIL")
|
print("FAIL")
|
||||||
|
print("更新房间礼物信息", end="\t", flush=True)
|
||||||
|
__res = api.updGiftInfo()
|
||||||
|
if __res < 0:
|
||||||
|
print("FAIL")
|
||||||
|
else:
|
||||||
|
print('OK\n礼物种数:', __res)
|
||||||
print("=" * 30)
|
print("=" * 30)
|
||||||
while True:
|
while True:
|
||||||
if api.isLive:
|
if api.isLive:
|
||||||
|
28
api.py
28
api.py
@ -32,6 +32,8 @@ ROOM_INFO_API = ("https://webcast3.ixigua.com/webcast/room/enter/?room_id={roomI
|
|||||||
"&webcast_language=zh&webcast_locale=zh_CN&pack_level=4{COMMON}")
|
"&webcast_language=zh&webcast_locale=zh_CN&pack_level=4{COMMON}")
|
||||||
DANMAKU_GET_API = ("https://webcast3.ixigua.com/webcast/room/{roomId}/_fetch_message_polling/?webcast_sdk_version=1350"
|
DANMAKU_GET_API = ("https://webcast3.ixigua.com/webcast/room/{roomId}/_fetch_message_polling/?webcast_sdk_version=1350"
|
||||||
"&webcast_language=zh&webcast_locale=zh_CN{COMMON}")
|
"&webcast_language=zh&webcast_locale=zh_CN{COMMON}")
|
||||||
|
GIFT_DATA_API = ("https://webcast.ixigua.com/webcast/gift/list/?room_id={roomId}&fetch_giftlist_from=2"
|
||||||
|
"&webcast_sdk_version=1350&webcast_language=zh&webcast_locale=zh_CN{COMMON}")
|
||||||
COMMON_HEADERS = {
|
COMMON_HEADERS = {
|
||||||
"sdk-version": '1',
|
"sdk-version": '1',
|
||||||
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 9) VideoArticle/8.1.6 cronet/TTNetVersion:b97574c0 2019-09-24",
|
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 9) VideoArticle/8.1.6 cronet/TTNetVersion:b97574c0 2019-09-24",
|
||||||
@ -319,7 +321,6 @@ class XiGuaLiveApi:
|
|||||||
self._updRoomAt = datetime.now()
|
self._updRoomAt = datetime.now()
|
||||||
self._updateRoomPopularity(d)
|
self._updateRoomPopularity(d)
|
||||||
Gift.roomID = self.roomID
|
Gift.roomID = self.roomID
|
||||||
Gift.update()
|
|
||||||
return self.isLive
|
return self.isLive
|
||||||
|
|
||||||
def updRoomInfo(self, force=False):
|
def updRoomInfo(self, force=False):
|
||||||
@ -334,6 +335,23 @@ class XiGuaLiveApi:
|
|||||||
else:
|
else:
|
||||||
return self._getRoomInfo(force)
|
return self._getRoomInfo(force)
|
||||||
|
|
||||||
|
def updGiftInfo(self):
|
||||||
|
self.updRoomInfo()
|
||||||
|
_formatData = {"COMMON": COMMON_GET_PARAM, "TIMESTAMP": time.time() * 1000, "roomId": self.roomID}
|
||||||
|
_url = GIFT_DATA_API.format_map(_formatData).format_map(_formatData)
|
||||||
|
d = self.getJson(_url)
|
||||||
|
Gift.roomID = self.roomID
|
||||||
|
if d is None or d["status_code"] != 0:
|
||||||
|
Gift.update()
|
||||||
|
elif 'pages' not in d["data"]:
|
||||||
|
Gift.update()
|
||||||
|
else:
|
||||||
|
for _page in d["data"]['pages']:
|
||||||
|
if 'gifts' in _page:
|
||||||
|
for _gift in _page['gifts']:
|
||||||
|
Gift.addGift(_gift)
|
||||||
|
return len(Gift.giftList)
|
||||||
|
|
||||||
def getDanmaku(self):
|
def getDanmaku(self):
|
||||||
"""
|
"""
|
||||||
获取弹幕
|
获取弹幕
|
||||||
@ -355,7 +373,7 @@ class XiGuaLiveApi:
|
|||||||
self.onPresentEnd(_gift)
|
self.onPresentEnd(_gift)
|
||||||
elif _each.method == "WebcastChatMessage":
|
elif _each.method == "WebcastChatMessage":
|
||||||
_chat = Chat(_each.raw)
|
_chat = Chat(_each.raw)
|
||||||
self.onChat(_chat)
|
# self.onChat(_chat)
|
||||||
elif _each.method == "WebcastFansclubMessage":
|
elif _each.method == "WebcastFansclubMessage":
|
||||||
_fansClubMessage = FansClubMessage()
|
_fansClubMessage = FansClubMessage()
|
||||||
_fansClubMessage.ParseFromString(_each.raw)
|
_fansClubMessage.ParseFromString(_each.raw)
|
||||||
@ -392,6 +410,12 @@ if __name__ == "__main__":
|
|||||||
print("OK")
|
print("OK")
|
||||||
else:
|
else:
|
||||||
print("FAIL")
|
print("FAIL")
|
||||||
|
print("更新房间礼物信息", end="\t", flush=True)
|
||||||
|
__res = api.updGiftInfo()
|
||||||
|
if __res < 0:
|
||||||
|
print("FAIL")
|
||||||
|
else:
|
||||||
|
print('OK\n礼物种数:', __res)
|
||||||
print("=" * 30)
|
print("=" * 30)
|
||||||
while True:
|
while True:
|
||||||
if api.isLive:
|
if api.isLive:
|
||||||
|
Reference in New Issue
Block a user