You've already forked XiguaLiveDanmakuHelper
录播端
This commit is contained in:
@ -1,31 +0,0 @@
|
||||
from .User import User
|
||||
from .Lottery import Lottery
|
||||
|
||||
|
||||
class Chat:
|
||||
|
||||
content =""
|
||||
user=None
|
||||
filterString = ["",]
|
||||
isFiltered = False
|
||||
|
||||
def __init__(self, json=None, lottery:Lottery = None):
|
||||
if json:
|
||||
self.parse(json)
|
||||
if lottery:
|
||||
self.filterString.append(lottery.content)
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User(json)
|
||||
if "extra" in json:
|
||||
if "content" in json["extra"]:
|
||||
self.content = json["extra"]['content']
|
||||
if self.content in self.filterString:
|
||||
self.isFiltered = True
|
||||
|
||||
def __str__(self):
|
||||
return "{} : {}".format(self.user,self.content)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.__str__()
|
||||
|
@ -1,61 +0,0 @@
|
||||
import requests
|
||||
from .User import User
|
||||
|
||||
|
||||
class Gift:
|
||||
roomID = 0
|
||||
giftList = {}
|
||||
|
||||
def __init__(self, json=None):
|
||||
self.ID = 0
|
||||
self.count = 0
|
||||
self.amount = 0
|
||||
self.user = None
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User(json)
|
||||
if "common" in json and json["common"] is not None:
|
||||
if Gift.roomID != int(json["common"]["room_id"]):
|
||||
Gift.roomID = int(json["common"]["room_id"])
|
||||
self.update()
|
||||
if "extra" in json and json["extra"] is not None:
|
||||
if "present_info" in json["extra"] and json["extra"]['present_info'] is not None:
|
||||
self.ID = int(json["extra"]['present_info']['id'])
|
||||
self.count = json["extra"]['present_info']['repeat_count']
|
||||
elif "present_end_info" in json["extra"] and json["extra"]['present_end_info'] is not None:
|
||||
self.ID = int(json["extra"]['present_end_info']['id'])
|
||||
self.count = json["extra"]['present_end_info']['count']
|
||||
if self.ID != 0 and self.ID in self.giftList:
|
||||
self.amount = self.giftList[self.ID]["Price"] * self.count
|
||||
else:
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
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))
|
||||
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"]}
|
||||
|
||||
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)
|
||||
|
||||
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)
|
@ -1,71 +0,0 @@
|
||||
# coding=utf-8
|
||||
import requests
|
||||
import time
|
||||
from .LuckyUser import LuckyUser
|
||||
|
||||
|
||||
class Lottery:
|
||||
ID = 0
|
||||
isActive = False
|
||||
content = ""
|
||||
isFinished = False
|
||||
luckyUsers = []
|
||||
joinedUserCount = 0
|
||||
prizeName = ""
|
||||
finish = 0
|
||||
|
||||
def __init__(self, json=None):
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
def parse(self, json):
|
||||
if "lottery_info" in json and json["lottery_info"] is not None:
|
||||
self.isActive = int(json["lottery_info"]["status"]) > 0
|
||||
self.ID = json["lottery_info"]["lottery_id"]
|
||||
for i in json["lottery_info"]['conditions']:
|
||||
if i['type'] != 3:
|
||||
continue
|
||||
self.content = i["content"]
|
||||
self.joinedUserCount = int(json["lottery_info"]["candidate_num"])
|
||||
self.prizeName = json["lottery_info"]["prize_info"]["name"]
|
||||
_delta = int(json["lottery_info"]["draw_time"]) - int(json["lottery_info"]["current_time"])
|
||||
self.finish = time.time()+_delta+1
|
||||
elif "extra" in json and json["extra"] is not None:
|
||||
if "lottery_info" in json["extra"] and json["extra"]["lottery_info"] is not None:
|
||||
return self.parse(json["extra"])
|
||||
|
||||
def update(self):
|
||||
if self.isActive:
|
||||
if not self.isFinished and self.finish > time.time():
|
||||
self.checkFinished()
|
||||
return True
|
||||
return False
|
||||
|
||||
def checkFinished(self):
|
||||
p = requests.get("https://i.snssdk.com/videolive/lottery/check_user_right?lottery_id={}"
|
||||
"&version_code=730&device_platform=android".format(
|
||||
self.ID
|
||||
))
|
||||
d = p.json()
|
||||
if d["base_resp"]["status_code"] != 0:
|
||||
self.isActive = False
|
||||
self.isFinished = False
|
||||
return
|
||||
self.isActive = int(d["lottery_info"]["status"]) > 0
|
||||
self.isFinished = int(d["lottery_info"]["status"]) == 2
|
||||
self.joinedUserCount = int(d["lottery_info"]["candidate_num"])
|
||||
if self.isFinished:
|
||||
self.luckyUsers = [ LuckyUser(i) for i in d["lottery_info"]["lucky_users"] ]
|
||||
|
||||
def __str__(self):
|
||||
if self.isFinished:
|
||||
ret = "恭喜以下中奖用户:\n"
|
||||
for i in self.luckyUsers:
|
||||
ret += "> {} {}\n".format(i,self.prizeName)
|
||||
ret += "> 参与人数:{}".format(self.joinedUserCount)
|
||||
return ret
|
||||
elif self.isActive:
|
||||
return "正在抽奖中。。。\n" \
|
||||
"> 参与人数:{}".format(self.joinedUserCount)
|
||||
else:
|
||||
return "抽奖已失效"
|
@ -1,19 +0,0 @@
|
||||
from .User import User
|
||||
|
||||
class LuckyUser:
|
||||
|
||||
user = None
|
||||
count = 0
|
||||
|
||||
def __init__(self, json=None):
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User()
|
||||
self.user.ID = json['user_id']
|
||||
self.user.name = json['user_name']
|
||||
self.count = int(json["grant_count"])
|
||||
|
||||
def __str__(self):
|
||||
return "用户 {} 获得了 {} 个".format(self.user,self.count)
|
@ -1,36 +0,0 @@
|
||||
from .User import User
|
||||
|
||||
|
||||
class MemberMsg:
|
||||
type = 0
|
||||
content = ""
|
||||
user = None
|
||||
|
||||
def __init__(self, json=None):
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User(json)
|
||||
if "extra" in json:
|
||||
if "action" in json["extra"]:
|
||||
self.type = json["extra"]['action']
|
||||
elif "content" in json["extra"]:
|
||||
self.content = json["extra"]['content']
|
||||
|
||||
def __str__(self):
|
||||
if self.type == 3:
|
||||
return "{} 被禁言了".format(self.user)
|
||||
elif self.type == 4:
|
||||
return "{} 被取消禁言了".format(self.user)
|
||||
elif self.type == 5:
|
||||
return "{} 被任命为房管".format(self.user)
|
||||
elif self.type == 1:
|
||||
return "{} 进入了房间".format(self.user)
|
||||
else:
|
||||
if self.content == "":
|
||||
return "未知消息{} 关于用户 {}".format(self.type, self.user)
|
||||
return self.content.format(self.user)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.__str__()
|
Reference in New Issue
Block a user