From 1803ef845c9aa7e653d1dc276a14740c8433575f Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 2 Dec 2024 14:32:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=BC=93=E5=AD=98=E7=9A=84=E8=B0=83=E7=94=A8,?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BD=BF=E7=94=A8=E6=98=AF=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84value=EF=BC=8C=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A6=E5=8F=91=E7=BC=93=E5=AD=98=E8=AE=A1?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yutou/biliapi/databases/BiliLiveDatabase.java | 2 ++ src/main/java/com/yutou/biliapi/net/WebSocketServer.java | 4 +--- .../com/yutou/bilibili/services/LiveDatabasesService.java | 4 +++- .../yutou/bilibili/services/LiveVideoDownloadService.java | 6 ++---- src/main/java/com/yutou/common/databases/SQLiteManager.java | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/yutou/biliapi/databases/BiliLiveDatabase.java b/src/main/java/com/yutou/biliapi/databases/BiliLiveDatabase.java index d563d7b..abc192b 100644 --- a/src/main/java/com/yutou/biliapi/databases/BiliLiveDatabase.java +++ b/src/main/java/com/yutou/biliapi/databases/BiliLiveDatabase.java @@ -10,6 +10,7 @@ import com.yutou.common.databases.AbsDatabasesBean; import com.yutou.common.databases.SQLiteManager; import com.yutou.common.okhttp.HttpDownloadUtils; import com.yutou.common.utils.Log; +import lombok.Getter; import java.io.File; import java.sql.PreparedStatement; @@ -20,6 +21,7 @@ import java.util.Date; import java.util.List; public class BiliLiveDatabase extends SQLiteManager { + @Getter LiveRoomConfig config; String fileName; File rootPath; diff --git a/src/main/java/com/yutou/biliapi/net/WebSocketServer.java b/src/main/java/com/yutou/biliapi/net/WebSocketServer.java index 46cc5aa..af32d2e 100644 --- a/src/main/java/com/yutou/biliapi/net/WebSocketServer.java +++ b/src/main/java/com/yutou/biliapi/net/WebSocketServer.java @@ -163,7 +163,6 @@ public class WebSocketServer { private class WebSocketClientTh extends WebSocketClient { private final LiveRoomConfig roomConfig; private final HeartbeatTask heartbeatTask; - BiliLiveDatabase liveDatabase; private final boolean isUser; public WebSocketClientTh(URI serverUri, LiveRoomConfig roomId, boolean isUser) { @@ -171,7 +170,6 @@ public class WebSocketServer { Log.i("WebSocketClientTh.WebSocketClientTh : " + serverUri); this.isUser = isUser; this.roomConfig = roomId; - liveDatabase = liveDatabasesService.getLiveDatabase(roomConfig.getRoomId()); Brotli4jLoader.ensureAvailability(); heartbeatTask = new HeartbeatTask(); addHeader("User-Agent", ConfigTools.getUserAgent()); @@ -253,7 +251,7 @@ public class WebSocketServer { // Log.i("协议:" + useHeader + " 命令数:" + body.getBodyList().size()); for (JSONObject json : body.getBodyList()) { WSData parse = WSData.parse(json); - liveDatabase.addSource(parse); + liveDatabasesService.getLiveDatabase(roomConfig.getRoomId()).addSource(parse); // Log.i("解压:" + parse); } // Log.i(); diff --git a/src/main/java/com/yutou/bilibili/services/LiveDatabasesService.java b/src/main/java/com/yutou/bilibili/services/LiveDatabasesService.java index 86d2f6c..a097c49 100644 --- a/src/main/java/com/yutou/bilibili/services/LiveDatabasesService.java +++ b/src/main/java/com/yutou/bilibili/services/LiveDatabasesService.java @@ -6,6 +6,7 @@ import com.yutou.biliapi.bean.live.LiveRoomConfig; import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean; import com.yutou.biliapi.databases.BiliLiveConfigDatabase; import com.yutou.biliapi.databases.BiliLiveDatabase; +import com.yutou.common.utils.Log; import lombok.Getter; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -24,6 +25,7 @@ public class LiveDatabasesService { if (it.wasEvicted()) { if (it.getValue() != null) { ((BiliLiveDatabase) it.getValue()).close(); + Log.i("缓存到期移除", ((BiliLiveDatabase) it.getValue()).getConfig().getRoomId()); } } }) @@ -34,7 +36,7 @@ public class LiveDatabasesService { configDatabase = new BiliLiveConfigDatabase(); } public String getCacheInfo() { - return "总数:"+liveDatabases.size()+","+ Arrays.toString(liveDatabases.asMap().keySet().toArray())+","+ Arrays.toString(liveDatabases.asMap().values().toArray()); + return "总数:" + liveDatabases.size() + "," + Arrays.toString(liveDatabases.asMap().keySet().toArray()) + "," + Arrays.toString(liveDatabases.asMap().values().toArray()); } public BiliLiveDatabase getLiveDatabase(String roomId) { diff --git a/src/main/java/com/yutou/bilibili/services/LiveVideoDownloadService.java b/src/main/java/com/yutou/bilibili/services/LiveVideoDownloadService.java index b35650b..8f04dd4 100644 --- a/src/main/java/com/yutou/bilibili/services/LiveVideoDownloadService.java +++ b/src/main/java/com/yutou/bilibili/services/LiveVideoDownloadService.java @@ -142,7 +142,6 @@ public class LiveVideoDownloadService { String savePath; File rootPath; LiveConfigDatabaseBean config; - BiliLiveDatabase database; LiveVideoDatabaseBean videoDatabaseBean = null; LiveRoomInfo roomInfo; @@ -200,7 +199,6 @@ public class LiveVideoDownloadService { config.setLogin(StringUtils.hasText(bean.getRecordUid())); config.setRoomInfo(roomInfo); config.setRootPath(bean.getRecordPath()); - database = liveDatabasesService.getLiveDatabase(bean.getRoomId()); saveLiveInfo(roomInfo); api.getLiveRoomPlayInfo( bean.getRoomId(), @@ -356,7 +354,7 @@ public class LiveVideoDownloadService { } if (videoDatabaseBean != null) { videoDatabaseBean.setStopTime(new Date()); - database.addLiveInfo(videoDatabaseBean); + liveDatabasesService.getLiveDatabase(bean.getRoomId()).addLiveInfo(videoDatabaseBean); } stopRecordDanmu(); } @@ -373,7 +371,7 @@ public class LiveVideoDownloadService { videoDatabaseBean.setPath(savePath); videoDatabaseBean.setRoomInfoJson(JSONObject.toJSONString(roomInfo)); videoDatabaseBean.setStartTime(new Date()); - database.addLiveInfo(videoDatabaseBean); + liveDatabasesService.getLiveDatabase(bean.getRoomId()).addLiveInfo(videoDatabaseBean); recordDanmu(); // LiveInfoNfoTools.saveLiveInfoNfo(roomInfo, rootPath.getAbsolutePath(), new File(savePath).getName().replace(".flv", ".nfo")); } diff --git a/src/main/java/com/yutou/common/databases/SQLiteManager.java b/src/main/java/com/yutou/common/databases/SQLiteManager.java index fc92a5e..75d81d1 100644 --- a/src/main/java/com/yutou/common/databases/SQLiteManager.java +++ b/src/main/java/com/yutou/common/databases/SQLiteManager.java @@ -88,7 +88,7 @@ public abstract class SQLiteManager { } } - public void close() { + public synchronized void close() { try { conn.close(); } catch (SQLException throwables) {