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