调整部分直播逻辑
This commit is contained in:
parent
57ec517608
commit
251ebe1a0c
@ -11,7 +11,7 @@
|
||||
<body>
|
||||
<div class="layui-layout layui-layout-admin">
|
||||
<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%;">
|
||||
<blockquote class="layui-elem-quote" style="background-color: #FFFFFF; height: 50%;">
|
||||
<div align="center">
|
||||
|
19
pom.xml
19
pom.xml
@ -124,6 +124,25 @@
|
||||
|
||||
<build>
|
||||
<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>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
|
@ -133,7 +133,7 @@ public class Live implements ApplicationContextAware {
|
||||
private void start() throws Exception {
|
||||
run = true;
|
||||
if (LiveUtils.isLivePlayer(roomId)) {
|
||||
upData.setLive(1);
|
||||
upData.setLive(-1);
|
||||
}
|
||||
String url = LiveUtils.getLiveUrl(roomId);
|
||||
if (url == null) {
|
||||
@ -227,14 +227,6 @@ public class Live implements ApplicationContextAware {
|
||||
}
|
||||
};
|
||||
client.connect();
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (client == null || client.isClosed()) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}, 0, 60 * 1000);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
@ -290,6 +282,7 @@ public class Live implements ApplicationContextAware {
|
||||
outputStream.flush();
|
||||
// LiveUtils.printHex(outputStream.toByteArray());
|
||||
client.send(outputStream.toByteArray());
|
||||
checkLive();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -336,8 +329,13 @@ public class Live implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
public void checkLive() {
|
||||
|
||||
boolean isLive = LiveUtils.isLivePlayer(roomId);
|
||||
upData.setLive(isLive ? 1 : 0);
|
||||
System.out.println(roomId+"直播状态="+isLive);
|
||||
if(SaveLive.getInstance().checkLive(roomId)){
|
||||
return;
|
||||
}
|
||||
if (isLive && upData.getSavelive() == 1) {
|
||||
SaveLive.getInstance().addLive(this);
|
||||
}
|
||||
@ -363,7 +361,17 @@ public class Live implements ApplicationContextAware {
|
||||
String danmu;
|
||||
GiftData giftData;
|
||||
Log.i(AppTools.getToDayTime(),roomId,json.toJSONString());
|
||||
if (json.getString("cmd").startsWith("DANMU_MSG")) {//普通弹幕
|
||||
switch (json.getString("cmd")) {
|
||||
case "INTERACT_WORD"://普通用户进直播间
|
||||
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
|
||||
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
||||
liveData.setType(LiveData.INTERACT_WORD);
|
||||
liveData.setMsg(danmu);
|
||||
liveData.setRoomid(roomId);
|
||||
liveData.setSubtime(new Date());
|
||||
service.addLiveData(liveData);
|
||||
break;
|
||||
case "DANMU_MSG"://普通弹幕
|
||||
JSONArray infoData = json.getJSONArray("info");
|
||||
danmu = json.getJSONArray("info").getString(1);
|
||||
DanmuData danmuData = new DanmuData();
|
||||
@ -381,19 +389,6 @@ public class Live implements ApplicationContextAware {
|
||||
danmuManager.addDanmu(danmuData);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (json.getString("cmd")) {
|
||||
case "INTERACT_WORD"://普通用户进直播间
|
||||
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";
|
||||
liveData.setUid(json.getJSONObject("data").getInteger("uid"));
|
||||
liveData.setType(LiveData.INTERACT_WORD);
|
||||
liveData.setMsg(danmu);
|
||||
liveData.setRoomid(roomId);
|
||||
liveData.setSubtime(new Date());
|
||||
service.addLiveData(liveData);
|
||||
break;
|
||||
case "DANMU_MSG":
|
||||
|
||||
break;
|
||||
case "SEND_GIFT"://送礼
|
||||
data = json.getJSONObject("data");
|
||||
@ -545,7 +540,7 @@ public class Live implements ApplicationContextAware {
|
||||
//com.yutou.bilibili.Tools.Log.i(msg);
|
||||
break;
|
||||
default:
|
||||
Log.i("[" + roomId + "]" + msg);
|
||||
com.yutou.bilibili.Tools.Log.i("["+roomId+"]"+msg);
|
||||
liveData = new BilibiliLiveData();
|
||||
liveData.setType(LiveData.UNKNOWN_MESSAGE);
|
||||
liveData.setUid(-1);
|
||||
@ -554,11 +549,11 @@ public class Live implements ApplicationContextAware {
|
||||
liveData.setSubtime(new Date());
|
||||
service.addLiveData(liveData);
|
||||
}
|
||||
}
|
||||
checkLive();
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
Log.i(AppTools.getToDayTimeToString(startTime), roomId, e.getLocalizedMessage());
|
||||
try {
|
||||
// Log.i(AppTools.getToDayTimeToString(startTime), roomId, e.getLocalizedMessage());
|
||||
/*try {
|
||||
JSONObject.parseObject(new String(bytes, StandardCharsets.UTF_8));
|
||||
processData(new String(bytes, StandardCharsets.UTF_8), null);
|
||||
} catch (Exception e2) {
|
||||
@ -572,7 +567,7 @@ public class Live implements ApplicationContextAware {
|
||||
com.yutou.bilibili.Tools.Log.i("---------ERROR !! end-----");
|
||||
// LiveUtils.printHex(bytes);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import org.springframework.context.annotation.Import;
|
||||
@SpringBootApplication
|
||||
public class BilibiliApplication {
|
||||
|
||||
public static String version="0.7.4.7";
|
||||
public static String version="0.8";
|
||||
|
||||
public static void main(String[] args) {
|
||||
QQBotManager.getInstance().init();
|
||||
|
@ -98,6 +98,7 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
if (info.getOfflinelistening() == 1) {
|
||||
if (info.getEnable() == 1) {
|
||||
Live live = LiveUtils.liveContains(info);
|
||||
System.out.println("扫描:"+info.getName()+" 结果:"+(live==null));
|
||||
if (live == null) {
|
||||
live = new Live();
|
||||
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) {
|
||||
String logFlag = RedisTools.get("live-log", 1);
|
||||
if (logFlag.startsWith("true")) {
|
||||
if (logFlag!=null&&logFlag.startsWith("true")) {
|
||||
if (logFlag.contains("|")) {
|
||||
if (log.toString().contains(logFlag.split("\\|")[1])) {
|
||||
getLogger("[" + timer.replace(":", "_") + "]" + roomId).log(Level.INFO, log.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user