新增了关键词检测
新增了手动暂停的恢复
This commit is contained in:
@@ -37,7 +37,7 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
|
||||
@JSONField(name = "syncDanmuForLive")
|
||||
private boolean isSyncDanmuForLive;
|
||||
@JSONField(name = "keyword")
|
||||
private List<String> keywordList;
|
||||
private List<String> keywordList=new ArrayList<>();
|
||||
@JSONField(name = "weeks")
|
||||
private List<String> weeks=Arrays.asList("1","2","3","4","5","6","7");
|
||||
@JSONField(name = "recordPath")
|
||||
|
||||
@@ -97,6 +97,14 @@ public class WebSocketServer {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeUserStopList(String roomId) {
|
||||
userStopList.remove(roomId);
|
||||
}
|
||||
|
||||
public boolean isUserStopList(String roomId) {
|
||||
return userStopList.contains(roomId);
|
||||
}
|
||||
|
||||
private class DanmuTask implements Runnable {
|
||||
LiveRoomConfig roomConfig;
|
||||
WebSocketClientTh client;
|
||||
|
||||
@@ -139,7 +139,7 @@ public class LiveConfigController {
|
||||
@RequestMapping(value = "set/array", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public JSONObject addArrayConfig(@RequestBody JSONObject jsonObject) {
|
||||
JSONObject config=jsonObject.getJSONObject("config");
|
||||
JSONObject config = jsonObject.getJSONObject("config");
|
||||
LiveConfigDatabaseBean bean = config.to(LiveConfigDatabaseBean.class);
|
||||
if (!bean.verifyLiveTimer()) {
|
||||
return ResultData.fail(ReturnCode.RC999.getCode(), "视频录制时间格式错误");
|
||||
@@ -147,15 +147,18 @@ public class LiveConfigController {
|
||||
if (!bean.verifyDanmuTimer()) {
|
||||
return ResultData.fail(ReturnCode.RC999.getCode(), "弹幕录制时间格式错误");
|
||||
}
|
||||
if("on".equals(config.getString("recordDanmu"))){
|
||||
if ("on".equals(config.getString("recordDanmu"))) {
|
||||
bean.setRecordDanmu(true);
|
||||
}
|
||||
if("on".equals(config.getString("recordLive"))){
|
||||
if ("on".equals(config.getString("recordLive"))) {
|
||||
bean.setRecordLive(true);
|
||||
}
|
||||
if("on".equals(config.getString("syncDanmuForLive"))){
|
||||
if ("on".equals(config.getString("syncDanmuForLive"))) {
|
||||
bean.setSyncDanmuForLive(true);
|
||||
}
|
||||
if (config.containsKey("keywordList")) {
|
||||
bean.setKeywordList(config.getList("keywordList", String.class));
|
||||
}
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("array");
|
||||
List<LiveConfigDatabaseBean> list = jsonArray.stream().map(roomId -> configService.addConfig(roomId.toString(), bean)).toList();
|
||||
int countNull = list.stream().filter(Objects::isNull).toList().size();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yutou.bilibili.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.bilibili.datas.ResultData;
|
||||
import com.yutou.bilibili.services.LiveDanmuService;
|
||||
@@ -10,6 +11,8 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class LiveController {
|
||||
@Resource
|
||||
@@ -22,13 +25,31 @@ public class LiveController {
|
||||
|
||||
@RequestMapping("/live/list")
|
||||
@ResponseBody
|
||||
public JSONObject getLiveList(int page,int limit) {
|
||||
return ResultData.success(liveService.getLiveList(page,limit), liveService.getConfigCount());
|
||||
public JSONObject getLiveList(int page, int limit) {
|
||||
List<JSONObject> list = liveService.getLiveList(page, limit).stream().map(it -> {
|
||||
JSONObject json = JSONObject.parseObject(JSON.toJSONString(it));
|
||||
if (videoService.isUserStopList(it.getRoomId())) {
|
||||
json.put("videoListen", "已暂停");
|
||||
} else if (it.isDownloadVideo()) {
|
||||
json.put("videoListen", "录制中");
|
||||
} else {
|
||||
json.put("videoListen", "待机中");
|
||||
}
|
||||
if (danmuService.isUserStopList(it.getRoomId())) {
|
||||
json.put("danmuListen", "已暂停");
|
||||
} else if (it.isDanmu()) {
|
||||
json.put("danmuListen", "录制中");
|
||||
} else {
|
||||
json.put("danmuListen", "待机中");
|
||||
}
|
||||
return json;
|
||||
}).toList();
|
||||
return ResultData.success(list, liveService.getConfigCount());
|
||||
}
|
||||
|
||||
@RequestMapping("/live/gift/info")
|
||||
@ResponseBody
|
||||
public JSONObject download(String roomId, String videoId) {
|
||||
return ResultData.success(liveService.getGiftInfo(roomId,videoId));
|
||||
return ResultData.success(liveService.getGiftInfo(roomId, videoId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ import java.util.List;
|
||||
public class LiveConfigService {
|
||||
@Resource
|
||||
LiveDatabasesService databasesService;
|
||||
@Resource
|
||||
LiveDanmuService danmuService;
|
||||
@Resource
|
||||
LiveVideoDownloadService videoDownloadService;
|
||||
|
||||
public LiveConfigDatabaseBean addConfig(String url, LiveConfigDatabaseBean bean) {
|
||||
if (!StringUtils.hasText(url)) {
|
||||
@@ -37,6 +41,8 @@ public class LiveConfigService {
|
||||
bean.setAnchorFace(infoBean.getInfo().getFace());
|
||||
bean.setAnchorName(infoBean.getInfo().getUname());
|
||||
databasesService.getConfigDatabase().setConfig(bean);
|
||||
danmuService.removeUserStopList(roomId);
|
||||
videoDownloadService.removeUserStopList(roomId);
|
||||
return bean;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -66,7 +72,8 @@ public class LiveConfigService {
|
||||
public List<LiveConfigDatabaseBean> getAllConfig() {
|
||||
return databasesService.getConfigDatabase().getAllConfig();
|
||||
}
|
||||
public List<LiveConfigDatabaseBean> getConfigs(int page,int limit) {
|
||||
|
||||
public List<LiveConfigDatabaseBean> getConfigs(int page, int limit) {
|
||||
return databasesService.getConfigDatabase().getConfigs(page, limit);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,12 @@ public class LiveDanmuService {
|
||||
public void clearUserList() {
|
||||
webSocketServer.clearUserStopList();
|
||||
}
|
||||
public void removeUserStopList(String roomId) {
|
||||
webSocketServer.removeUserStopList(roomId);
|
||||
}
|
||||
public boolean isUserStopList(String roomId) {
|
||||
return webSocketServer.isUserStopList(roomId);
|
||||
}
|
||||
|
||||
public List<File> getDanmuFileList(String roomId) {
|
||||
LiveConfigDatabaseBean bean = liveDatabasesService.getConfigDatabase().getConfig(roomId);
|
||||
|
||||
@@ -67,6 +67,12 @@ public class LiveVideoDownloadService {
|
||||
public void clearUserStopList() {
|
||||
userStopList.clear();
|
||||
}
|
||||
public void removeUserStopList(String roomId) {
|
||||
userStopList.remove(roomId);
|
||||
}
|
||||
public boolean isUserStopList(String roomId) {
|
||||
return userStopList.contains(roomId);
|
||||
}
|
||||
|
||||
public void start(LiveConfigDatabaseBean bean, boolean isUser) {
|
||||
if (!isUser && userStopList.contains(bean.getRoomId())) {
|
||||
@@ -82,6 +88,19 @@ public class LiveVideoDownloadService {
|
||||
@Override
|
||||
public void onResponse(Headers headers, int code, String status, LiveRoomInfo response, String rawResponse) {
|
||||
if (response.getLiveStatus() == 1) {
|
||||
if (!bean.getKeywordList().isEmpty() && !isUser) {
|
||||
String foundKey = bean.getKeywordList().stream()
|
||||
.filter(key -> response.getTitle().contains(key))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (foundKey != null) {
|
||||
Log.i(response.getRoomId(), "检测到开播关键词", foundKey, response.getTitle());
|
||||
} else {
|
||||
Log.i(response.getRoomId(), "未检测到关键词", response.getTitle(), Arrays.toString(bean.getKeywordList().toArray()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
VideoTask task = new VideoTask(bean, response);
|
||||
executor.execute(task);
|
||||
} else {
|
||||
@@ -281,7 +300,7 @@ public class LiveVideoDownloadService {
|
||||
// .withNotSymbolParam("-threads", "8")//看bili-go也没有加这个,改成设置好了
|
||||
// .withNotSymbolParam("-bufsize", "10M")
|
||||
.withNotSymbolParam("-f", "segment")
|
||||
.withNotSymbolParam("-rw_timeout","60000000")
|
||||
.withNotSymbolParam("-rw_timeout", "60000000")
|
||||
.withNotSymbolParam("-segment_time", "60")
|
||||
.withNotSymbolParam("-segment_format", "mpegts")
|
||||
.withNotSymbolParam("-map", "0")
|
||||
|
||||
Reference in New Issue
Block a user