调整数据库全部走LiveDatabaseServer
This commit is contained in:
parent
8afb8f8f0b
commit
5ae1b474f9
@ -10,7 +10,7 @@
|
||||
|
||||
<body>
|
||||
<div id="header"></div>
|
||||
<div class="layui-row layui-col-space15">
|
||||
<div class="layui-row">
|
||||
<div id="follow">
|
||||
</div>
|
||||
<div id="card"></div>
|
||||
@ -141,7 +141,7 @@
|
||||
})
|
||||
}
|
||||
}, function () {
|
||||
layer.msg('点击取消的回调');
|
||||
|
||||
});
|
||||
}
|
||||
function confirmFollow(userId) {
|
||||
|
@ -14,13 +14,13 @@ public class LiveRoomConfig {
|
||||
String roomId;
|
||||
String anchorName;
|
||||
boolean isLogin;
|
||||
String rootPath="live";
|
||||
String rootPath = "live";
|
||||
LiveDanmuInfo liveInfo;
|
||||
LiveRoomInfo roomInfo;
|
||||
|
||||
public String getLoginUid() {
|
||||
if("null".equals(loginUid)){
|
||||
loginUid=null;
|
||||
if ("null".equals(loginUid)) {
|
||||
loginUid = null;
|
||||
}
|
||||
return loginUid;
|
||||
}
|
||||
@ -42,9 +42,11 @@ public class LiveRoomConfig {
|
||||
return Objects.hashCode(roomId);
|
||||
}
|
||||
|
||||
public static LiveRoomConfig buildConfig(String roomId){
|
||||
|
||||
@Deprecated
|
||||
public static LiveRoomConfig buildConfigTmp(String roomId) {
|
||||
BiliLiveConfigDatabase database = new BiliLiveConfigDatabase();
|
||||
LiveConfigDatabaseBean bean = database.getConfig(new String(roomId));
|
||||
LiveConfigDatabaseBean bean = database.getConfig(roomId);
|
||||
database.close();
|
||||
LiveRoomConfig config = new LiveRoomConfig();
|
||||
config.setLoginUid(bean.getRecordUid());
|
||||
|
@ -271,7 +271,7 @@ public class BiliLiveDatabase extends SQLiteManager {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("33989"));
|
||||
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfigTmp("33989"));
|
||||
// biliLiveDatabase.resetSQL();
|
||||
biliLiveDatabase.resetData();
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
|
||||
import com.yutou.biliapi.databases.BiliLiveConfigDatabase;
|
||||
import com.yutou.bilibili.datas.ResultData;
|
||||
import com.yutou.bilibili.datas.ReturnCode;
|
||||
import com.yutou.bilibili.services.LiveDatabasesService;
|
||||
import com.yutou.bilibili.services.LiveVideoDownloadService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@ -17,6 +18,8 @@ import java.util.List;
|
||||
public class LiveVideoController {
|
||||
@Resource
|
||||
LiveVideoDownloadService videoService;
|
||||
@Resource
|
||||
LiveDatabasesService databasesService;
|
||||
|
||||
@RequestMapping("/live/video/list")
|
||||
@ResponseBody
|
||||
@ -34,9 +37,7 @@ public class LiveVideoController {
|
||||
@RequestMapping("/live/video/start")
|
||||
@ResponseBody
|
||||
public JSONObject startDownload(String roomId) {
|
||||
BiliLiveConfigDatabase liveConfigDatabase = new BiliLiveConfigDatabase();
|
||||
List<LiveConfigDatabaseBean> list = liveConfigDatabase.getAllConfig();
|
||||
liveConfigDatabase.close();
|
||||
List<LiveConfigDatabaseBean> list = databasesService.getConfigDatabase().getAllConfig();
|
||||
for (LiveConfigDatabaseBean bean : list) {
|
||||
if (bean.getRoomId().toString().equals(roomId)) {
|
||||
videoService.start(bean, true);
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.yutou.bilibili.Tools;
|
||||
|
||||
import com.yutou.bilibili.services.LiveDatabasesService;
|
||||
import com.yutou.bilibili.services.LiveVideoDownloadService;
|
||||
import com.yutou.bilibili.services.SystemService;
|
||||
import com.yutou.common.utils.Log;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -14,10 +16,14 @@ public class ApplicationClose implements ApplicationListener<ContextClosedEvent>
|
||||
SystemService systemConfigService;
|
||||
@Resource
|
||||
LiveVideoDownloadService videoService;
|
||||
@Resource
|
||||
LiveDatabasesService databasesService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
|
||||
public void onApplicationEvent(@NotNull ContextClosedEvent contextClosedEvent) {
|
||||
Log.i("服务结束");
|
||||
systemConfigService.stop();
|
||||
videoService.stopAll();
|
||||
databasesService.closeAll();
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import java.io.File;
|
||||
public class LiveInfoNfoTools {
|
||||
public static void saveLiveInfoNfo(LiveRoomInfo info, String path,String xmlName) {
|
||||
try {
|
||||
LiveRoomConfig config = LiveRoomConfig.buildConfig(info.getRoomId().toString());
|
||||
LiveRoomConfig config = LiveRoomConfig.buildConfigTmp(info.getRoomId());
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = null;
|
||||
dBuilder = dbFactory.newDocumentBuilder();
|
||||
|
@ -17,7 +17,8 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LiveConfigService {
|
||||
BiliLiveConfigDatabase database = new BiliLiveConfigDatabase();
|
||||
@Resource
|
||||
LiveDatabasesService databasesService;
|
||||
|
||||
public LiveConfigDatabaseBean addConfig(String url, LiveConfigDatabaseBean bean) {
|
||||
if (!StringUtils.hasText(url)) {
|
||||
@ -35,7 +36,7 @@ public class LiveConfigService {
|
||||
bean.setRoomId(body.getRoomId());
|
||||
bean.setAnchorFace(infoBean.getInfo().getFace());
|
||||
bean.setAnchorName(infoBean.getInfo().getUname());
|
||||
database.setConfig(bean);
|
||||
databasesService.getConfigDatabase().setConfig(bean);
|
||||
return bean;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -43,38 +44,38 @@ public class LiveConfigService {
|
||||
}
|
||||
|
||||
public LiveConfigDatabaseBean updateConfig(String roomId, LiveConfigDatabaseBean bean) {
|
||||
LiveConfigDatabaseBean config = database.getConfig(roomId);
|
||||
LiveConfigDatabaseBean config = databasesService.getConfigDatabase().getConfig(roomId);
|
||||
if (config == null) {
|
||||
return null;
|
||||
}
|
||||
bean.setRoomId(roomId);
|
||||
bean.setSql_time(config.getSql_time());
|
||||
database.setConfig(bean);
|
||||
databasesService.getConfigDatabase().setConfig(bean);
|
||||
return bean;
|
||||
}
|
||||
|
||||
public boolean deleteConfig(String roomId) {
|
||||
LiveConfigDatabaseBean config = database.getConfig(roomId);
|
||||
LiveConfigDatabaseBean config = databasesService.getConfigDatabase().getConfig(roomId);
|
||||
if (config == null) {
|
||||
return false;
|
||||
|
||||
}
|
||||
return database.deleteConfig(roomId);
|
||||
return databasesService.getConfigDatabase().deleteConfig(roomId);
|
||||
}
|
||||
|
||||
public List<LiveConfigDatabaseBean> getAllConfig() {
|
||||
return database.getAllConfig();
|
||||
return databasesService.getConfigDatabase().getAllConfig();
|
||||
}
|
||||
public List<LiveConfigDatabaseBean> getConfigs(int page,int limit) {
|
||||
return database.getConfigs(page, limit);
|
||||
return databasesService.getConfigDatabase().getConfigs(page, limit);
|
||||
}
|
||||
|
||||
public LiveConfigDatabaseBean getConfig(String roomId) {
|
||||
return database.getConfig(roomId);
|
||||
return databasesService.getConfigDatabase().getConfig(roomId);
|
||||
}
|
||||
|
||||
public File getFace(String roomId) {
|
||||
LiveConfigDatabaseBean config = database.getConfig(new String(roomId));
|
||||
LiveConfigDatabaseBean config = databasesService.getConfigDatabase().getConfig(new String(roomId));
|
||||
if (config == null) {
|
||||
return null;
|
||||
}
|
||||
@ -102,6 +103,6 @@ public class LiveConfigService {
|
||||
}
|
||||
|
||||
public int getConfigCount() {
|
||||
return database.getConfigCount();
|
||||
return databasesService.getConfigDatabase().getConfigCount();
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ public class LiveDanmuService {
|
||||
WebSocketServer webSocketServer;
|
||||
|
||||
public void start(String roomId, boolean isUser) {
|
||||
webSocketServer.addRoom(LiveRoomConfig.buildConfig(roomId), isUser);
|
||||
webSocketServer.addRoom(liveDatabasesService.buildConfig(roomId), isUser);
|
||||
}
|
||||
|
||||
public void start(LiveConfigDatabaseBean roomId, boolean isUser) {
|
||||
webSocketServer.addRoom(LiveRoomConfig.buildConfig(roomId.getRoomId()), isUser);
|
||||
webSocketServer.addRoom(liveDatabasesService.buildConfig(roomId.getRoomId()), isUser);
|
||||
}
|
||||
|
||||
public boolean check(String roomId) {
|
||||
@ -56,9 +56,7 @@ public class LiveDanmuService {
|
||||
}
|
||||
|
||||
public List<File> getDanmuFileList(String roomId) {
|
||||
BiliLiveConfigDatabase configDatabase = new BiliLiveConfigDatabase();
|
||||
LiveConfigDatabaseBean bean = configDatabase.getConfig(roomId);
|
||||
configDatabase.close();
|
||||
LiveConfigDatabaseBean bean = liveDatabasesService.getConfigDatabase().getConfig(roomId);
|
||||
return Tools.scanFile(new File(bean.getRecordPath() + File.separator + bean.getAnchorName()));
|
||||
}
|
||||
|
||||
@ -150,7 +148,7 @@ public class LiveDanmuService {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BiliLiveDatabase database = new BiliLiveDatabase(LiveRoomConfig.buildConfig("17961"));
|
||||
BiliLiveDatabase database = new BiliLiveDatabase(LiveRoomConfig.buildConfigTmp("17961"));
|
||||
for (LiveVideoDatabaseBean info : database.getLiveInfos()) {
|
||||
System.out.println(info);
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package com.yutou.bilibili.services;
|
||||
|
||||
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 lombok.Getter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -10,12 +14,33 @@ import java.util.Map;
|
||||
@Service
|
||||
public class LiveDatabasesService {
|
||||
private final Map<String, BiliLiveDatabase> liveDatabases=new HashMap<>();
|
||||
@Getter
|
||||
private final BiliLiveConfigDatabase configDatabase;
|
||||
|
||||
private LiveDatabasesService() {
|
||||
configDatabase=new BiliLiveConfigDatabase();
|
||||
}
|
||||
public BiliLiveDatabase getLiveDatabase(String roomId) {
|
||||
if(liveDatabases.containsKey(roomId)) {
|
||||
return liveDatabases.get(roomId);
|
||||
}
|
||||
BiliLiveDatabase liveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig(roomId));
|
||||
BiliLiveDatabase liveDatabase = new BiliLiveDatabase(buildConfig(roomId));
|
||||
liveDatabases.put(roomId, liveDatabase);
|
||||
return liveDatabase;
|
||||
}
|
||||
public void closeAll(){
|
||||
liveDatabases.forEach((k,v)->v.close());
|
||||
configDatabase.close();
|
||||
}
|
||||
|
||||
public LiveRoomConfig buildConfig(String roomId){
|
||||
LiveConfigDatabaseBean bean = configDatabase.getConfig(roomId);
|
||||
LiveRoomConfig config = new LiveRoomConfig();
|
||||
config.setLoginUid(bean.getRecordUid());
|
||||
config.setRoomId(bean.getRoomId());
|
||||
config.setAnchorName(bean.getAnchorName());
|
||||
config.setLogin(StringUtils.hasText(bean.getRecordUid()));
|
||||
config.setRootPath(bean.getRecordPath());
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -4,31 +4,22 @@ import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.biliapi.api.LiveApi;
|
||||
import com.yutou.biliapi.bean.live.LiveAnchorInfo;
|
||||
import com.yutou.biliapi.bean.live.LiveRoomConfig;
|
||||
import com.yutou.biliapi.bean.live.LiveRoomInfo;
|
||||
import com.yutou.biliapi.bean.live.LiveRoomPlayInfo;
|
||||
import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
|
||||
import com.yutou.biliapi.bean.live.database.LiveVideoDatabaseBean;
|
||||
import com.yutou.biliapi.databases.BiliLiveConfigDatabase;
|
||||
import com.yutou.biliapi.databases.BiliLiveDatabase;
|
||||
import com.yutou.biliapi.net.BiliLiveNetApiManager;
|
||||
import com.yutou.bilibili.Tools.DateFormatUtils;
|
||||
import com.yutou.bilibili.datas.web.LiveData;
|
||||
import com.yutou.common.okhttp.BaseBean;
|
||||
import com.yutou.common.okhttp.HttpLoggingInterceptor;
|
||||
import com.yutou.common.utils.FFmpegUtils;
|
||||
import com.yutou.common.utils.Log;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class LiveService {
|
||||
BiliLiveConfigDatabase liveConfigDatabase;
|
||||
@Resource
|
||||
LiveVideoDownloadService videoDownloadService;
|
||||
@Resource
|
||||
@ -39,16 +30,15 @@ public class LiveService {
|
||||
|
||||
|
||||
public LiveService() {
|
||||
liveConfigDatabase = new BiliLiveConfigDatabase();
|
||||
api = BiliLiveNetApiManager.getInstance().getApi(null);
|
||||
}
|
||||
|
||||
public int getConfigCount() {
|
||||
return liveConfigDatabase.getAllConfig().size();
|
||||
return databasesService.getConfigDatabase().getAllConfig().size();
|
||||
}
|
||||
|
||||
public List<LiveData> getLiveList(int page, int limit) {
|
||||
List<LiveConfigDatabaseBean> allConfig = liveConfigDatabase.getAllConfig();
|
||||
List<LiveConfigDatabaseBean> allConfig = databasesService.getConfigDatabase().getAllConfig();
|
||||
List<LiveData> liveDataList = new ArrayList<>();
|
||||
if (allConfig.isEmpty()) {
|
||||
return liveDataList;
|
||||
|
@ -281,6 +281,7 @@ public class LiveVideoDownloadService {
|
||||
// .withNotSymbolParam("-threads", "8")//看bili-go也没有加这个,改成设置好了
|
||||
// .withNotSymbolParam("-bufsize", "10M")
|
||||
.withNotSymbolParam("-f", "segment")
|
||||
.withNotSymbolParam("-rw_timeout","60000000")
|
||||
.withNotSymbolParam("-segment_time", "60")
|
||||
.withNotSymbolParam("-segment_format", "mpegts")
|
||||
.withNotSymbolParam("-map", "0")
|
||||
@ -360,13 +361,13 @@ public class LiveVideoDownloadService {
|
||||
|
||||
//录制弹幕
|
||||
private void recordDanmu() {
|
||||
if (bean.isSyncDanmuForLive() && !webSocketServer.checkRoom(LiveRoomConfig.buildConfig(bean.getRoomId()))) {
|
||||
webSocketServer.addRoom(LiveRoomConfig.buildConfig(bean.getRoomId()), true);
|
||||
if (bean.isSyncDanmuForLive() && !webSocketServer.checkRoom(liveDatabasesService.buildConfig(bean.getRoomId()))) {
|
||||
webSocketServer.addRoom(liveDatabasesService.buildConfig(bean.getRoomId()), true);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopRecordDanmu() {
|
||||
if (bean.isSyncDanmuForLive() && webSocketServer.checkRoom(LiveRoomConfig.buildConfig(bean.getRoomId()))) {
|
||||
if (bean.isSyncDanmuForLive() && webSocketServer.checkRoom(liveDatabasesService.buildConfig(bean.getRoomId()))) {
|
||||
webSocketServer.stopRoom(bean.getRoomId(), false);
|
||||
}
|
||||
}
|
||||
@ -377,9 +378,7 @@ public class LiveVideoDownloadService {
|
||||
}
|
||||
|
||||
public VideoFilePath getVideoPath(String roomId) {
|
||||
BiliLiveConfigDatabase configDatabase = new BiliLiveConfigDatabase();
|
||||
LiveConfigDatabaseBean bean = configDatabase.getConfig(roomId);
|
||||
configDatabase.close();
|
||||
LiveConfigDatabaseBean bean = liveDatabasesService.getConfigDatabase().getConfig(roomId);
|
||||
return getVideoFilePath(bean);
|
||||
}
|
||||
|
||||
@ -428,10 +427,8 @@ public class LiveVideoDownloadService {
|
||||
|
||||
public String getVideoPlay(String roomId, String videoId) {
|
||||
String ffmpegPath = ConfigTools.load(ConfigTools.CONFIG, "ffmpeg", String.class);
|
||||
BiliLiveConfigDatabase configDatabase = new BiliLiveConfigDatabase();
|
||||
LiveConfigDatabaseBean config = configDatabase.getConfig(roomId);
|
||||
LiveConfigDatabaseBean config = liveDatabasesService.getConfigDatabase().getConfig(roomId);
|
||||
String recordPath = config.getRecordPath() + File.separator + config.getAnchorName();
|
||||
configDatabase.close();
|
||||
LiveVideoDatabaseBean videoInfo = null;
|
||||
for (LiveVideoDatabaseBean info : liveDatabasesService.getLiveDatabase(roomId).getLiveInfos()) {
|
||||
if (videoId.trim().equals(String.valueOf(info.getSql_time().getTime()))) {
|
||||
|
@ -22,11 +22,12 @@ public class SystemService {
|
||||
LiveVideoDownloadService videoService;
|
||||
@Resource
|
||||
LiveDanmuService danmuService;
|
||||
@Resource
|
||||
LiveDatabasesService databasesService;
|
||||
|
||||
SystemConfigDatabases databases = new SystemConfigDatabases();
|
||||
private ScheduledExecutorService timer;
|
||||
private ScheduledFuture<?> scheduled;
|
||||
BiliLiveConfigDatabase liveConfigDatabase = new BiliLiveConfigDatabase();
|
||||
|
||||
public long getLoopTimer() {
|
||||
SystemConfigDatabaseBean config = databases.getConfig();
|
||||
@ -47,7 +48,7 @@ public class SystemService {
|
||||
scheduled.cancel(true);
|
||||
}
|
||||
scheduled = timer.scheduleAtFixedRate(() -> {
|
||||
List<LiveConfigDatabaseBean> list = liveConfigDatabase.getAllConfig();
|
||||
List<LiveConfigDatabaseBean> list = databasesService.getConfigDatabase().getAllConfig();
|
||||
Log.i("循环任务:" + list.size());
|
||||
if (DateFormatUtils.getInstance().checkTime(null, resetTimer)) {
|
||||
videoService.clearUserStopList();
|
||||
@ -64,10 +65,6 @@ public class SystemService {
|
||||
}
|
||||
// 如果bean需要录制直播,并且检查录制直播时间
|
||||
if (bean.isRecordLive() && bean.checkRecordLiveTime()) {
|
||||
// 如果需要同步直播弹幕,则录制弹幕
|
||||
if (bean.isSyncDanmuForLive()) {
|
||||
recordDanmu(bean);
|
||||
}
|
||||
// 录制视频
|
||||
recordVideo(bean);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user