直播状态改为人气值判断

日志系统支持过滤
其他
This commit is contained in:
yutou 2021-05-26 18:37:46 +08:00
parent 5a49fc831a
commit efcb7e5ac2
10 changed files with 62 additions and 52 deletions

View File

@ -294,7 +294,7 @@ public class Live implements ApplicationContextAware {
processData(list.get(i), data);
tmp +="|||"+i+"[start] "+ list.get(i)+ " [end]||| ";
}
Log.i(AppTools.getToDayTimeToString(startTime), roomId, "list size = " + list.size() + " data = " + tmp);
// Log.i(AppTools.getToDayTimeToString(startTime), roomId, "list size = " + list.size() + " data = " + tmp);
} else {
try {
JSONObject json = JSONObject.parseObject(new String(bytes, StandardCharsets.UTF_8));
@ -302,8 +302,14 @@ public class Live implements ApplicationContextAware {
} catch (Exception e) {
int popular = LiveUtils.bytesToInt2(bytes, 0);
info.setPopular(popular);
if(popular>1){
upData.setLive(1);
}else{
upData.setLive(0);
}
}
}
} catch (Exception e) {
Log.e(e);
com.yutou.bilibili.Tools.Log.i("----------ERROR----------");
@ -340,11 +346,10 @@ public class Live implements ApplicationContextAware {
BilibiliLiveData liveData = new BilibiliLiveData();
String danmu;
GiftData giftData;
Log.i(AppTools.getToDayTimeToString(startTime),roomId,json.toJSONString());
switch (json.getString("cmd")) {
case "INTERACT_WORD"://普通用户进直播间
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
Log.i(AppTools.getToDayTimeToString(startTime), roomId, danmu);
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
liveData.setType(LiveData.INTERACT_WORD);
liveData.setMsg(danmu);
@ -370,7 +375,6 @@ public class Live implements ApplicationContextAware {
danmuManager.addDanmu(danmuData);
}
}
Log.i(AppTools.getToDayTimeToString(startTime), roomId, danmu);
break;
case "SEND_GIFT"://送礼
data = json.getJSONObject("data");
@ -397,7 +401,6 @@ public class Live implements ApplicationContextAware {
liveData.setRoomid(roomId);
info.setGiftuser(info.getGiftuser() + 1);
service.addLiveData(liveData);
Log.i(AppTools.getToDayTimeToString(startTime), roomId, danmu);
break;
case "COMBO_SEND"://礼物连击
data = json.getJSONObject("data");
@ -428,7 +431,6 @@ public class Live implements ApplicationContextAware {
liveData.setRoomid(roomId);
info.setGiftuser(info.getGiftuser() + 1);
service.addLiveData(liveData);
Log.i(AppTools.getToDayTimeToString(startTime), roomId, danmu);
break;
case "ENTRY_EFFECT"://舰长进直播间
info.setVipuserindex(info.getVipuserindex() + 1);
@ -439,7 +441,6 @@ public class Live implements ApplicationContextAware {
liveData.setRoomid(roomId);
liveData.setSubtime(new Date());
service.addLiveData(liveData);
Log.i(AppTools.getToDayTimeToString(startTime), roomId, danmu);
break;
case "LIVE_INTERACTIVE_GAME"://彩色弹幕通过游戏弹幕
break;
@ -459,7 +460,6 @@ public class Live implements ApplicationContextAware {
liveData.setSubtime(new Date());
info.setGiftuser(info.getGiftuser() + 1);
service.addLiveData(liveData);
Log.i(AppTools.getToDayTimeToString(startTime), roomId, danmu);
break;
case "USER_TOAST_MSG":
break;
@ -477,7 +477,6 @@ public class Live implements ApplicationContextAware {
liveData.setRoomid(roomId);
info.setGiftuser(info.getGiftuser() + 1);
service.addLiveData(liveData);
Log.i(AppTools.getToDayTimeToString(startTime), roomId, liveData.toString());
break;
case "LIVE"://开始直播,不过有在心跳包上做检测了所以也无所谓
if (upData.getLive() == 1) {
@ -505,7 +504,6 @@ public class Live implements ApplicationContextAware {
QQBotManager.getInstance().sendMessage(file, builder.toString());
}
});
Log.i(AppTools.getToDayTimeToString(startTime), roomId, upData.getName() + "开播了!");
break;
case "PREPARING"://
case "SUPER_CHAT_MESSAGE_JPN":
@ -536,7 +534,6 @@ public class Live implements ApplicationContextAware {
liveData.setRoomid(roomId);
liveData.setSubtime(new Date());
service.addLiveData(liveData);
Log.i(AppTools.getToDayTimeToString(startTime), roomId, liveData.toString());
}
} catch (Exception e) {
Log.e(e);
@ -619,7 +616,6 @@ public class Live implements ApplicationContextAware {
outputStream.write("[object Object]".getBytes(StandardCharsets.UTF_8));
outputStream.flush();
client.send(outputStream.toByteArray());
checkLive();
} catch (Exception e) {
Log.e(e);
com.yutou.bilibili.Tools.Log.i(client.isClosed());

View File

@ -25,6 +25,7 @@ import java.util.zip.Inflater;
public class LiveUtils {
private static String cookie = null;
private static Map<Integer,Boolean> liveStateMap=new HashMap<>();
public LiveUtils() {
@ -353,6 +354,12 @@ public class LiveUtils {
private static JSONObject getLiveState(int roomId){
return http_get("https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?room_id=" + roomId);
}
public static void reloadLiveState(int roomId){
JSONObject json = getLiveState(roomId);
if(json!=null){
liveStateMap.put(roomId,json.getJSONObject("data").getInteger("live_status") == 1);
}
}
public static String getLiveTitle(int roomId) {
JSONObject json =getLiveInfo(roomId);
@ -363,11 +370,12 @@ public class LiveUtils {
}
public static boolean isLivePlayer(int roomId) {
JSONObject json = getLiveState(roomId);
if (json == null) {
return false;
/* if (liveStateMap.containsKey(roomId)) {
return liveStateMap.get(roomId);
}
return json.getJSONObject("data").getInteger("live_status") == 1;
reloadLiveState(roomId);
return false;*/
return Live.lives.get(roomId).geData().getLive()==1;
}
private static void checkLiveSave(int roomId) {

View File

@ -13,7 +13,7 @@ import org.springframework.context.annotation.Import;
@SpringBootApplication
public class BilibiliApplication {
public static String version="0.7.4.1";
public static String version="0.7.4.4";
public static void main(String[] args) {
QQBotManager.getInstance().init();

View File

@ -9,6 +9,7 @@ import com.yutou.bilibili.BiliBili.Tools.BiliTools;
import com.yutou.bilibili.Services.IUserService;
import com.yutou.bilibili.Tools.AppTools;
import com.yutou.bilibili.Tools.Config;
import com.yutou.bilibili.Tools.RedisTools;
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo;
import com.yutou.bilibili.mybatis.model.UBiliUp;
import com.yutou.bilibili.mybatis.model.UUser;
@ -50,6 +51,7 @@ public class UserController {
user.setPower("[1,2,3,5,6,7]");
user.setSubtime(new Date());
user.setLogintoken(UUID.randomUUID().toString());
RedisTools.set(user.getLogintoken(),user.getId()+"",30*24*60);
AppTools.setCookie(response, "login", user.getLogintoken(), -1);
boolean flag = service.reg(user);
if (flag) {
@ -69,8 +71,8 @@ public class UserController {
json.put("code", 0);
if (service.login(user.getUser(), user.getPassword())) {
user = service.getUser(user.getUser());
user.setLogintoken(UUID.randomUUID().toString());
service.update(user);
//user.setLogintoken(UUID.randomUUID().toString());
RedisTools.set(user.getLogintoken(),user.getId()+"",30*24*60);
AppTools.setCookie(response, "login", user.getLogintoken(), -1);
json.put("msg", "登陆成功");
json.put("power", user.getPower());
@ -92,6 +94,7 @@ public class UserController {
} else {
UUser user = service.getUserToToken(token);
if (user != null) {
RedisTools.remove(user.getLogintoken());
user.setLogintoken("");
service.update(user);
AppTools.deleteCookie(request, response, "login");
@ -114,7 +117,7 @@ public class UserController {
json.put("code", -1);
json.put("msg", "未登录");
} else {
UUser loginUser = service.getUserToToken(token);
UUser loginUser = service.getUserToUid(Integer.parseInt(RedisTools.get(token)));
if (loginUser != null) {
user.setLogintoken("");
user.setId(loginUser.getId());
@ -144,8 +147,7 @@ public class UserController {
} else {
json.put("code", 0);
json.put("msg", "ok");
UUser user = service.getUserToToken(token);
json.put("data", service.getUserUp(user.getId()));
json.put("data", service.getUserUp(Integer.parseInt(RedisTools.get(token))));
}
return json;
}
@ -159,7 +161,6 @@ public class UserController {
json.put("code", "-1");
json.put("msg", "未登录");
} else {
UUser user = service.getUserToToken(token);
int roomid = 0;
if (!info.getUrl().startsWith("http")) {
info.setUrl("https://live.bilibili.com/" + info.getUrl());
@ -181,7 +182,7 @@ public class UserController {
return json;
}
UBiliUp up = new UBiliUp();
up.setUid(user.getId());
up.setUid(Integer.parseInt(RedisTools.get(token)));
up.setRoomid(roomid);
json.put("code", 0);
json.put("msg", service.addUp(up) ? "添加成功" : "添加失败");
@ -198,7 +199,7 @@ public class UserController {
json.put("code", -1);
json.put("msg", "未登录");
} else {
UUser user = service.getUserToToken(token);
UUser user = service.getUserToUid(Integer.parseInt(RedisTools.get(token)));;
if (user == null) {
json.put("code", -2);
json.put("msg", "未登录");

View File

@ -235,8 +235,8 @@ public class QQBotManager implements ApplicationContextAware {
}
}
private void myGroup(String msg) {
msg = msg.replace("", "!").toLowerCase();
private void myGroup(String message) {
String msg = message.replace("", "!").toLowerCase();
msg=msg.trim();
StringBuilder builder = new StringBuilder();
JSONObject json;
@ -346,19 +346,9 @@ public class QQBotManager implements ApplicationContextAware {
}
} else if (msg.startsWith(QQCommands.QQ_SYSTEM_LOG)) {
try {
cmd = msg.split(" ");
switch (cmd[1]){
case "true":
RedisTools.set(1,"live-log","true");
getInstance().sendMessage("日志设为 true");
break;
case "false":
RedisTools.set(1,"live-log","false");
getInstance().sendMessage("日志设为 false");
break;
default:
getInstance().sendMessage("设置错误,"+QQCommands.QQ_SYSTEM_LOG +" true|false");
}
cmd = message.replace("","!").replace(QQCommands.QQ_SYSTEM_LOG,"").split(" ");
RedisTools.set(1,"live-log",cmd[1].trim());
getInstance().sendMessage("日志设为:"+cmd[1].trim());
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -12,6 +12,7 @@ public interface IUserService {
boolean removeUp(UUser user,UBiliUp up);
boolean update(UUser user);
UUser getUser(String uname);
UUser getUserToUid(Integer uid);
UUser getUserToToken(String token);
List<UBiliUp> getUserUp(int uid);
}

View File

@ -73,6 +73,11 @@ public class UserServiceImpl implements IUserService {
}
}
@Override
public UUser getUserToUid(Integer uid) {
return userDao.selectByPrimaryKey(uid);
}
@Override
public List<UBiliUp> getUserUp(int uid) {
UBiliUpExample example=new UBiliUpExample();

View File

@ -47,7 +47,7 @@ public class APIFilter implements Filter {
){
filterChain.doFilter(servletRequest,servletResponse);
}else {
UUser user= service.getUserToToken(token);
UUser user= service.getUserToUid(Integer.parseInt(RedisTools.get(token)));;
if(user==null){
response.sendRedirect("/");
}else{

View File

@ -94,6 +94,7 @@ public class ApplicationInit implements ApplicationRunner {
private void checkLive() {
for (BilibiliUpInfo info : service.getUpInfo()) {
// LiveUtils.reloadLiveState(info.getRoomid());
if (info.getOfflinelistening() == 1) {
if (info.getEnable() == 1) {
Live live = LiveUtils.liveContains(info);
@ -111,7 +112,7 @@ public class ApplicationInit implements ApplicationRunner {
}
}
}
}, 0, 60 * 1000);
}, 0, 2*60 * 1000);
}
}

View File

@ -9,6 +9,7 @@ import java.util.logging.Logger;
public class Log {
private static Logger logger;
public static void i(Object log) {
if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "logout"))) {
return;
@ -27,11 +28,18 @@ public class Log {
i(e.getMessage());
e.printStackTrace();
}
public static void i(String timer, int roomId, Object log) {
String logFlag = RedisTools.get("live-log", 1);
if("true".equals(logFlag)) {
if (logFlag.startsWith("true")) {
if (logFlag.contains("|")) {
if (log.toString().contains(logFlag.split("\\|")[1])) {
getLogger("[" + timer.replace(":", "_") + "]" + roomId).log(Level.INFO, log.toString());
}
} else {
getLogger("[" + timer.replace(":", "_") + "]" + roomId).log(Level.INFO, log.toString());
}
}
}
public static Logger getLogger(String fileName) {