更新部分接口,待测试
This commit is contained in:
parent
37fdd0fa9a
commit
372953b3e0
@ -317,9 +317,9 @@ class downloader(XiGuaLiveApi):
|
||||
doClean()
|
||||
super(downloader, self).updRoomInfo(force)
|
||||
|
||||
def _updateRoomOnly(self):
|
||||
def _updateUserOnly(self):
|
||||
global broadcaster, isBroadcasting, updateTime
|
||||
super(downloader, self)._updateRoomOnly()
|
||||
super(downloader, self)._updateUserOnly()
|
||||
updateTime = datetime.strftime(datetime.now(), dt_format)
|
||||
broadcaster = self.roomLiver
|
||||
isBroadcasting = self.isLive
|
||||
|
@ -3,14 +3,14 @@ from .User import User
|
||||
|
||||
|
||||
class Gift:
|
||||
ID = 0
|
||||
count = 0
|
||||
roomID = 0
|
||||
giftList = {}
|
||||
amount = 0
|
||||
user = None
|
||||
|
||||
def __init__(self, json=None):
|
||||
self.ID = 0
|
||||
self.count = 0
|
||||
self.amount = 0
|
||||
self.user = None
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
@ -34,7 +34,7 @@ class Gift:
|
||||
|
||||
def update(self):
|
||||
p = requests.get("https://i.snssdk.com/videolive/gift/get_gift_list?room_id={roomID}"
|
||||
"&version_code=730&device_platform=android".format(roomID = self.roomID))
|
||||
"&version_code=800&device_platform=android".format(roomID=self.roomID))
|
||||
d = p.json()
|
||||
if "gift_info" not in d:
|
||||
print("错误:礼物更新失败")
|
||||
@ -48,7 +48,14 @@ class Gift:
|
||||
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=giftN)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.__str__()
|
||||
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)
|
||||
|
50
api.py
50
api.py
@ -45,13 +45,17 @@ class XiGuaLiveApi:
|
||||
lottery = None
|
||||
s = requests.session()
|
||||
|
||||
def __init__(self, name: str = "永恒de草薙"):
|
||||
def __init__(self, name=None):
|
||||
"""
|
||||
Api类
|
||||
Init Function
|
||||
:param name: 主播名
|
||||
:param name: class:str|User: 主播名
|
||||
"""
|
||||
self.name = name
|
||||
if type(name) == User:
|
||||
self.roomLiver = name
|
||||
self.name = name.name
|
||||
else:
|
||||
self.name = str(name)
|
||||
self.s.headers.update(COMMON_HEADERS)
|
||||
self._updRoomAt = datetime.now()
|
||||
self.updRoomInfo(True)
|
||||
@ -188,9 +192,9 @@ class XiGuaLiveApi:
|
||||
if len(_results) > 0:
|
||||
self.isValidRoom = True
|
||||
self.roomLiver = _results[0]
|
||||
return self._updateRoomOnly()
|
||||
return self._updateUserOnly()
|
||||
|
||||
def _updateRoomOnly(self):
|
||||
def _updateUserOnly(self):
|
||||
"""
|
||||
获取用户信息
|
||||
:return:
|
||||
@ -199,7 +203,11 @@ class XiGuaLiveApi:
|
||||
return False
|
||||
_formatData = {"COMMON": COMMON_GET_PARAM, "TIMESTAMP": time.time() * 1000, "userId": self.roomLiver.ID}
|
||||
_url = USER_INFO_API.format_map(_formatData).format_map(_formatData)
|
||||
p = self.s.get(_url)
|
||||
try:
|
||||
p = self.s.get(_url)
|
||||
except Exception as e:
|
||||
self.apiChangedError("更新用户信息接口请求失败", e.__str__())
|
||||
return False
|
||||
try:
|
||||
d = p.json()
|
||||
except Exception as e:
|
||||
@ -216,6 +224,7 @@ class XiGuaLiveApi:
|
||||
self.isLive = d["user_info"]["is_living"]
|
||||
self._rawRoomInfo = d["user_info"]['live_info']
|
||||
if self.isLive:
|
||||
self.roomID = d["user_info"]['live_info']['room_id']
|
||||
# 处理抽奖事件
|
||||
l = Lottery(self._rawRoomInfo)
|
||||
if l.isActive:
|
||||
@ -232,25 +241,30 @@ class XiGuaLiveApi:
|
||||
return self.isLive
|
||||
self._updRoomAt = datetime.now()
|
||||
if self.isLive:
|
||||
return self._updateRoomOnly()
|
||||
return self._updateUserOnly()
|
||||
else:
|
||||
return self._forceSearchUser()
|
||||
|
||||
@staticmethod
|
||||
def findRoomByUserId(userId: int):
|
||||
def getUserInfoByUserId(userId):
|
||||
"""
|
||||
通过UserId查找用户的房间号(已弃用)
|
||||
通过UserId查找用户的房间号
|
||||
:param userId: 用户ID
|
||||
:return: XiGuaLiveApi
|
||||
"""
|
||||
p = requests.get("https://live.ixigua.com/api/room?anchorId={room}".format(room=userId))
|
||||
if DEBUG:
|
||||
print(p.text)
|
||||
d = p.json()
|
||||
if "data" not in d or "title" not in d["data"] or "id" not in d["data"]:
|
||||
XiGuaLiveApi.apiChangedError("网页接口已更改,除非你是开发者,请不要用这个方法", d)
|
||||
return XiGuaLiveApi()
|
||||
return XiGuaLiveApi(d["data"]["id"])
|
||||
_formatData = {"COMMON": COMMON_GET_PARAM, "TIMESTAMP": time.time() * 1000, "userId": userId}
|
||||
_url = USER_INFO_API.format_map(_formatData).format_map(_formatData)
|
||||
try:
|
||||
p = requests.get(_url, headers=COMMON_HEADERS)
|
||||
except Exception as e:
|
||||
XiGuaLiveApi.apiChangedError("更新用户信息接口请求失败", e.__str__())
|
||||
return None
|
||||
try:
|
||||
d = p.json()
|
||||
except Exception as e:
|
||||
XiGuaLiveApi.apiChangedError("更新房间接口错误", e.__str__())
|
||||
return None
|
||||
return XiGuaLiveApi(User(d))
|
||||
|
||||
@staticmethod
|
||||
def searchUser(keyword):
|
||||
@ -286,7 +300,7 @@ class XiGuaLiveApi:
|
||||
self.updRoomInfo()
|
||||
return
|
||||
p = self.s.get("https://i.snssdk.com/videolive/im/get_msg?cursor={cursor}&room_id={roomID}"
|
||||
"&version_code=730&device_platform=android".format(
|
||||
"&version_code=800&device_platform=android".format(
|
||||
roomID=self.roomID,
|
||||
cursor=self._cursor
|
||||
))
|
||||
|
Reference in New Issue
Block a user