调整部分直播逻辑
This commit is contained in:
parent
57ec517608
commit
251ebe1a0c
@ -11,7 +11,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="layui-layout layui-layout-admin">
|
<div class="layui-layout layui-layout-admin">
|
||||||
<div id="header"></div>
|
<div id="header"></div>
|
||||||
<div class="layui-body" style="left: 0px;">
|
<div class="layui-body" style="left: 0px;overflow:auto;">
|
||||||
<div style="width: 40%;height: 25%;margin-left: 25%; margin-top: 2%;">
|
<div style="width: 40%;height: 25%;margin-left: 25%; margin-top: 2%;">
|
||||||
<blockquote class="layui-elem-quote" style="background-color: #FFFFFF; height: 50%;">
|
<blockquote class="layui-elem-quote" style="background-color: #FFFFFF; height: 50%;">
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
19
pom.xml
19
pom.xml
@ -124,6 +124,25 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>1.8</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<tasks>
|
||||||
|
<echo>复制正式文件</echo>
|
||||||
|
<copy file="src/main/resources/application.properties.release" tofile="${project.build.outputDirectory}/application.properties" overwrite="true"/>
|
||||||
|
</tasks>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-maven-plugin</artifactId>
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
@ -133,7 +133,7 @@ public class Live implements ApplicationContextAware {
|
|||||||
private void start() throws Exception {
|
private void start() throws Exception {
|
||||||
run = true;
|
run = true;
|
||||||
if (LiveUtils.isLivePlayer(roomId)) {
|
if (LiveUtils.isLivePlayer(roomId)) {
|
||||||
upData.setLive(1);
|
upData.setLive(-1);
|
||||||
}
|
}
|
||||||
String url = LiveUtils.getLiveUrl(roomId);
|
String url = LiveUtils.getLiveUrl(roomId);
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
@ -227,14 +227,6 @@ public class Live implements ApplicationContextAware {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
client.connect();
|
client.connect();
|
||||||
new Timer().schedule(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (client == null || client.isClosed()) {
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, 60 * 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
@ -290,6 +282,7 @@ public class Live implements ApplicationContextAware {
|
|||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
// LiveUtils.printHex(outputStream.toByteArray());
|
// LiveUtils.printHex(outputStream.toByteArray());
|
||||||
client.send(outputStream.toByteArray());
|
client.send(outputStream.toByteArray());
|
||||||
|
checkLive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -306,11 +299,11 @@ public class Live implements ApplicationContextAware {
|
|||||||
if (data.length > 32) {
|
if (data.length > 32) {
|
||||||
List<String> list = LiveUtils.getMsgList(LiveUtils.dec(bytes), new ArrayList<>(), true);
|
List<String> list = LiveUtils.getMsgList(LiveUtils.dec(bytes), new ArrayList<>(), true);
|
||||||
String tmp = "";
|
String tmp = "";
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i=0;i<list.size();i++) {
|
||||||
processData(list.get(i), data);
|
processData(list.get(i), data);
|
||||||
tmp += "|||" + i + "[start] " + list.get(i) + " [end]||| ";
|
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 {
|
} else {
|
||||||
try {
|
try {
|
||||||
JSONObject json = JSONObject.parseObject(new String(bytes, StandardCharsets.UTF_8));
|
JSONObject json = JSONObject.parseObject(new String(bytes, StandardCharsets.UTF_8));
|
||||||
@ -318,14 +311,14 @@ public class Live implements ApplicationContextAware {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
int popular = LiveUtils.bytesToInt2(bytes, 0);
|
int popular = LiveUtils.bytesToInt2(bytes, 0);
|
||||||
info.setPopular(popular);
|
info.setPopular(popular);
|
||||||
if (popular > 1) {
|
if(popular>1){
|
||||||
upData.setLive(1);
|
upData.setLive(1);
|
||||||
} else {
|
}else{
|
||||||
upData.setLive(0);
|
upData.setLive(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(e);
|
Log.e(e);
|
||||||
com.yutou.bilibili.Tools.Log.i("----------ERROR----------");
|
com.yutou.bilibili.Tools.Log.i("----------ERROR----------");
|
||||||
@ -336,8 +329,13 @@ public class Live implements ApplicationContextAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkLive() {
|
public void checkLive() {
|
||||||
|
|
||||||
boolean isLive = LiveUtils.isLivePlayer(roomId);
|
boolean isLive = LiveUtils.isLivePlayer(roomId);
|
||||||
upData.setLive(isLive ? 1 : 0);
|
upData.setLive(isLive ? 1 : 0);
|
||||||
|
System.out.println(roomId+"直播状态="+isLive);
|
||||||
|
if(SaveLive.getInstance().checkLive(roomId)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isLive && upData.getSavelive() == 1) {
|
if (isLive && upData.getSavelive() == 1) {
|
||||||
SaveLive.getInstance().addLive(this);
|
SaveLive.getInstance().addLive(this);
|
||||||
}
|
}
|
||||||
@ -362,203 +360,200 @@ public class Live implements ApplicationContextAware {
|
|||||||
BilibiliLiveData liveData = new BilibiliLiveData();
|
BilibiliLiveData liveData = new BilibiliLiveData();
|
||||||
String danmu;
|
String danmu;
|
||||||
GiftData giftData;
|
GiftData giftData;
|
||||||
Log.i(AppTools.getToDayTime(), roomId, json.toJSONString());
|
Log.i(AppTools.getToDayTime(),roomId,json.toJSONString());
|
||||||
if (json.getString("cmd").startsWith("DANMU_MSG")) {//普通弹幕
|
switch (json.getString("cmd")) {
|
||||||
JSONArray infoData = json.getJSONArray("info");
|
case "INTERACT_WORD"://普通用户进直播间
|
||||||
danmu = json.getJSONArray("info").getString(1);
|
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
|
||||||
DanmuData danmuData = new DanmuData();
|
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
||||||
danmuData.setModel(infoData.getJSONArray(0).getInteger(1));
|
liveData.setType(LiveData.INTERACT_WORD);
|
||||||
danmuData.setFontSize(infoData.getJSONArray(0).getInteger(2));
|
liveData.setMsg(danmu);
|
||||||
danmuData.setFontColor(infoData.getJSONArray(0).getInteger(3));
|
liveData.setRoomid(roomId);
|
||||||
danmuData.setTime(infoData.getJSONArray(0).getLong(4));
|
liveData.setSubtime(new Date());
|
||||||
danmuData.setUCode(infoData.getJSONArray(0).getString(7));
|
service.addLiveData(liveData);
|
||||||
danmuData.setDanmu(danmu);
|
break;
|
||||||
danmuData.setUid(infoData.getJSONArray(2).getInteger(0));
|
case "DANMU_MSG"://普通弹幕
|
||||||
danmuData.setUname(infoData.getJSONArray(2).getString(1));
|
JSONArray infoData = json.getJSONArray("info");
|
||||||
|
danmu = json.getJSONArray("info").getString(1);
|
||||||
|
DanmuData danmuData = new DanmuData();
|
||||||
|
danmuData.setModel(infoData.getJSONArray(0).getInteger(1));
|
||||||
|
danmuData.setFontSize(infoData.getJSONArray(0).getInteger(2));
|
||||||
|
danmuData.setFontColor(infoData.getJSONArray(0).getInteger(3));
|
||||||
|
danmuData.setTime(infoData.getJSONArray(0).getLong(4));
|
||||||
|
danmuData.setUCode(infoData.getJSONArray(0).getString(7));
|
||||||
|
danmuData.setDanmu(danmu);
|
||||||
|
danmuData.setUid(infoData.getJSONArray(2).getInteger(0));
|
||||||
|
danmuData.setUname(infoData.getJSONArray(2).getString(1));
|
||||||
|
|
||||||
if (upData != null && upData.getSavedanmu() == 1) {
|
if (upData != null && upData.getSavedanmu() == 1) {
|
||||||
if (danmuManager != null) {
|
if (danmuManager != null) {
|
||||||
danmuManager.addDanmu(danmuData);
|
danmuManager.addDanmu(danmuData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
} else {
|
case "SEND_GIFT"://送礼
|
||||||
switch (json.getString("cmd")) {
|
data = json.getJSONObject("data");
|
||||||
case "INTERACT_WORD"://普通用户进直播间
|
giftData = getGiftData(data.getInteger("giftId"));
|
||||||
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
|
if (giftData == null) {
|
||||||
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
giftData = new GiftData();
|
||||||
liveData.setType(LiveData.INTERACT_WORD);
|
giftData.setName(data.getString("giftName"));
|
||||||
liveData.setMsg(danmu);
|
giftData.setId(data.getInteger("giftId"));
|
||||||
liveData.setRoomid(roomId);
|
giftData.setPrice(data.getInteger("price"));
|
||||||
liveData.setSubtime(new Date());
|
giftData.setIcon("");
|
||||||
service.addLiveData(liveData);
|
giftData.setDesc("这是阿B没有收录的礼物,金额可能不准(无法判别为免费礼物)");
|
||||||
|
giftData.setRights("?");
|
||||||
|
}
|
||||||
|
danmu = data.getString("uname") + " " + data.getString("action") + " " + giftData.getName();
|
||||||
|
liveData.setType(LiveData.SEND_GIFT);
|
||||||
|
liveData.setUid(data.getInteger("uid"));
|
||||||
|
liveData.setGiftid(giftData.getId());
|
||||||
|
liveData.setGiftindex(data.getInteger("num"));
|
||||||
|
liveData.setGiftname(giftData.getName());
|
||||||
|
liveData.setMsg(danmu);
|
||||||
|
liveData.setPrice(giftData.getPrice());
|
||||||
|
liveData.setPriceofcommission(giftData.getPrice() == 0 ? 0 : giftData.getPrice() / 2);
|
||||||
|
liveData.setSubtime(new Date());
|
||||||
|
liveData.setRoomid(roomId);
|
||||||
|
info.setGiftuser(info.getGiftuser() + 1);
|
||||||
|
service.addLiveData(liveData);
|
||||||
|
break;
|
||||||
|
case "COMBO_SEND"://礼物连击
|
||||||
|
data = json.getJSONObject("data");
|
||||||
|
String gift = data.getString("giftName");
|
||||||
|
if (gift == null || "null".equals(gift)) {
|
||||||
|
gift = data.getString("gift_name");
|
||||||
|
}
|
||||||
|
danmu = data.getString("uname") + " " + data.getString("action") + " " + gift + "x" + data.getInteger("batch_combo_num");
|
||||||
|
giftData = getGiftData(data.getInteger("gift_id"));
|
||||||
|
if (giftData == null) {
|
||||||
|
giftData = new GiftData();
|
||||||
|
giftData.setName(data.getString("giftName"));
|
||||||
|
giftData.setId(data.getInteger("giftId"));
|
||||||
|
giftData.setPrice(data.getInteger("price"));
|
||||||
|
giftData.setIcon("");
|
||||||
|
giftData.setDesc("这是阿B没有收录的礼物,金额可能不准(无法判别为免费礼物)");
|
||||||
|
giftData.setRights("?");
|
||||||
|
}
|
||||||
|
liveData.setType(LiveData.COMBO_SEND);
|
||||||
|
liveData.setUid(data.getInteger("uid"));
|
||||||
|
liveData.setGiftid(giftData.getId());
|
||||||
|
liveData.setGiftindex(data.getInteger("batch_combo_num"));
|
||||||
|
liveData.setGiftname(giftData.getName());
|
||||||
|
liveData.setMsg(danmu);
|
||||||
|
liveData.setPrice(giftData.getPrice() * liveData.getGiftindex());
|
||||||
|
liveData.setPriceofcommission(giftData.getPrice() == 0 ? 0 : giftData.getPrice() / 2);
|
||||||
|
liveData.setSubtime(new Date());
|
||||||
|
liveData.setRoomid(roomId);
|
||||||
|
info.setGiftuser(info.getGiftuser() + 1);
|
||||||
|
service.addLiveData(liveData);
|
||||||
|
break;
|
||||||
|
case "ENTRY_EFFECT"://舰长进直播间
|
||||||
|
info.setVipuserindex(info.getVipuserindex() + 1);
|
||||||
|
danmu = "[舰长]" + json.getJSONObject("data").getString("uid") + " 进入到直播间";
|
||||||
|
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
||||||
|
liveData.setType(LiveData.ENTRY_EFFECT);
|
||||||
|
liveData.setMsg(danmu);
|
||||||
|
liveData.setRoomid(roomId);
|
||||||
|
liveData.setSubtime(new Date());
|
||||||
|
service.addLiveData(liveData);
|
||||||
|
break;
|
||||||
|
case "LIVE_INTERACTIVE_GAME"://彩色弹幕?通过游戏弹幕
|
||||||
|
break;
|
||||||
|
case "SUPER_CHAT_MESSAGE"://SC
|
||||||
|
data = json.getJSONObject("data");
|
||||||
|
danmu = data.getJSONObject("user_info").getString("uname") + " "
|
||||||
|
+ data.getJSONObject("gift").getString("gift_name") + " " + data.getInteger("price") + "元: " + data.getString("message");
|
||||||
|
liveData.setType(LiveData.SUPER_CHAT_MESSAGE);
|
||||||
|
liveData.setUid(data.getInteger("uid"));
|
||||||
|
liveData.setMsg(danmu);
|
||||||
|
liveData.setGiftid(0);
|
||||||
|
liveData.setRoomid(roomId);
|
||||||
|
liveData.setGiftname(data.getJSONObject("gift").getString("gift_name"));
|
||||||
|
liveData.setGiftindex(1);
|
||||||
|
liveData.setPrice(data.getInteger("price") * 1000);
|
||||||
|
liveData.setPriceofcommission(liveData.getPrice() == 0 ? 0 : liveData.getPrice() / 2);
|
||||||
|
liveData.setSubtime(new Date());
|
||||||
|
info.setGiftuser(info.getGiftuser() + 1);
|
||||||
|
service.addLiveData(liveData);
|
||||||
|
break;
|
||||||
|
case "USER_TOAST_MSG":
|
||||||
|
break;
|
||||||
|
case "GUARD_BUY"://开通/续费 牛逼的东西
|
||||||
|
data = json.getJSONObject("data");
|
||||||
|
liveData.setType(LiveData.GUARD_BUY);
|
||||||
|
liveData.setUid(data.getInteger("uid"));
|
||||||
|
liveData.setMsg(data.getString("gift_name"));
|
||||||
|
liveData.setGiftid(-data.getInteger("guard_level"));
|
||||||
|
liveData.setGiftindex(data.getInteger("num"));
|
||||||
|
liveData.setGiftname(data.getString("gift_name"));
|
||||||
|
liveData.setPrice(data.getInteger("price"));
|
||||||
|
liveData.setPriceofcommission(liveData.getPrice() == 0 ? 0 : liveData.getPrice() / 2);
|
||||||
|
liveData.setSubtime(new Date());
|
||||||
|
liveData.setRoomid(roomId);
|
||||||
|
info.setGiftuser(info.getGiftuser() + 1);
|
||||||
|
service.addLiveData(liveData);
|
||||||
|
break;
|
||||||
|
case "LIVE"://开始直播,不过有在心跳包上做检测了,所以也无所谓?
|
||||||
|
if (upData.getLive() == 1) {
|
||||||
break;
|
break;
|
||||||
case "DANMU_MSG":
|
}
|
||||||
|
upData.setLive(1);
|
||||||
|
JSONObject liveInfo = LiveUtils.getLiveInfo(roomId);
|
||||||
|
if (liveInfo == null) {
|
||||||
break;
|
break;
|
||||||
case "SEND_GIFT"://送礼
|
}
|
||||||
data = json.getJSONObject("data");
|
LiveInfo info = new LiveInfo();
|
||||||
giftData = getGiftData(data.getInteger("giftId"));
|
info.setTitle(liveInfo.getJSONObject("data").getJSONObject("room_info").getString("title"));
|
||||||
if (giftData == null) {
|
info.setKeyframe(liveInfo.getJSONObject("data").getJSONObject("room_info").getString("keyframe"));
|
||||||
giftData = new GiftData();
|
info.setRoomId(liveInfo.getJSONObject("data").getJSONObject("room_info").getInteger("room_id"));
|
||||||
giftData.setName(data.getString("giftName"));
|
info.setShortId(liveInfo.getJSONObject("data").getJSONObject("room_info").getInteger("short_id"));
|
||||||
giftData.setId(data.getInteger("giftId"));
|
info.setInfo(liveInfo);
|
||||||
giftData.setPrice(data.getInteger("price"));
|
setLiveInfo(info);
|
||||||
giftData.setIcon("");
|
StringBuilder builder = new StringBuilder();
|
||||||
giftData.setDesc("这是阿B没有收录的礼物,金额可能不准(无法判别为免费礼物)");
|
builder.append(upData.getName()).append("开播了!").append("\n");
|
||||||
giftData.setRights("?");
|
builder.append(info.getTitle());
|
||||||
|
Tools.download(info.getKeyframe(), new DownloadInterface() {
|
||||||
|
@Override
|
||||||
|
public void onDownload(File file) {
|
||||||
|
super.onDownload(file);
|
||||||
|
QQBotManager.getInstance().sendMessage(file, builder.toString());
|
||||||
}
|
}
|
||||||
danmu = data.getString("uname") + " " + data.getString("action") + " " + giftData.getName();
|
});
|
||||||
liveData.setType(LiveData.SEND_GIFT);
|
break;
|
||||||
liveData.setUid(data.getInteger("uid"));
|
case "PREPARING"://
|
||||||
liveData.setGiftid(giftData.getId());
|
case "SUPER_CHAT_MESSAGE_JPN":
|
||||||
liveData.setGiftindex(data.getInteger("num"));
|
case "NOTICE_MSG":
|
||||||
liveData.setGiftname(giftData.getName());
|
case "HOT_RANK_CHANGED"://榜单更新等无用信息
|
||||||
liveData.setMsg(danmu);
|
case "ONLINE_RANK_COUNT":
|
||||||
liveData.setPrice(giftData.getPrice());
|
case "ONLINE_RANK_V2":
|
||||||
liveData.setPriceofcommission(giftData.getPrice() == 0 ? 0 : giftData.getPrice() / 2);
|
case "ONLINE_RANK_TOP3":
|
||||||
liveData.setSubtime(new Date());
|
case "ROOM_REAL_TIME_MESSAGE_UPDATE":
|
||||||
liveData.setRoomid(roomId);
|
case "WIDGET_BANNER"://鬼知道是啥
|
||||||
info.setGiftuser(info.getGiftuser() + 1);
|
case "HOT_RANK_SETTLEMENT":
|
||||||
service.addLiveData(liveData);
|
case "PK_BATTLE_SETTLE_V2":
|
||||||
break;
|
case "PK_BATTLE_END":
|
||||||
case "COMBO_SEND"://礼物连击
|
case "PK_BATTLE_SETTLE":
|
||||||
data = json.getJSONObject("data");
|
case "PK_BATTLE_PRE_NEW":
|
||||||
String gift = data.getString("giftName");
|
case "PK_BATTLE_PRE":
|
||||||
if (gift == null || "null".equals(gift)) {
|
case "STOP_LIVE_ROOM_LIST"://不知道是啥,停止直播?
|
||||||
gift = data.getString("gift_name");
|
|
||||||
}
|
|
||||||
danmu = data.getString("uname") + " " + data.getString("action") + " " + gift + "x" + data.getInteger("batch_combo_num");
|
|
||||||
giftData = getGiftData(data.getInteger("gift_id"));
|
|
||||||
if (giftData == null) {
|
|
||||||
giftData = new GiftData();
|
|
||||||
giftData.setName(data.getString("giftName"));
|
|
||||||
giftData.setId(data.getInteger("giftId"));
|
|
||||||
giftData.setPrice(data.getInteger("price"));
|
|
||||||
giftData.setIcon("");
|
|
||||||
giftData.setDesc("这是阿B没有收录的礼物,金额可能不准(无法判别为免费礼物)");
|
|
||||||
giftData.setRights("?");
|
|
||||||
}
|
|
||||||
liveData.setType(LiveData.COMBO_SEND);
|
|
||||||
liveData.setUid(data.getInteger("uid"));
|
|
||||||
liveData.setGiftid(giftData.getId());
|
|
||||||
liveData.setGiftindex(data.getInteger("batch_combo_num"));
|
|
||||||
liveData.setGiftname(giftData.getName());
|
|
||||||
liveData.setMsg(danmu);
|
|
||||||
liveData.setPrice(giftData.getPrice() * liveData.getGiftindex());
|
|
||||||
liveData.setPriceofcommission(giftData.getPrice() == 0 ? 0 : giftData.getPrice() / 2);
|
|
||||||
liveData.setSubtime(new Date());
|
|
||||||
liveData.setRoomid(roomId);
|
|
||||||
info.setGiftuser(info.getGiftuser() + 1);
|
|
||||||
service.addLiveData(liveData);
|
|
||||||
break;
|
|
||||||
case "ENTRY_EFFECT"://舰长进直播间
|
|
||||||
info.setVipuserindex(info.getVipuserindex() + 1);
|
|
||||||
danmu = "[舰长]" + json.getJSONObject("data").getString("uid") + " 进入到直播间";
|
|
||||||
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
|
||||||
liveData.setType(LiveData.ENTRY_EFFECT);
|
|
||||||
liveData.setMsg(danmu);
|
|
||||||
liveData.setRoomid(roomId);
|
|
||||||
liveData.setSubtime(new Date());
|
|
||||||
service.addLiveData(liveData);
|
|
||||||
break;
|
|
||||||
case "LIVE_INTERACTIVE_GAME"://彩色弹幕?通过游戏弹幕
|
|
||||||
break;
|
|
||||||
case "SUPER_CHAT_MESSAGE"://SC
|
|
||||||
data = json.getJSONObject("data");
|
|
||||||
danmu = data.getJSONObject("user_info").getString("uname") + " "
|
|
||||||
+ data.getJSONObject("gift").getString("gift_name") + " " + data.getInteger("price") + "元: " + data.getString("message");
|
|
||||||
liveData.setType(LiveData.SUPER_CHAT_MESSAGE);
|
|
||||||
liveData.setUid(data.getInteger("uid"));
|
|
||||||
liveData.setMsg(danmu);
|
|
||||||
liveData.setGiftid(0);
|
|
||||||
liveData.setRoomid(roomId);
|
|
||||||
liveData.setGiftname(data.getJSONObject("gift").getString("gift_name"));
|
|
||||||
liveData.setGiftindex(1);
|
|
||||||
liveData.setPrice(data.getInteger("price") * 1000);
|
|
||||||
liveData.setPriceofcommission(liveData.getPrice() == 0 ? 0 : liveData.getPrice() / 2);
|
|
||||||
liveData.setSubtime(new Date());
|
|
||||||
info.setGiftuser(info.getGiftuser() + 1);
|
|
||||||
service.addLiveData(liveData);
|
|
||||||
break;
|
|
||||||
case "USER_TOAST_MSG":
|
|
||||||
break;
|
|
||||||
case "GUARD_BUY"://开通/续费 牛逼的东西
|
|
||||||
data = json.getJSONObject("data");
|
|
||||||
liveData.setType(LiveData.GUARD_BUY);
|
|
||||||
liveData.setUid(data.getInteger("uid"));
|
|
||||||
liveData.setMsg(data.getString("gift_name"));
|
|
||||||
liveData.setGiftid(-data.getInteger("guard_level"));
|
|
||||||
liveData.setGiftindex(data.getInteger("num"));
|
|
||||||
liveData.setGiftname(data.getString("gift_name"));
|
|
||||||
liveData.setPrice(data.getInteger("price"));
|
|
||||||
liveData.setPriceofcommission(liveData.getPrice() == 0 ? 0 : liveData.getPrice() / 2);
|
|
||||||
liveData.setSubtime(new Date());
|
|
||||||
liveData.setRoomid(roomId);
|
|
||||||
info.setGiftuser(info.getGiftuser() + 1);
|
|
||||||
service.addLiveData(liveData);
|
|
||||||
break;
|
|
||||||
case "LIVE"://开始直播,不过有在心跳包上做检测了,所以也无所谓?
|
|
||||||
if (upData.getLive() == 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
upData.setLive(1);
|
|
||||||
JSONObject liveInfo = LiveUtils.getLiveInfo(roomId);
|
|
||||||
if (liveInfo == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
LiveInfo info = new LiveInfo();
|
|
||||||
info.setTitle(liveInfo.getJSONObject("data").getJSONObject("room_info").getString("title"));
|
|
||||||
info.setKeyframe(liveInfo.getJSONObject("data").getJSONObject("room_info").getString("keyframe"));
|
|
||||||
info.setRoomId(liveInfo.getJSONObject("data").getJSONObject("room_info").getInteger("room_id"));
|
|
||||||
info.setShortId(liveInfo.getJSONObject("data").getJSONObject("room_info").getInteger("short_id"));
|
|
||||||
info.setInfo(liveInfo);
|
|
||||||
setLiveInfo(info);
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append(upData.getName()).append("开播了!").append("\n");
|
|
||||||
builder.append(info.getTitle());
|
|
||||||
Tools.download(info.getKeyframe(), new DownloadInterface() {
|
|
||||||
@Override
|
|
||||||
public void onDownload(File file) {
|
|
||||||
super.onDownload(file);
|
|
||||||
QQBotManager.getInstance().sendMessage(file, builder.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case "PREPARING"://
|
|
||||||
case "SUPER_CHAT_MESSAGE_JPN":
|
|
||||||
case "NOTICE_MSG":
|
|
||||||
case "HOT_RANK_CHANGED"://榜单更新等无用信息
|
|
||||||
case "ONLINE_RANK_COUNT":
|
|
||||||
case "ONLINE_RANK_V2":
|
|
||||||
case "ONLINE_RANK_TOP3":
|
|
||||||
case "ROOM_REAL_TIME_MESSAGE_UPDATE":
|
|
||||||
case "WIDGET_BANNER"://鬼知道是啥
|
|
||||||
case "HOT_RANK_SETTLEMENT":
|
|
||||||
case "PK_BATTLE_SETTLE_V2":
|
|
||||||
case "PK_BATTLE_END":
|
|
||||||
case "PK_BATTLE_SETTLE":
|
|
||||||
case "PK_BATTLE_PRE_NEW":
|
|
||||||
case "PK_BATTLE_PRE":
|
|
||||||
case "STOP_LIVE_ROOM_LIST"://不知道是啥,停止直播?
|
|
||||||
|
|
||||||
|
|
||||||
//com.yutou.bilibili.Tools.Log.i(msg);
|
//com.yutou.bilibili.Tools.Log.i(msg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.i("[" + roomId + "]" + msg);
|
com.yutou.bilibili.Tools.Log.i("["+roomId+"]"+msg);
|
||||||
liveData = new BilibiliLiveData();
|
liveData = new BilibiliLiveData();
|
||||||
liveData.setType(LiveData.UNKNOWN_MESSAGE);
|
liveData.setType(LiveData.UNKNOWN_MESSAGE);
|
||||||
liveData.setUid(-1);
|
liveData.setUid(-1);
|
||||||
liveData.setMsg(msg);
|
liveData.setMsg(msg);
|
||||||
liveData.setRoomid(roomId);
|
liveData.setRoomid(roomId);
|
||||||
liveData.setSubtime(new Date());
|
liveData.setSubtime(new Date());
|
||||||
service.addLiveData(liveData);
|
service.addLiveData(liveData);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
checkLive();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(e);
|
Log.e(e);
|
||||||
Log.i(AppTools.getToDayTimeToString(startTime), roomId, e.getLocalizedMessage());
|
// Log.i(AppTools.getToDayTimeToString(startTime), roomId, e.getLocalizedMessage());
|
||||||
try {
|
/*try {
|
||||||
JSONObject.parseObject(new String(bytes, StandardCharsets.UTF_8));
|
JSONObject.parseObject(new String(bytes, StandardCharsets.UTF_8));
|
||||||
processData(new String(bytes, StandardCharsets.UTF_8), null);
|
processData(new String(bytes, StandardCharsets.UTF_8), null);
|
||||||
} catch (Exception e2) {
|
} catch (Exception e2) {
|
||||||
@ -572,7 +567,7 @@ public class Live implements ApplicationContextAware {
|
|||||||
com.yutou.bilibili.Tools.Log.i("---------ERROR !! end-----");
|
com.yutou.bilibili.Tools.Log.i("---------ERROR !! end-----");
|
||||||
// LiveUtils.printHex(bytes);
|
// LiveUtils.printHex(bytes);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class BilibiliApplication {
|
public class BilibiliApplication {
|
||||||
|
|
||||||
public static String version="0.7.4.7";
|
public static String version="0.8";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
QQBotManager.getInstance().init();
|
QQBotManager.getInstance().init();
|
||||||
|
@ -98,6 +98,7 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
if (info.getOfflinelistening() == 1) {
|
if (info.getOfflinelistening() == 1) {
|
||||||
if (info.getEnable() == 1) {
|
if (info.getEnable() == 1) {
|
||||||
Live live = LiveUtils.liveContains(info);
|
Live live = LiveUtils.liveContains(info);
|
||||||
|
System.out.println("扫描:"+info.getName()+" 结果:"+(live==null));
|
||||||
if (live == null) {
|
if (live == null) {
|
||||||
live = new Live();
|
live = new Live();
|
||||||
live.add(info.getRoomid(), !StringUtils.isEmpty(AppTools.readFile(new File("cookies.json"))));
|
live.add(info.getRoomid(), !StringUtils.isEmpty(AppTools.readFile(new File("cookies.json"))));
|
||||||
|
@ -31,7 +31,7 @@ public class Log {
|
|||||||
|
|
||||||
public static void i(String timer, int roomId, Object log) {
|
public static void i(String timer, int roomId, Object log) {
|
||||||
String logFlag = RedisTools.get("live-log", 1);
|
String logFlag = RedisTools.get("live-log", 1);
|
||||||
if (logFlag.startsWith("true")) {
|
if (logFlag!=null&&logFlag.startsWith("true")) {
|
||||||
if (logFlag.contains("|")) {
|
if (logFlag.contains("|")) {
|
||||||
if (log.toString().contains(logFlag.split("\\|")[1])) {
|
if (log.toString().contains(logFlag.split("\\|")[1])) {
|
||||||
getLogger("[" + timer.replace(":", "_") + "]" + roomId).log(Level.INFO, log.toString());
|
getLogger("[" + timer.replace(":", "_") + "]" + roomId).log(Level.INFO, log.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user