From 3f10e19e50128ca208394dab2e582fb7e24d7680 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 28 Nov 2024 18:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E8=8E=B7=E5=8F=96=E5=BC=B9=E5=B9=95?= =?UTF-8?q?=E6=97=B6=E6=8A=9B=E5=BC=82=E5=B8=B8=E5=90=8E=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bilibili/services/LiveDanmuService.java | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java b/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java index ed7037d..9f3342b 100644 --- a/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java +++ b/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java @@ -89,36 +89,42 @@ public class LiveDanmuService { public LiveVideoDanmu getDanmu(String roomId, String videoId, int page) { LiveVideoDanmu danmus = new LiveVideoDanmu(); BiliLiveDatabase liveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig(roomId)); - LiveVideoDatabaseBean videoBean = liveDatabase.getVideo(videoId); - if (videoBean == null) { - return new LiveVideoDanmu(); - } - long startTime = videoBean.getStartTime().getTime(); - long endTime = videoBean.getStopTime() == null ? System.currentTimeMillis() : videoBean.getStopTime().getTime(); - List superChatList = liveDatabase.getOfTime(startTime, endTime, LiveSuperChatDatabaseBean.class); + try { + LiveVideoDatabaseBean videoBean = liveDatabase.getVideo(videoId); + if (videoBean == null) { + return new LiveVideoDanmu(); + } + long startTime = videoBean.getStartTime().getTime(); + long endTime = videoBean.getStopTime() == null ? System.currentTimeMillis() : videoBean.getStopTime().getTime(); + List superChatList = liveDatabase.getOfTime(startTime, endTime, LiveSuperChatDatabaseBean.class); - long count = liveDatabase.getCount(new LiveDanmuDatabaseBean().getTableName()); - int pageSize = 10000; - int pageCount = (int) Math.ceil((double) count / pageSize); + long count = liveDatabase.getCount(new LiveDanmuDatabaseBean().getTableName()); + int pageSize = 10000; + int pageCount = (int) Math.ceil((double) count / pageSize); - List danmuList = liveDatabase.getOfTime(startTime, endTime, page, pageSize, LiveDanmuDatabaseBean.class) - .stream() - .map(item -> createDanmu(item, startTime)) - .filter(item-> item.getTime()>=0) - .toList(); - danmus.getDanmu().addAll(danmuList); - danmus.setDanmuCount(count); - if (page < pageCount) { - danmus.setNextDanmu(true); + List danmuList = liveDatabase.getOfTime(startTime, endTime, page, pageSize, LiveDanmuDatabaseBean.class) + .stream() + .map(item -> createDanmu(item, startTime)) + .filter(item -> item.getTime() >= 0) + .toList(); + danmus.getDanmu().addAll(danmuList); + danmus.setDanmuCount(count); + if (page < pageCount) { + danmus.setNextDanmu(true); + } + + + for (LiveSuperChatDatabaseBean bean : superChatList) { + LiveVideoDanmu.SuperChat superChat = new LiveVideoDanmu.SuperChat(startTime, bean); + danmus.getSuperChat().add(superChat); + } + + } catch (Exception e) { + Log.e(e); + } finally { + liveDatabase.close(); } - - for (LiveSuperChatDatabaseBean bean : superChatList) { - LiveVideoDanmu.SuperChat superChat = new LiveVideoDanmu.SuperChat(startTime, bean); - danmus.getSuperChat().add(superChat); - } - - liveDatabase.close(); return danmus; }