准备加入自动投递功能

This commit is contained in:
2019-01-23 14:50:01 +08:00
parent 4270612a98
commit 746f993a8d
2 changed files with 376 additions and 5 deletions

17
api.py
View File

@ -9,7 +9,8 @@ import time
s = requests.Session()
DEBUG:bool = False
DEBUG: bool = False
class XiGuaLiveApi:
isLive: bool = False
@ -21,6 +22,7 @@ class XiGuaLiveApi:
roomPopularity: int = 0
roomMember: int = 0
_cursor = ""
playlist: str = None
def __init__(self, room: int):
self.room = room
@ -38,7 +40,6 @@ class XiGuaLiveApi:
if "popularity" in json["data"]:
self.roomPopularity = json["data"]["popularity"]
def apiChangedError(self, msg: str, *args):
print(msg)
print(*args)
@ -56,7 +57,7 @@ class XiGuaLiveApi:
def onChat(self, chat: Chat):
print(chat)
def onEnter(self, msg:MemberMsg):
def onEnter(self, msg: MemberMsg):
print("提示 : ", msg)
def onSubscribe(self, user: User):
@ -95,6 +96,12 @@ class XiGuaLiveApi:
self.roomTitle = d["data"]["title"]
self.roomID = d["data"]["id"]
self._updateRoomInfo(d)
if "playInfo" not in d["data"] or "Main" not in d["data"]["playInfo"]:
if self.playlist is None:
self.apiChangedError("无法获取直播链接")
self.playlist = False
else:
self.playlist = d["data"]["playInfo"]["Main"]["1"]["Url"]["HlsUrl"]
if "status" in d["data"] and d["data"]["status"] == 2:
self.isLive = True
else:
@ -117,9 +124,9 @@ class XiGuaLiveApi:
else:
self._cursor = d["data"]["Extra"]["Cursor"]
if DEBUG:
print("Cursor",self._cursor)
print("Cursor", self._cursor)
if "LiveMsgs" not in d["data"]:
return
self.updRoomInfo()
for i in d['data']['LiveMsgs']:
if DEBUG:
print(i)