更新粉丝团
This commit is contained in:
parent
ff53afffb5
commit
cae988e0fe
@ -3,7 +3,8 @@ import "XiguaUser.proto";
|
||||
import "XiguaGift.proto";
|
||||
message Message {
|
||||
required CommonInfo commonInfo = 1;
|
||||
optional string content = 3;
|
||||
required bytes contents = 2;
|
||||
optional bool isFinished = 9 [ default = false ];
|
||||
}
|
||||
// 样式
|
||||
message Style {
|
||||
|
@ -11,6 +11,7 @@ class Gift:
|
||||
self.count = 0
|
||||
self.amount = 0
|
||||
self.user = None
|
||||
self.backupName = None
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
@ -32,30 +33,34 @@ class Gift:
|
||||
else:
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
@staticmethod
|
||||
def update():
|
||||
p = requests.get("https://i.snssdk.com/videolive/gift/get_gift_list?room_id={roomID}"
|
||||
"&version_code=800&device_platform=android".format(roomID=self.roomID))
|
||||
"&version_code=800&device_platform=android".format(roomID=Gift.roomID))
|
||||
d = p.json()
|
||||
if "gift_info" not in d:
|
||||
print("错误:礼物更新失败")
|
||||
else:
|
||||
for i in d["gift_info"]:
|
||||
_id = int(i["id"])
|
||||
Gift.giftList[_id] = {"Name": i["name"], "Price": i["diamond_count"]}
|
||||
Gift.giftList[_id] = {"Name": i["name"], "Price": i["diamond_count"], "Type": i["type"]}
|
||||
|
||||
def isAnimate(self):
|
||||
return self.ID != 0 and self.ID in self.giftList and self.giftList[self.ID]["Type"] == 2
|
||||
|
||||
def _getGiftName(self):
|
||||
if self.ID in self.giftList:
|
||||
return self.giftList[self.ID]["Name"]
|
||||
elif self.backupName is not None:
|
||||
return self.backupName
|
||||
else:
|
||||
return "未知礼物[{}]".format(self.ID)
|
||||
|
||||
def __str__(self):
|
||||
if self.ID in self.giftList:
|
||||
giftN = self.giftList[self.ID]["Name"]
|
||||
else:
|
||||
giftN = "未知礼物[{}]".format(self.ID)
|
||||
return "{user} 送出的 {count} 个 {name}".format(user=self.user, count=self.count, name=giftN)
|
||||
return "{user} 送出的 {count} 个 {name}".format(user=self.user, count=self.count, name=self._getGiftName())
|
||||
|
||||
def __unicode__(self):
|
||||
return self.__str__()
|
||||
|
||||
def __repr__(self):
|
||||
if self.ID in self.giftList:
|
||||
giftN = self.giftList[self.ID]["Name"]
|
||||
else:
|
||||
giftN = "未知礼物"
|
||||
return "西瓜礼物【{}(ID:{})】".format(giftN, self.ID)
|
||||
return "西瓜礼物【{}(ID:{})】".format(self._getGiftName(), self.ID)
|
||||
|
@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
package='',
|
||||
syntax='proto2',
|
||||
serialized_options=None,
|
||||
serialized_pb=b'\n\x11XiguaCommon.proto\x1a\x0fXiguaUser.proto\x1a\x0fXiguaGift.proto\";\n\x07Message\x12\x1f\n\ncommonInfo\x18\x01 \x02(\x0b\x32\x0b.CommonInfo\x12\x0f\n\x07\x63ontent\x18\x03 \x01(\t\"*\n\x05Style\x12\r\n\x05\x63olor\x18\x01 \x01(\t\x12\x12\n\nfontWeight\x18\x04 \x01(\x05\"q\n\x06Params\x12\x0c\n\x04type\x18\x01 \x02(\x05\x12\x15\n\x05style\x18\x02 \x01(\x0b\x32\x06.Style\x12\x0e\n\x06string\x18\x0b \x01(\t\x12\x18\n\x05users\x18\x15 \x01(\x0b\x32\t.UserPack\x12\x18\n\x05gifts\x18\x16 \x01(\x0b\x32\t.GiftPack\"_\n\x0b\x44isplayText\x12\x0e\n\x06method\x18\x01 \x02(\t\x12\x0e\n\x06\x66ormat\x18\x02 \x02(\t\x12\x17\n\x07\x62gStyle\x18\x03 \x01(\x0b\x32\x06.Style\x12\x17\n\x06params\x18\x04 \x02(\x0b\x32\x07.Params\"u\n\nCommonInfo\x12\x0e\n\x06method\x18\x01 \x01(\t\x12\x0e\n\x06msg_id\x18\x02 \x01(\x05\x12\x0f\n\x07room_id\x18\x03 \x01(\x05\x12\x13\n\x0b\x63reate_time\x18\x04 \x01(\x05\x12!\n\x0b\x64isplayText\x18\x08 \x01(\x0b\x32\x0c.DisplayText'
|
||||
serialized_pb=b'\n\x11XiguaCommon.proto\x1a\x0fXiguaUser.proto\x1a\x0fXiguaGift.proto\"W\n\x07Message\x12\x1f\n\ncommonInfo\x18\x01 \x02(\x0b\x32\x0b.CommonInfo\x12\x10\n\x08\x63ontents\x18\x02 \x02(\x0c\x12\x19\n\nisFinished\x18\t \x01(\x08:\x05\x66\x61lse\"*\n\x05Style\x12\r\n\x05\x63olor\x18\x01 \x01(\t\x12\x12\n\nfontWeight\x18\x04 \x01(\x05\"q\n\x06Params\x12\x0c\n\x04type\x18\x01 \x02(\x05\x12\x15\n\x05style\x18\x02 \x01(\x0b\x32\x06.Style\x12\x0e\n\x06string\x18\x0b \x01(\t\x12\x18\n\x05users\x18\x15 \x01(\x0b\x32\t.UserPack\x12\x18\n\x05gifts\x18\x16 \x01(\x0b\x32\t.GiftPack\"_\n\x0b\x44isplayText\x12\x0e\n\x06method\x18\x01 \x02(\t\x12\x0e\n\x06\x66ormat\x18\x02 \x02(\t\x12\x17\n\x07\x62gStyle\x18\x03 \x01(\x0b\x32\x06.Style\x12\x17\n\x06params\x18\x04 \x02(\x0b\x32\x07.Params\"u\n\nCommonInfo\x12\x0e\n\x06method\x18\x01 \x01(\t\x12\x0e\n\x06msg_id\x18\x02 \x01(\x05\x12\x0f\n\x07room_id\x18\x03 \x01(\x05\x12\x13\n\x0b\x63reate_time\x18\x04 \x01(\x05\x12!\n\x0b\x64isplayText\x18\x08 \x01(\x0b\x32\x0c.DisplayText'
|
||||
,
|
||||
dependencies=[XiguaUser__pb2.DESCRIPTOR,XiguaGift__pb2.DESCRIPTOR,])
|
||||
|
||||
@ -42,9 +42,16 @@ _MESSAGE = _descriptor.Descriptor(
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='content', full_name='Message.content', index=1,
|
||||
number=3, type=9, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=b"".decode('utf-8'),
|
||||
name='contents', full_name='Message.contents', index=1,
|
||||
number=2, type=12, cpp_type=9, label=2,
|
||||
has_default_value=False, default_value=b"",
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='isFinished', full_name='Message.isFinished', index=2,
|
||||
number=9, type=8, cpp_type=7, label=1,
|
||||
has_default_value=True, default_value=False,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
@ -61,7 +68,7 @@ _MESSAGE = _descriptor.Descriptor(
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=55,
|
||||
serialized_end=114,
|
||||
serialized_end=142,
|
||||
)
|
||||
|
||||
|
||||
@ -98,8 +105,8 @@ _STYLE = _descriptor.Descriptor(
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=116,
|
||||
serialized_end=158,
|
||||
serialized_start=144,
|
||||
serialized_end=186,
|
||||
)
|
||||
|
||||
|
||||
@ -157,8 +164,8 @@ _PARAMS = _descriptor.Descriptor(
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=160,
|
||||
serialized_end=273,
|
||||
serialized_start=188,
|
||||
serialized_end=301,
|
||||
)
|
||||
|
||||
|
||||
@ -209,8 +216,8 @@ _DISPLAYTEXT = _descriptor.Descriptor(
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=275,
|
||||
serialized_end=370,
|
||||
serialized_start=303,
|
||||
serialized_end=398,
|
||||
)
|
||||
|
||||
|
||||
@ -268,8 +275,8 @@ _COMMONINFO = _descriptor.Descriptor(
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=372,
|
||||
serialized_end=489,
|
||||
serialized_start=400,
|
||||
serialized_end=517,
|
||||
)
|
||||
|
||||
_MESSAGE.fields_by_name['commonInfo'].message_type = _COMMONINFO
|
||||
|
26
api.py
26
api.py
@ -69,7 +69,7 @@ class XiGuaLiveApi:
|
||||
self._updRoomAt = datetime.fromtimestamp(0)
|
||||
self.updRoomInfo()
|
||||
self._ext = ""
|
||||
self._cursor = ""
|
||||
self._cursor = "0"
|
||||
|
||||
def _updateRoomPopularity(self, _data):
|
||||
"""
|
||||
@ -107,7 +107,7 @@ class XiGuaLiveApi:
|
||||
|
||||
def postJson(self, url, data, **kwargs):
|
||||
try:
|
||||
p = self.s.post(url, data, **kwargs)
|
||||
p = self.s.post(url, data=data, **kwargs)
|
||||
except Exception as e:
|
||||
print("网络请求失败")
|
||||
if DEBUG:
|
||||
@ -317,6 +317,8 @@ class XiGuaLiveApi:
|
||||
self.isLive = d["data"]["status"] == 2
|
||||
self._updRoomAt = datetime.now()
|
||||
self._updateRoomPopularity(d)
|
||||
Gift.roomID = self.roomID
|
||||
Gift.update()
|
||||
return self.isLive
|
||||
|
||||
def updRoomInfo(self, force=False):
|
||||
@ -343,26 +345,28 @@ class XiGuaLiveApi:
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded"})
|
||||
data = XiguaLive()
|
||||
data.ParseFromString(p.content)
|
||||
f = open("Demo/a.txt", 'wb')
|
||||
f.write(p.content)
|
||||
f.close()
|
||||
self._cursor = data.cursor
|
||||
self._ext = data.internal_ext
|
||||
for _each in data.data:
|
||||
if _each.method == "WebcastGiftMessage":
|
||||
print("Gift\t", _each.message.commonInfo.displayText.params.gifts.id, "\t",
|
||||
_each.message.commonInfo.displayText.params.users.user.nickname,
|
||||
_each.message.commonInfo.displayText.params.gifts.gift.name,
|
||||
_each.message.commonInfo.displayText.params.string)
|
||||
_gift = Gift()
|
||||
_gift.ID = _each.message.commonInfo.displayText.params.gifts.id
|
||||
_gift.count = _each.message.commonInfo.displayText.params.string
|
||||
if _gift.isAnimate() or _each.message.isFinished:
|
||||
_user = User()
|
||||
_user.ID = _each.message.commonInfo.displayText.params.users.user.id
|
||||
_user.name = _each.message.commonInfo.displayText.params.users.user.nickname
|
||||
_gift.user = _user
|
||||
_gift.backupName = _each.message.commonInfo.displayText.params.gifts.gift.name
|
||||
self.onPresentEnd(_gift)
|
||||
else:
|
||||
pass
|
||||
print(_each.message.contents)
|
||||
# 更新抽奖信息
|
||||
if self.lottery is not None and self.lottery.ID != 0:
|
||||
self.lottery.update()
|
||||
if self.lottery.isFinished:
|
||||
self.onLottery(self.lottery)
|
||||
self.lottery = None
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
name = "永恒de草薙"
|
||||
|
Reference in New Issue
Block a user