From 34a41f50ac383f29dfd944a5dc9bfe4b3703ddf9 Mon Sep 17 00:00:00 2001
From: zlzw <583819556@qq.com>
Date: Thu, 31 Oct 2024 18:23:39 +0800
Subject: [PATCH] update
---
Web/html/body/video.html | 64 +++------
Web/html/ui/createConfig.html | 131 +++++++++++++----
Web/index.html | 132 ++++++++++++++++--
Web/js/CommonConfig.js | 19 +++
Web/js/httpUtils.js | 74 +++++++---
Web/js/myjs.js | 9 --
.../biliapi/bean/live/LiveAnchorInfo.java | 4 +-
.../biliapi/bean/live/LiveRoomConfig.java | 4 +-
.../yutou/biliapi/bean/live/LiveRoomInfo.java | 4 +-
.../biliapi/bean/live/LiveRoomPlayInfo.java | 4 +-
.../biliapi/bean/live/LiveRoomStatus.java | 2 +-
.../biliapi/bean/live/MasterInfoBean.java | 2 +-
.../live/database/LiveConfigDatabaseBean.java | 90 ++++++------
.../live/database/LiveDanmuDatabaseBean.java | 2 +-
.../live/database/LiveInfoDatabaseBean.java | 4 +-
.../biliapi/bean/login/UserInfoBean.java | 2 +-
.../bean/websocket/live/WSDanmuData.java | 4 +-
.../databases/BiliBiliLoginDatabase.java | 2 +-
.../databases/BiliLiveConfigDatabase.java | 4 +-
.../biliapi/net/BiliLiveNetApiManager.java | 6 +-
.../yutou/biliapi/net/WebSocketManager.java | 4 +-
.../Controllers/LiveConfigController.java | 8 +-
.../bilibili/Controllers/LiveController.java | 32 +++++
.../bilibili/Controllers/TestControllers.java | 7 +
.../yutou/bilibili/Tools/DateFormatUtils.java | 29 +++-
.../yutou/bilibili/datas/web/LiveData.java | 21 +++
.../bilibili/services/LiveConfigService.java | 23 +--
.../bilibili/services/LiveDanmuService.java | 7 +-
.../yutou/bilibili/services/LiveService.java | 62 ++++++++
.../bilibili/services/LiveVideoService.java | 22 +--
.../yutou/common/databases/SQLiteManager.java | 6 +-
31 files changed, 561 insertions(+), 223 deletions(-)
create mode 100644 src/main/java/com/yutou/bilibili/Controllers/LiveController.java
create mode 100644 src/main/java/com/yutou/bilibili/datas/web/LiveData.java
create mode 100644 src/main/java/com/yutou/bilibili/services/LiveService.java
diff --git a/Web/html/body/video.html b/Web/html/body/video.html
index f85158e..a8ea737 100644
--- a/Web/html/body/video.html
+++ b/Web/html/body/video.html
@@ -37,35 +37,15 @@
$('#header').load("/html/header.html");
+
\ No newline at end of file
diff --git a/Web/index.html b/Web/index.html
index 70bfd7f..3e53e82 100644
--- a/Web/index.html
+++ b/Web/index.html
@@ -1,33 +1,141 @@
+
-
-
- DD监视器
-
+
+
+ DD监视器
+
-
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Web/js/CommonConfig.js b/Web/js/CommonConfig.js
index 5a9f65c..c18e18e 100644
--- a/Web/js/CommonConfig.js
+++ b/Web/js/CommonConfig.js
@@ -6,4 +6,23 @@ function createUi(html){
.then(htmlText=>{
return htmlText;
})
+}
+function getParam(name){
+ console.log(window.location.href)
+ var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);
+ if (results == null) {
+ return null;
+ } else {
+ return decodeURI(results[1]) || 0;
+ }
+}
+function showImage(url, imgElement) {
+ getHttpImage(url)
+ .then(imageUrl => {
+ imgElement.src = imageUrl;
+ })
+ .catch(error => {
+ console.log("Error loading image:", error);
+ // 可以在这里设置一个默认图片或者显示错误信息
+ });
}
\ No newline at end of file
diff --git a/Web/js/httpUtils.js b/Web/js/httpUtils.js
index cfe73a1..532eeeb 100644
--- a/Web/js/httpUtils.js
+++ b/Web/js/httpUtils.js
@@ -40,24 +40,7 @@ function post(url,formData,isJSON) {
throw error; // 重新抛出错误以便外部捕获
});
}
-function getLiveVideoList() {
- return get("/live/video/list");
-}
-function getHttpImage(url) {
- const encode = encodeURI(url);
-
- const formData = new FormData();
- formData.append("url", encode);
- return post("/file/img",formData,false)
- .then(blob=>{
- return blob;
- })
-}
-
-function getBiliAllUser(){
- return get("/user/list")
-}
-function addRoomConfig(json){
+function buildFormData(json){
const formData = new FormData();
Object.keys(json).forEach(key => {
@@ -73,5 +56,56 @@ function addRoomConfig(json){
formData.append(key, value);
}
});
- return post("/live/config/set",formData)
-}
\ No newline at end of file
+ return formData;
+}
+
+//----------------直播配置相关接口
+function getLiveVideoList() {
+ return get("/live/video/list");
+}
+function getHttpImage(url) {
+ const encode = encodeURI(url);
+
+ const formData = new FormData();
+ formData.append("url", encode);
+ return post("/file/img",formData,false)
+ .then(blob=>{
+ return blob;
+ })
+}
+function getBiliAllUser(){
+ return get("/user/list")
+}
+function addRoomConfig(json){
+ const formData=buildFormData(json)
+ return post("/live/config/set",formData,true)
+}
+function getRoomConfig(roomId){
+ return get("/live/config/get?roomId="+roomId)
+}
+function deleteRoomConfig(roomId){
+ return get("/live/config/delete?roomId="+roomId)
+}
+
+//----------------直播配置相关接口end
+//----------------首页相关接口
+function getAllLive(){
+ return get("/live/list")
+}
+//----------------首页相关接口end
+//----------------视频相关接口
+function startLiveVideo(roomId){
+ return get("/live/video/start?roomId="+roomId)
+}
+function stopLiveVideo(roomId){
+ return get("/live/video/stop?roomId="+roomId)
+}
+//----------------视频相关接口end
+//----------------弹幕相关接口
+function startLiveDanmu(roomId){
+ return get("/live/danmu/start?roomId="+roomId)
+}
+function stopLiveDanmu(roomId){
+ return get("/live/danmu/stop?roomId="+roomId)
+}
+//----------------弹幕相关接口end
diff --git a/Web/js/myjs.js b/Web/js/myjs.js
index d8f8ad3..add6e71 100644
--- a/Web/js/myjs.js
+++ b/Web/js/myjs.js
@@ -101,12 +101,3 @@ function Base64() {
return string;
}
}
-function getParam(name){
- console.log(window.location.href)
- var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);
- if (results == null) {
- return null;
- } else {
- return decodeURI(results[1]) || 0;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/yutou/biliapi/bean/live/LiveAnchorInfo.java b/src/main/java/com/yutou/biliapi/bean/live/LiveAnchorInfo.java
index 7edd83c..1d3f9fa 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/LiveAnchorInfo.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/LiveAnchorInfo.java
@@ -37,9 +37,9 @@ public class LiveAnchorInfo {
@JSONField(name = "title")
private String title;
@JSONField(name = "room_id")
- private BigInteger roomId;
+ private String roomId;
@JSONField(name = "uid")
- private BigInteger uid;
+ private String uid;
@JSONField(name = "online")
private int online;
@JSONField(name = "live_time")
diff --git a/src/main/java/com/yutou/biliapi/bean/live/LiveRoomConfig.java b/src/main/java/com/yutou/biliapi/bean/live/LiveRoomConfig.java
index 227adfa..f6bf433 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/LiveRoomConfig.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/LiveRoomConfig.java
@@ -11,7 +11,7 @@ import java.util.Objects;
@Data
public class LiveRoomConfig {
String loginUid;
- BigInteger roomId;
+ String roomId;
String anchorName;
boolean isLogin;
String rootPath="live";
@@ -44,7 +44,7 @@ public class LiveRoomConfig {
public static LiveRoomConfig buildConfig(String roomId){
BiliLiveConfigDatabase database = new BiliLiveConfigDatabase();
- LiveConfigDatabaseBean bean = database.getConfig(new BigInteger(roomId));
+ LiveConfigDatabaseBean bean = database.getConfig(new String(roomId));
LiveRoomConfig config = new LiveRoomConfig();
config.setLoginUid(bean.getRecordUid());
diff --git a/src/main/java/com/yutou/biliapi/bean/live/LiveRoomInfo.java b/src/main/java/com/yutou/biliapi/bean/live/LiveRoomInfo.java
index d25fbb5..52562b6 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/LiveRoomInfo.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/LiveRoomInfo.java
@@ -9,10 +9,10 @@ import java.util.List;
@Data
public class LiveRoomInfo {
@JSONField(name = "uid")
- private BigInteger uid;
+ private String uid;
@JSONField(name = "room_id")
- private BigInteger roomId;
+ private String roomId;
@JSONField(name = "short_id")
private int shortId;
diff --git a/src/main/java/com/yutou/biliapi/bean/live/LiveRoomPlayInfo.java b/src/main/java/com/yutou/biliapi/bean/live/LiveRoomPlayInfo.java
index 344f68c..6cbeb1e 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/LiveRoomPlayInfo.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/LiveRoomPlayInfo.java
@@ -12,13 +12,13 @@ import java.util.List;
@Data
public class LiveRoomPlayInfo extends BaseBean {
@JSONField(name = "room_id")
- private BigInteger roomId;
+ private String roomId;
@JSONField(name = "short_id")
private int shortId;
@JSONField(name = "uid")
- private BigInteger uid;
+ private String uid;
@JSONField(name = "is_hidden")
private boolean isHidden;
diff --git a/src/main/java/com/yutou/biliapi/bean/live/LiveRoomStatus.java b/src/main/java/com/yutou/biliapi/bean/live/LiveRoomStatus.java
index 41f3d75..9633734 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/LiveRoomStatus.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/LiveRoomStatus.java
@@ -29,7 +29,7 @@ public class LiveRoomStatus {
private int online;
@JSONField(name = "roomid")
- private BigInteger roomid;
+ private String roomid;
@JSONField(name = "broadcast_type")
private int broadcastType;
diff --git a/src/main/java/com/yutou/biliapi/bean/live/MasterInfoBean.java b/src/main/java/com/yutou/biliapi/bean/live/MasterInfoBean.java
index 70ef99b..0b2baac 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/MasterInfoBean.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/MasterInfoBean.java
@@ -41,7 +41,7 @@ public class MasterInfoBean extends BaseBean {
@Data
public static class Info {
@JSONField(name = "uid")
- private BigInteger uid;
+ private String uid;
@JSONField(name = "uname")
private String uname;
diff --git a/src/main/java/com/yutou/biliapi/bean/live/database/LiveConfigDatabaseBean.java b/src/main/java/com/yutou/biliapi/bean/live/database/LiveConfigDatabaseBean.java
index 1bdb2ee..f593464 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/database/LiveConfigDatabaseBean.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/database/LiveConfigDatabaseBean.java
@@ -2,12 +2,17 @@ package com.yutou.biliapi.bean.live.database;
import com.alibaba.fastjson2.annotation.JSONField;
import com.alibaba.fastjson2.util.DateUtils;
+import com.yutou.bilibili.Tools.DateFormatUtils;
import com.yutou.common.databases.AbsDatabasesBean;
+import com.yutou.common.utils.Log;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.File;
import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -18,9 +23,9 @@ import static com.alibaba.fastjson2.util.DateUtils.DateTimeFormatPattern.DATE_FO
@Data
public class LiveConfigDatabaseBean extends AbsDatabasesBean {
@JSONField(name = "live_room_id")
- private BigInteger roomId;
+ private String roomId;
@JSONField(name = "anchorUid")
- private BigInteger anchorUid;
+ private String anchorUid;
@JSONField(name = "anchorName")
private String anchorName;
@JSONField(name = "anchorFace")
@@ -31,6 +36,8 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
private boolean isRecordDanmu;
@JSONField(name = "keyword")
private List keywordList;
+ @JSONField(name = "week")
+ private List weeks;
@JSONField(name = "recordPath")
private String recordPath = "live";
@JSONField(name = "recordUid")
@@ -38,9 +45,9 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
@JSONField(name = "recordLiveModel")
private int recordLiveModel;//0 - ffmpeg 1 - java
@JSONField(name = "recordDanmuDate")
- private String recordDanmuDate = "* * *";// * * * 分 时 星期 | 周日是1
+ private String recordDanmuDate = null;// 时间范围 20:00:00 - 23:59:59
@JSONField(name = "recordLiveDate")
- private String recordLiveDate = "* * *";// * * * 分 时 星期 | 周日是1
+ private String recordLiveDate = null;// 时间范围 20:00:00 - 23:59:59
public LiveConfigDatabaseBean() {
@@ -64,55 +71,42 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
}
private boolean verifyTimer(String val) {
- int _length = val.length();
- boolean isFullDate = (_length - val.replace("*", "").length()) == 3
- && (_length - val.replace("*", "").trim().length()) == 0;
- String[] split = val.split(" ");
- if (isFullDate) {
- return true;
- }
- String minute = split[0];
- String hour = split[1];
- String day = split[2];
+ String t = "20:00:00 - 23:59:59";
try {
- Integer.parseInt(minute);
- Integer.parseInt(hour);
- Integer.parseInt(day);
+ String[] time = val.split(" - ");
+ Date start = DateFormatUtils.parseTimer(time[0]);
+ Date end = DateFormatUtils.parseTimer(time[1]);
+ if (start != null && end != null) {
+ return true;
+ }
} catch (Exception e) {
- return false;
+ Log.e(e);
}
- return true;
+ return false;
}
private boolean checkRecordTime(String recordDate) {
- int _length = recordDate.length();
- boolean isFullDate = (_length - recordDate.replace("*", "").length()) == 3;
- if (isFullDate) {
- return true;
- }
- String[] split = recordDate.split(" ");
- String minute = split[0];
- String hour = split[1];
- String day = split[2];
- boolean isFullMinute = "*".equals(minute);
- boolean isFullHour = "*".equals(hour);
- boolean isFullDay = "*".equals(day);
- Calendar today = Calendar.getInstance();
- if (!isFullDay) {
- if (today.get(Calendar.DAY_OF_WEEK) != Integer.parseInt(day) + 1) {
- return false;
- }
- }
- if (!isFullHour) {
- if (today.get(Calendar.HOUR_OF_DAY) != Integer.parseInt(hour)) {
- return false;
- }
- }
- if (!isFullMinute) {
- if (today.get(Calendar.MINUTE) != Integer.parseInt(minute)) {
- return false;
- }
- }
- return true;
+ //TODO 待测试
+ String[] parts = recordDate.split(" - ");
+ LocalTime startTime = LocalTime.parse(parts[0], DateTimeFormatter.ofPattern("HH:mm:ss"));
+ LocalTime endTime = LocalTime.parse(parts[1], DateTimeFormatter.ofPattern("HH:mm:ss"));
+
+
+ // 获取当前时间
+ LocalTime currentTime = LocalTime.now();
+ LocalDate currentDate = LocalDate.now();
+
+
+ // 获取当前日期对应的星期几(1-7分别对应周一到周日)
+ int currentWeekDay = currentDate.getDayOfWeek().getValue();
+
+ // 判断当前日期是否在指定的星期列表中
+ boolean isSpecifiedWeekDay = weeks.contains(String.valueOf(currentWeekDay));
+
+
+ // 判断当前时间是否在指定的时间范围内
+ boolean isWithinRange = (currentTime.isAfter(startTime) || currentTime.equals(startTime)) &&
+ (currentTime.isBefore(endTime) || currentTime.equals(endTime));
+ return isWithinRange && isSpecifiedWeekDay;
}
}
diff --git a/src/main/java/com/yutou/biliapi/bean/live/database/LiveDanmuDatabaseBean.java b/src/main/java/com/yutou/biliapi/bean/live/database/LiveDanmuDatabaseBean.java
index d5aec40..9b469b9 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/database/LiveDanmuDatabaseBean.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/database/LiveDanmuDatabaseBean.java
@@ -25,7 +25,7 @@ public class LiveDanmuDatabaseBean extends AbsDatabasesBean {
@JSONField(name = "time")
private long time;
@JSONField(name = "uid")
- private BigInteger uid;
+ private String uid;
@JSONField(name = "uname")
private String uname;
diff --git a/src/main/java/com/yutou/biliapi/bean/live/database/LiveInfoDatabaseBean.java b/src/main/java/com/yutou/biliapi/bean/live/database/LiveInfoDatabaseBean.java
index 711c171..a582b24 100644
--- a/src/main/java/com/yutou/biliapi/bean/live/database/LiveInfoDatabaseBean.java
+++ b/src/main/java/com/yutou/biliapi/bean/live/database/LiveInfoDatabaseBean.java
@@ -18,9 +18,9 @@ public class LiveInfoDatabaseBean extends AbsDatabasesBean {
@JSONField(name = "id")
int id;
@JSONField(name = "roomId")
- private BigInteger roomId;
+ private String roomId;
@JSONField(name = "anchorUid")
- private BigInteger anchorUid;
+ private String anchorUid;
@JSONField(name = "title")
private String title;
@JSONField(name = "record_time_start")
diff --git a/src/main/java/com/yutou/biliapi/bean/login/UserInfoBean.java b/src/main/java/com/yutou/biliapi/bean/login/UserInfoBean.java
index 3e0878c..85e2178 100644
--- a/src/main/java/com/yutou/biliapi/bean/login/UserInfoBean.java
+++ b/src/main/java/com/yutou/biliapi/bean/login/UserInfoBean.java
@@ -32,7 +32,7 @@ public class UserInfoBean extends BaseBean {
private LevelInfo levelInfo;
@JSONField(name = "mid")
- private BigInteger mid;
+ private String mid;
@JSONField(name = "mobile_verified")
private int mobileVerified;
diff --git a/src/main/java/com/yutou/biliapi/bean/websocket/live/WSDanmuData.java b/src/main/java/com/yutou/biliapi/bean/websocket/live/WSDanmuData.java
index 4d5cace..a6d911d 100644
--- a/src/main/java/com/yutou/biliapi/bean/websocket/live/WSDanmuData.java
+++ b/src/main/java/com/yutou/biliapi/bean/websocket/live/WSDanmuData.java
@@ -23,7 +23,7 @@ public class WSDanmuData extends WSData {
private long time;
private String uCode;
private String danmu;
- private BigInteger uid;
+ private String uid;
private String uname;
private WSUserMedal medal;
@@ -36,7 +36,7 @@ public class WSDanmuData extends WSData {
setTime(infoData.getJSONArray(0).getLong(4));
setUCode(infoData.getJSONArray(0).getString(7));
setDanmu(infoData.getString(1));
- setUid(infoData.getJSONArray(2).getBigInteger(0));
+ setUid(infoData.getJSONArray(2).getFirst().toString());
setUname(infoData.getJSONArray(2).getString(1));
try {
medal = WSUserMedal.create(infoData.getJSONArray(3));
diff --git a/src/main/java/com/yutou/biliapi/databases/BiliBiliLoginDatabase.java b/src/main/java/com/yutou/biliapi/databases/BiliBiliLoginDatabase.java
index 2ed513d..980a72f 100644
--- a/src/main/java/com/yutou/biliapi/databases/BiliBiliLoginDatabase.java
+++ b/src/main/java/com/yutou/biliapi/databases/BiliBiliLoginDatabase.java
@@ -61,7 +61,7 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
return list.getFirst();
}
for (LoginUserDatabaseBean bean : list) {
- if (bean.getUserInfo().getMid().equals(new BigInteger(userId))) {
+ if (bean.getUserInfo().getMid().equals(new String(userId))) {
return bean;
}
}
diff --git a/src/main/java/com/yutou/biliapi/databases/BiliLiveConfigDatabase.java b/src/main/java/com/yutou/biliapi/databases/BiliLiveConfigDatabase.java
index eacfd9e..d082007 100644
--- a/src/main/java/com/yutou/biliapi/databases/BiliLiveConfigDatabase.java
+++ b/src/main/java/com/yutou/biliapi/databases/BiliLiveConfigDatabase.java
@@ -41,7 +41,7 @@ public class BiliLiveConfigDatabase extends SQLiteManager {
update(bean);
}
- public LiveConfigDatabaseBean getConfig(BigInteger roomId) {
+ public LiveConfigDatabaseBean getConfig(String roomId) {
List list = get(getDataBean().get(0).getTableName(), LiveConfigDatabaseBean.class);
if (list.isEmpty()) {
return null;
@@ -54,7 +54,7 @@ public class BiliLiveConfigDatabase extends SQLiteManager {
return null;
}
- public boolean deleteConfig(BigInteger roomId) {
+ public boolean deleteConfig(String roomId) {
LiveConfigDatabaseBean config = getConfig(roomId);
if (config == null) {
return false;
diff --git a/src/main/java/com/yutou/biliapi/net/BiliLiveNetApiManager.java b/src/main/java/com/yutou/biliapi/net/BiliLiveNetApiManager.java
index 71a0b56..d43b18b 100644
--- a/src/main/java/com/yutou/biliapi/net/BiliLiveNetApiManager.java
+++ b/src/main/java/com/yutou/biliapi/net/BiliLiveNetApiManager.java
@@ -44,18 +44,18 @@ public class BiliLiveNetApiManager extends BaseApi {
return createApi(LiveApi.class);
}
- public Map getAnchorInfos(String loginUid,List anchorIds) {
+ public Map getAnchorInfos(String loginUid,List anchorIds) {
JSONObject json = new JSONObject();
json.put("uids", anchorIds);
try {
String src = getApi(loginUid).getLiveRoomStatus(json).execute().body().getSrc();
json = JSONObject.parseObject(src);
if (json.getInteger("code") == 0) {
- Map map = new HashMap<>();
+ Map map = new HashMap<>();
JSONObject data = json.getJSONObject("data");
for (String key : data.keySet()) {
LiveAnchorInfo info = JSONObject.parseObject(data.getString(key), LiveAnchorInfo.class);
- map.put(new BigInteger(key), info);
+ map.put(key, info);
}
return map;
}
diff --git a/src/main/java/com/yutou/biliapi/net/WebSocketManager.java b/src/main/java/com/yutou/biliapi/net/WebSocketManager.java
index d07025d..c42f208 100644
--- a/src/main/java/com/yutou/biliapi/net/WebSocketManager.java
+++ b/src/main/java/com/yutou/biliapi/net/WebSocketManager.java
@@ -85,7 +85,7 @@ public class WebSocketManager {
public void stopRoom(String roomId, boolean isUser) {
LiveRoomConfig roomConfig = new LiveRoomConfig();
- roomConfig.setRoomId(new BigInteger(roomId));
+ roomConfig.setRoomId(new String(roomId));
if (checkRoom(roomConfig)) {
roomMap.get(roomConfig).close();
roomMap.remove(roomConfig);
@@ -278,7 +278,7 @@ public class WebSocketManager {
String buvid = BiliUserUtils.getBuvid(BiliBiliLoginDatabase.getInstance().getCookie(roomConfig.getLoginUid()));
if (buvid != null) {
try {
- json.put("roomid", roomConfig.getRoomId());
+ json.put("roomid", new BigInteger(roomConfig.getRoomId()));
json.put("protover", 3);
json.put("buvid", buvid);
json.put("platform", "web");
diff --git a/src/main/java/com/yutou/bilibili/Controllers/LiveConfigController.java b/src/main/java/com/yutou/bilibili/Controllers/LiveConfigController.java
index aaf5ec8..b1b35d8 100644
--- a/src/main/java/com/yutou/bilibili/Controllers/LiveConfigController.java
+++ b/src/main/java/com/yutou/bilibili/Controllers/LiveConfigController.java
@@ -56,7 +56,7 @@ public class LiveConfigController {
return ResultData.fail(ReturnCode.RC999.getCode(),"弹幕录制时间格式错误");
}
- LiveConfigDatabaseBean config = configService.updateConfig(new BigInteger(roomId), bean);
+ LiveConfigDatabaseBean config = configService.updateConfig(new String(roomId), bean);
if (config != null) {
return ResultData.success(config.toJson());
}
@@ -69,7 +69,7 @@ public class LiveConfigController {
if ("0".equals(roomId) || !StringUtils.hasText(roomId)) {
return ResultData.fail(ReturnCode.RC999);
}
- LiveConfigDatabaseBean config = configService.getConfig(new BigInteger(roomId));
+ LiveConfigDatabaseBean config = configService.getConfig(new String(roomId));
if (config != null) {
return ResultData.success(config.toJson());
}
@@ -88,8 +88,8 @@ public class LiveConfigController {
@RequestMapping(value = "delete", method = RequestMethod.GET)
@ResponseBody
- public JSONObject deleteConfig(BigInteger roomId) {
- if (roomId.equals(BigInteger.ZERO)) {
+ public JSONObject deleteConfig(String roomId) {
+ if ("0".equals(roomId)|| !StringUtils.hasText(roomId)) {
return ResultData.fail(ReturnCode.RC999);
}
boolean flag = configService.deleteConfig(roomId);
diff --git a/src/main/java/com/yutou/bilibili/Controllers/LiveController.java b/src/main/java/com/yutou/bilibili/Controllers/LiveController.java
new file mode 100644
index 0000000..aa4e14f
--- /dev/null
+++ b/src/main/java/com/yutou/bilibili/Controllers/LiveController.java
@@ -0,0 +1,32 @@
+package com.yutou.bilibili.Controllers;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.yutou.bilibili.datas.ResultData;
+import com.yutou.bilibili.datas.VideoFilePath;
+import com.yutou.bilibili.services.LiveDanmuService;
+import com.yutou.bilibili.services.LiveService;
+import com.yutou.bilibili.services.LiveVideoService;
+import jakarta.annotation.Resource;
+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
+ LiveVideoService videoService;
+ @Resource
+ LiveDanmuService danmuService;
+ @Resource
+ LiveService liveService;
+
+
+ @RequestMapping("/live/list")
+ @ResponseBody
+ public JSONObject getLiveList(){
+
+ return ResultData.success(liveService.getLiveList());
+ }
+}
diff --git a/src/main/java/com/yutou/bilibili/Controllers/TestControllers.java b/src/main/java/com/yutou/bilibili/Controllers/TestControllers.java
index 76f29cb..a12d2d7 100644
--- a/src/main/java/com/yutou/bilibili/Controllers/TestControllers.java
+++ b/src/main/java/com/yutou/bilibili/Controllers/TestControllers.java
@@ -1,5 +1,6 @@
package com.yutou.bilibili.Controllers;
+import com.yutou.common.okhttp.HttpLoggingInterceptor;
import com.yutou.common.utils.FFmpegUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,4 +13,10 @@ public class TestControllers {
public String test(){
return "hello world";
}
+ @ResponseBody
+ @RequestMapping("/root/log")
+ public String log(boolean flag){
+ HttpLoggingInterceptor.setLog(flag);
+ return flag+"";
+ }
}
diff --git a/src/main/java/com/yutou/bilibili/Tools/DateFormatUtils.java b/src/main/java/com/yutou/bilibili/Tools/DateFormatUtils.java
index 0042115..fb25929 100644
--- a/src/main/java/com/yutou/bilibili/Tools/DateFormatUtils.java
+++ b/src/main/java/com/yutou/bilibili/Tools/DateFormatUtils.java
@@ -1,22 +1,41 @@
package com.yutou.bilibili.Tools;
+import com.yutou.common.utils.Log;
+
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatUtils {
- public static String format(Date date,String format){
+ public static String format(Date date, String format) {
return new SimpleDateFormat(format).format(date);
}
- public static String format(long time,String format){
+
+ public static String format(long time, String format) {
return new SimpleDateFormat(format).format(new Date(time));
}
- public static String format(long time){
+
+ public static String format(long time) {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(time));
}
- public static String format(Date date){
+
+ public static String format(Date date) {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(date);
}
- public static String format(){
+
+ public static String format() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
}
+
+ public static Date parseTimer(String date) {
+ return parse(date, "HH:mm:ss");
+ }
+
+ public static Date parse(String date, String format) {
+ try {
+ return new SimpleDateFormat(format).parse(date);
+ } catch (Exception e) {
+ Log.e(e);
+ return null;
+ }
+ }
}
diff --git a/src/main/java/com/yutou/bilibili/datas/web/LiveData.java b/src/main/java/com/yutou/bilibili/datas/web/LiveData.java
new file mode 100644
index 0000000..004068d
--- /dev/null
+++ b/src/main/java/com/yutou/bilibili/datas/web/LiveData.java
@@ -0,0 +1,21 @@
+package com.yutou.bilibili.datas.web;
+
+import com.yutou.common.okhttp.BaseBean;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class LiveData extends BaseBean {
+ private String roomId;
+ private String anchorName;
+ private String anchorUid;
+ private String anchorFace;
+ private String title;
+ private String cover;
+ private boolean isLive;
+ private boolean isDanmu;
+ private boolean isDownloadVideo;
+
+
+}
diff --git a/src/main/java/com/yutou/bilibili/services/LiveConfigService.java b/src/main/java/com/yutou/bilibili/services/LiveConfigService.java
index 84f61ca..c6e5341 100644
--- a/src/main/java/com/yutou/bilibili/services/LiveConfigService.java
+++ b/src/main/java/com/yutou/bilibili/services/LiveConfigService.java
@@ -27,7 +27,7 @@ public class LiveConfigService {
if (!StringUtils.hasText(roomId)) {
return null;
}
- bean.setRoomId(new BigInteger(roomId));
+ bean.setRoomId(new String(roomId));
try {
LiveRoomInfo body = BiliLiveNetApiManager.getInstance().getApi(null).getRoomInfo(String.valueOf(bean.getRoomId())).execute().body().getData();
MasterInfoBean infoBean = BiliLiveNetApiManager.getInstance().getApi(null).getMasterInfo(String.valueOf(body.getUid())).execute().body().getData();
@@ -36,14 +36,13 @@ public class LiveConfigService {
bean.setAnchorFace(infoBean.getInfo().getFace());
bean.setAnchorName(infoBean.getInfo().getUname());
database.setConfig(bean);
- downloadFace(bean);
return bean;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
- public LiveConfigDatabaseBean updateConfig(BigInteger roomId, LiveConfigDatabaseBean bean) {
+ public LiveConfigDatabaseBean updateConfig(String roomId, LiveConfigDatabaseBean bean) {
LiveConfigDatabaseBean config = database.getConfig(roomId);
if (config == null) {
return null;
@@ -51,11 +50,10 @@ public class LiveConfigService {
bean.setRoomId(roomId);
bean.setSql_time(config.getSql_time());
database.setConfig(bean);
- downloadFace(bean);
return bean;
}
- public boolean deleteConfig(BigInteger roomId) {
+ public boolean deleteConfig(String roomId) {
LiveConfigDatabaseBean config = database.getConfig(roomId);
if (config == null) {
return false;
@@ -68,32 +66,23 @@ public class LiveConfigService {
return database.getAllConfig();
}
- public LiveConfigDatabaseBean getConfig(BigInteger roomId) {
+ public LiveConfigDatabaseBean getConfig(String roomId) {
return database.getConfig(roomId);
}
public File getFace(String roomId) {
- LiveConfigDatabaseBean config = database.getConfig(new BigInteger(roomId));
+ LiveConfigDatabaseBean config = database.getConfig(new String(roomId));
if (config == null) {
return null;
}
return new File(config.getRecordPath() + File.separator + config.getAnchorName() + File.separator + config.getAnchorFace());
}
- private void downloadFace(LiveConfigDatabaseBean bean) {
- HttpDownloadUtils.download(
- new HttpDownloadUtils.Builder()
- .setPath(bean.getRecordPath() + File.separator + bean.getAnchorName())
- .setUrl(bean.getAnchorFace())
- .setFileName("face.jpg")
- );
- bean.setAnchorFace(bean.getRecordPath() + File.separator + bean.getAnchorName() + File.separator + "face.jpg");
- }
public boolean checkUrl(String url) {
if (!url.startsWith("https://live.bilibili.com/")) {
try {
- new BigInteger(url);
+ new String(url);
} catch (Exception e) {
return false;
}
diff --git a/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java b/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java
index c5f32b7..8ec4d8d 100644
--- a/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java
+++ b/src/main/java/com/yutou/bilibili/services/LiveDanmuService.java
@@ -25,6 +25,11 @@ public class LiveDanmuService {
public void start(String roomId,boolean isUser) {
WebSocketManager.getInstance().addRoom(LiveRoomConfig.buildConfig(roomId), isUser);
}
+ public boolean check(String roomId) {
+ LiveRoomConfig roomConfig = new LiveRoomConfig();
+ roomConfig.setRoomId(roomId);
+ return WebSocketManager.getInstance().checkRoom(roomConfig);
+ }
public void stop(String roomId,boolean isUser) {
WebSocketManager.getInstance().stopRoom(roomId, isUser);
@@ -37,7 +42,7 @@ public class LiveDanmuService {
public List getDanmuFileList(String roomId) {
BiliLiveConfigDatabase configDatabase=new BiliLiveConfigDatabase();
- LiveConfigDatabaseBean bean = configDatabase.getConfig(new BigInteger(roomId));
+ LiveConfigDatabaseBean bean = configDatabase.getConfig(new String(roomId));
configDatabase.close();
return Tools.scanFile(new File(bean.getRecordPath() + File.separator + bean.getAnchorName()));
}
diff --git a/src/main/java/com/yutou/bilibili/services/LiveService.java b/src/main/java/com/yutou/bilibili/services/LiveService.java
new file mode 100644
index 0000000..22be5f9
--- /dev/null
+++ b/src/main/java/com/yutou/bilibili/services/LiveService.java
@@ -0,0 +1,62 @@
+package com.yutou.bilibili.services;
+
+import com.yutou.biliapi.api.LiveApi;
+import com.yutou.biliapi.bean.live.LiveRoomInfo;
+import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
+import com.yutou.biliapi.databases.BiliLiveConfigDatabase;
+import com.yutou.biliapi.net.BiliLiveNetApiManager;
+import com.yutou.bilibili.datas.web.LiveData;
+import com.yutou.common.okhttp.HttpBody;
+import com.yutou.common.utils.AppTools;
+import com.yutou.common.utils.Log;
+import jakarta.annotation.Resource;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class LiveService {
+ BiliLiveConfigDatabase liveConfigDatabase;
+ @Resource
+ LiveVideoService videoService;
+ @Resource
+ LiveDanmuService danmuService;
+ LiveApi api;
+
+ public LiveService() {
+ liveConfigDatabase = new BiliLiveConfigDatabase();
+ api = BiliLiveNetApiManager.getInstance().getApi(null);
+ }
+
+ public List getLiveList() {
+ List allConfig = liveConfigDatabase.getAllConfig();
+ List liveDataList = new ArrayList<>();
+ for (LiveConfigDatabaseBean config : allConfig) {
+ LiveData liveData = new LiveData();
+ liveData.setRoomId(config.getRoomId());
+ liveData.setAnchorUid(config.getAnchorUid());
+ liveData.setAnchorName(config.getAnchorName());
+ liveData.setAnchorFace(config.getAnchorFace());
+ liveData.setDownloadVideo(videoService.checkDownload(config.getRoomId()));
+ liveData.setDanmu(danmuService.check(config.getRoomId()));
+ try {
+ LiveRoomInfo body = api.getRoomInfo(config.getRoomId()).execute().body().getData();
+ if (body != null) {
+ liveData.setTitle(body.getTitle());
+ liveData.setLive(body.getLiveStatus() == 1);
+ if (body.getLiveStatus() == 1) {
+ liveData.setCover(body.getKeyframe());
+ } else {
+ liveData.setCover(body.getUserCover());
+ }
+ }
+ liveDataList.add(liveData);
+ } catch (IOException e) {
+ Log.e(e);
+ }
+ }
+ return liveDataList;
+ }
+}
diff --git a/src/main/java/com/yutou/bilibili/services/LiveVideoService.java b/src/main/java/com/yutou/bilibili/services/LiveVideoService.java
index 1112bbd..a9b1937 100644
--- a/src/main/java/com/yutou/bilibili/services/LiveVideoService.java
+++ b/src/main/java/com/yutou/bilibili/services/LiveVideoService.java
@@ -47,16 +47,20 @@ import static com.alibaba.fastjson2.util.DateUtils.DateTimeFormatPattern.DATE_FO
@Service
public class LiveVideoService {
- ThreadPoolExecutor executor;
+ private final ThreadPoolExecutor executor;
private final List userStopList = new ArrayList<>();//手动停止列表
- AbsVideoRecord videoRecord;
+ private final AbsVideoRecord videoRecord;
public LiveVideoService() {
Log.i("初始化下载服务");
- videoRecord=new FFmpegUtils();
+ videoRecord = new FFmpegUtils();
executor = new ThreadPoolExecutor(2, 4, Long.MAX_VALUE, TimeUnit.SECONDS, new ArrayBlockingQueue(100));
}
+ public boolean checkDownload(String roomId) {
+ return videoRecord.check(roomId);
+ }
+
public void start(LiveConfigDatabaseBean bean, boolean isUser) {
if (!isUser && userStopList.contains(bean.getRoomId().toString())) {
return;
@@ -240,15 +244,17 @@ public class LiveVideoService {
cookie = ck.toCookieString();
}
- FFmpegUtils command = new FFmpegUtils.Builder()
+ FFmpegUtils.Builder builder = new FFmpegUtils.Builder()
.withParam("-user_agent", ConfigTools.getUserAgent())
- .withParam("-cookies", cookie)
.withParam("-headers", "Referer: https://live.bilibili.com")
// .withNotSymbolParam("-progress", "-")
.withNotSymbolParam("-threads", "8")
.withNotSymbolParam("-c:v", "copy")
- .withNotSymbolParam("-y", "")
- .build(config.getRoomId().toString(), ffmpegPath, url, savePath);
+ .withNotSymbolParam("-y", "");
+ if (ck != null) {
+ builder = builder.withParam("-cookies", cookie);
+ }
+ FFmpegUtils command = builder.build(config.getRoomId(), ffmpegPath, url, savePath);
Log.i(command.getCommand());
try {
command.start(new DownloadInterface() {
@@ -306,7 +312,7 @@ public class LiveVideoService {
public List getVideoPath(String roomId) {
BiliLiveConfigDatabase configDatabase = new BiliLiveConfigDatabase();
- LiveConfigDatabaseBean bean = configDatabase.getConfig(new BigInteger(roomId));
+ LiveConfigDatabaseBean bean = configDatabase.getConfig(new String(roomId));
configDatabase.close();
return new ArrayList<>(getVideoFilePath(bean));
}
diff --git a/src/main/java/com/yutou/common/databases/SQLiteManager.java b/src/main/java/com/yutou/common/databases/SQLiteManager.java
index d1f5ef0..247cf73 100644
--- a/src/main/java/com/yutou/common/databases/SQLiteManager.java
+++ b/src/main/java/com/yutou/common/databases/SQLiteManager.java
@@ -54,7 +54,7 @@ public abstract class SQLiteManager {
type = BuildSqlItem.TYPE_BOOLEAN;
} else if (field.getType() == ISqlDatabaseBean.class) {
type = BuildSqlItem.TYPE_TEXT;
- } else if (field.getType() == BigInteger.class) {
+ } else if (field.getType() == String.class) {
type = BuildSqlItem.TYPE_INT;
}
items.add(BuildSqlItem.create().setName(name).setType(type).setNull(!"id".equals(name)).setKey("id".equals(name)));
@@ -136,7 +136,7 @@ public abstract class SQLiteManager {
statement.setInt(i++, json.getInteger(key));
} else if (json.get(key) instanceof Long) {
statement.setLong(i++, json.getLong(key));
- } else if (json.get(key) instanceof BigInteger) {
+ } else if (json.get(key) instanceof String) {
statement.setObject(i++, json.get(key));
} else if (json.get(key) instanceof Boolean) {
statement.setBoolean(i++, json.getBoolean(key));
@@ -353,7 +353,7 @@ public abstract class SQLiteManager {
public static void main(String[] args) {
LiveConfigDatabaseBean bean = new LiveConfigDatabaseBean();
- bean.setRoomId(new BigInteger("123"));
+ bean.setRoomId(new String("123"));
bean.setRecordLive(true);
bean.setKeywordList(List.of("111", "22"));
JSONObject json = bean.toJson();