This commit is contained in:
zlzw 2024-10-31 18:23:39 +08:00
parent 4b04c1863b
commit 34a41f50ac
31 changed files with 561 additions and 223 deletions

View File

@ -37,35 +37,15 @@
$('#header').load("/html/header.html");
</script>
<script>
function showImage(url, imgElement) {
getHttpImage(url)
.then(imageUrl => {
imgElement.src = imageUrl;
})
.catch(error => {
console.error("Error loading image:", error);
// 可以在这里设置一个默认图片或者显示错误信息
imgElement.src = 'default-image.jpg';
});
}
function createRoom() {
function createRoom(roomId) {
layer.open({
type: 2,
title:"添加新房间",
title: "添加新房间",
area: ['500px', '400px'],
content: '/html/ui/createConfig.html'
});
// createUi("/html/ui/createConfig.html")
// .then(html => {
// layer.open({
// type: 1,
// area: ['500px', '300px'],
// content: '/html/ui/createConfig.html'
// });
// })
}
content: '/html/ui/createConfig.html?roomId=' + roomId
});
}
</script>
<script>
layui.use(['table', 'dropdown'], function () {
@ -93,16 +73,16 @@
},
cols: [[
{ type: 'checkbox', fixed: 'left' },
{ field: 'anchorUid', title: 'UID', width: 80, sort: true, fixed: 'left' },
{ field: 'anchorUid', title: 'UID', width: 100, sort: true, fixed: 'left', templet: '<div><a href="https://space.bilibili.com/{{= d.anchorUid}}" target="_blank">{{= d.anchorUid}}</a>' },
{ field: 'anchorName', title: '用户名', width: 100, fixed: 'left' },
{ field: 'anchorFace', title: '头像', width: 80, templet: '<div><image src="" onerror="showImage(\'{{= d.anchorFace }}\',this);" style="width: 30px;height: 30px;"></div>' },
{ field: 'live_room_id', title: '房间号', width: 80 },
{ field: 'live_room_id', title: '房间号', width: 80, templet: '<div><a href="https://live.bilibili.com/{{= d.live_room_id}}" target="_blank">{{= d.live_room_id}}</a>' },
{ field: 'recordPath', title: '保存路径', width: 120 },
{ field: 'recordDanmu', title: '录制弹幕', width: 120, sort: true },
{ field: 'recordLive', title: '录制视频', width: 120, sort: true },
{ field: 'recordDanmuDate', title: '弹幕录制预定时间', width: 170, sort: true },
{ field: 'recordLiveDate', title: '视频录制预定时间', width: 170, sort: true },
{ field: 'recordUid', title: '录制账号', width: 120, sort: true },
{ field: 'recordDanmuDate', title: '弹幕录制预定时间', width: 100, sort: true },
{ field: 'recordLiveDate', title: '视频录制预定时间', width: 100, sort: true },
{ field: 'recordUid', title: '录制账号', width: 120, sort: true, templet: '<div><a href="https://space.bilibili.com/{{= d.recordUid}}" target="_blank">{{= d.recordUid}}</a>' },
{ field: 'recordDanmu', title: '录制弹幕', width: 120, sort: true },
{ field: 'sql_time', title: '添加时间', width: 100 },
{ fixed: "right", title: "操作", width: 190, align: "center", toolbar: "#toolDemo" }
@ -133,14 +113,9 @@
// 触发单元格工具事件
table.on('tool(roomTable)', function (obj) { // 双击 toolDouble
var data = obj.data; // 获得当前行数据
// console.log(obj)
console.log(obj)
if (obj.event === 'edit') {
layer.open({
title: '编辑 - id:' + data.id,
type: 1,
area: ['80%', '80%'],
content: '<div style="padding: 16px;">自定义表单元素</div>'
});
createRoom(obj.data.live_room_id)
} else if (obj.event === 'more') {
// 更多 - 下拉菜单
dropdown.render({
@ -155,11 +130,18 @@
}],
click: function (menudata) {
if (menudata.id === 'detail') {
layer.msg('查看操作,当前行 ID:' + data.id);
layer.msg('查看操作,当前行 ID:' + data.live_room_id);
} else if (menudata.id === 'del') {
layer.confirm('真的删除行 [id: ' + data.id + '] 么', function (index) {
obj.del(); // 删除对应行tr的DOM结构
layer.close(index);
layer.confirm('真的删除行 [' + data.anchorName + '] 么', function (index) {
deleteRoomConfig(data.live_room_id)
.then(data => {
layer.msg(data.message)
if (data.status == 100) {
obj.del(); // 删除对应行tr的DOM结构
layer.close(index);
}
})
// 向服务端发送删除指令
});
}

View File

@ -1,39 +1,60 @@
<link rel="stylesheet" href="/layui/css/layui.css">
<head>
<link rel="stylesheet" href="/layui/css/layui.css">
<style>
.layui-form-label {
width: 120px !important;
}
</style>
</head>
<body>
<input id="value" value="" type="hidden" />
<form class="layui-form layui-form-pane" action="" style="padding-left: 10px;padding-right: 10px;">
<form class="layui-form layui-form-pane" action="" lay-filter="form-filter">
<div class="layui-form-item">
<label class="layui-form-label">直播房间地址</label>
<div class="layui-input-block">
<input type="text" name="url" autocomplete="off" placeholder="https://live.bilibili.com/xxxxx"
<div class="layui-input-inline" style="width: 60%;">
<input type="text" id="url" name="url" autocomplete="off" placeholder="https://live.bilibili.com/xxxxx"
lay-verify="required" class="layui-input">
</div>
</div>
<div class="layui-form-item" pane>
<label class="layui-form-label">录制弹幕</label>
<div class="layui-input-block">
<input type="checkbox" name="recordLive" lay-skin="switch" lay-filter="switchTest" title="启用|禁用">
<input type="checkbox" name="recordDanmu" lay-skin="switch" lay-filter="switchTest" title="启用|禁用">
</div>
</div>
<div class="layui-form-item" pane>
<label class="layui-form-label">录制视频</label>
<div class="layui-input-block">
<input type="checkbox" name="recordDanmu" lay-skin="switch" lay-filter="switchTest" title="启用|禁用">
<input type="checkbox" name="recordLive" lay-skin="switch" lay-filter="switchTest" title="启用|禁用">
</div>
</div>
<div class="layui-form-item" pane>
<label class="layui-form-label">录制日期</label>
<div class="layui-input-block">
<input type="checkbox" name="2" title="周一" lay-skin="tag">
<input type="checkbox" name="3" title="周二" lay-skin="tag">
<input type="checkbox" name="4" title="周三" lay-skin="tag">
<input type="checkbox" name="5" title="周四" lay-skin="tag">
<input type="checkbox" name="6" title="周五" lay-skin="tag">
<input type="checkbox" name="7" title="周六" lay-skin="tag">
<input type="checkbox" name="1" title="周日" lay-skin="tag">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">弹幕预定录制时间</label>
<label class="layui-form-label">弹幕录制时间</label>
<div class="layui-input-inline">
<input type="text" name="recordDanmuDate" value="* * *" placeholder="* * *" lay-verify="required" autocomplete="off" class="layui-input">
<input type="text" name="recordDanmuDate" id="recordDanmuDate" lay-verify="required" autocomplete="off"
class="layui-input">
</div>
<div class="layui-form-mid layui-text-em" onclick="timeTips(this)"><i
class="layui-icon layui-icon-help"></i> </div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">视频预定录制时间</label>
<label class="layui-form-label">视频录制时间</label>
<div class="layui-input-inline">
<input type="text" name="recordLiveDate" value="* * *" placeholder="* * *" lay-verify="required" autocomplete="off" class="layui-input">
<input type="text" name="recordLiveDate" id="recordLiveDate" lay-verify="required"
autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-text-em" onclick="timeTips(this)"><i
class="layui-icon layui-icon-help"></i> </div>
@ -47,7 +68,7 @@
</div>
<div class="layui-form-item">
<button class="layui-btn" lay-submit lay-filter="submit-form">确认</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
<button id="btn_reset" type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
@ -55,8 +76,8 @@
</body>
<script id="selectUser" type="text/html">
<select id="recordUid" name="recordUid" lay-verify="required" lay-search>
<option value="">直接选择或搜索选择</option>
<select id="recordUid" name="recordUid" lay-search>
<option value="">不登陆</option>
{{# layui.each(d.data, function(index, item){ }}
<option value="{{= item.uid}}">[{{=item.uid}}]{{= item.uname}}</option>
{{# }); }}
@ -66,41 +87,89 @@
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script src="/js/httpUtils.js"></script>
<script src="/js/CommonConfig.js"></script>
<script>
function timeTips(that) {
layer.tips('填写[分钟][小时][星期],空格分割,例如预定每周6晚上8点之后才开始录制则填写:* 8 6', that);
}
layui.use(['form', 'laytpl'], function () {
var roomId = getParam("roomId");
layui.use(['form', 'laytpl', 'laydate'], function () {
var form = layui.form;
var layer = layui.layer;
var laytpl = layui.laytpl
var laytpl = layui.laytpl;
var laydate = layui.laydate;
var windowsIndex;
form.render();
// 提交事件
form.on('submit(submit-form)', function (data) {
var field = data.field; // 获取表单字段值
windowsIndex = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
// 显示填写结果,仅作演示用
// 此处可执行 Ajax 等操作
// …
addRoomConfig(field)
.then(json=>{
console.log(json)
})
console.log(field)
// addRoomConfig(field)
// .then(json => {
// layer.msg(json.message, function () {
// if (json.status == 100) {
// close()
// }
// })
// })
return false; // 阻止默认 form 跳转
});
function close(){
var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
parent.layer.close(index);
function close() {
parent.layer.close(windowsIndex);
}
getBiliAllUser()
.then(data => {
var view = $("#selects").get(0);
laytpl($('#selectUser').get(0).innerHTML).render(data, function (html) {
view.innerHTML=html
form.render('select');
});
laydate.render({
elem: '#recordDanmuDate',
type: 'time',
range: true
});
laydate.render({
elem: '#recordLiveDate',
type: 'time',
range: true
});
function init() {
getUserInfo();
if (roomId !== null) {
$('#btn_reset').get(0).disabled = true;
editRoom()
}
}
function getUserInfo() {
getBiliAllUser()
.then(data => {
var view = $("#selects").get(0);
laytpl($('#selectUser').get(0).innerHTML).render(data, function (html) {
view.innerHTML = html
form.render('select');
});
})
});
}
function editRoom() {
getRoomConfig(roomId)
.then(data => {
if (data.status === 100) {
var json = data.data;
form.val('form-filter', {
'url': 'https://live.bilibili.com/' + json.live_room_id,
'recordLive': json.recordLive,
'recordDanmu': json.recordDanmu,
'recordDanmuDate': json.recordDanmuDate,
'recordLiveDate': json.recordLiveDate
});
$('#url').get(0).disabled = true;
}
})
}
init();
});
</script>

View File

@ -1,33 +1,141 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>DD监视器</title>
<link rel="stylesheet" href="/layui/css/layui.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>DD监视器</title>
<link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
<div id="header"></div>
<button id="btn" type="button" class="layui-btn" onclick="onButton()">默认按钮</button>
<div id="header"></div>
<button id="btn" type="button" class="layui-btn" onclick="onButton()">默认按钮</button>
<div class="layui-row layui-col-space15">
<div id="card"></div>
</div>
</body>
<script id="liveCard" type="text/html">
{{# layui.each(d.data, function(index, item){ }}
<div class="layui-col-xs3">
<div class="layui-bg-gray" style="padding: 16px;">
<div class="layui-row layui-col-space15">
<div class="layui-card">
<div class="layui-card-header" ><img src="#" onerror="showImage('{{= item.anchorFace}}',this)" style="width: 40px; height: 40px;"/> {{= item.anchorName}}
<span style="float: right;">直播状态:
{{# if(item.live){ }}
<span class="layui-badge-dot layui-bg-green"></span>
{{# } else{ }}
<span class="layui-badge-dot"></span>
{{# }; }}
</span>
</div>
<div class="layui-card-body">
<img src="#" onerror="showImage('{{= item.cover}}',this)" style="width: 100%; height: 100%;"/><br>
{{= item.title}}<br>
直播录制状态:
{{# if(item.downloadVideo){ }}
<span style="color: #16b777" onclick="clickVideo('{{= item.roomId}}',true)">录制中</span>
{{# } else{ }}
<span style="color: #FD482C" onclick="clickVideo('{{= item.roomId}}',false)">监听中</span>
{{# }; }}<br>
弹幕录制状态:
{{# if(item.danmu){ }}
<span style="color: #16b777" onclick="clickDanmu('{{= item.roomId}}',true)">录制中</span>
{{# } else{ }}
<span style="color: #FD482C" onclick="clickDanmu('{{= item.roomId}}',false)">监听中</span>
{{# }; }}<br>
</div>
</div>
</div>
</div>
</div>
{{# }); }}
</script>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script src="/js/CommonConfig.js"></script>
<script src="/js/httpUtils.js"></script>
<script>
headerModel=0;
$('#header').load("/html/header.html");
headerModel = 0;
$('#header').load("/html/header.html");
function clickVideo(roomId, status) {
const title = "是否" + (status ? "停止" : "启动") + "录制视频?"
layer.confirm(title, { icon: 3 }, function () {
if (status) {
stopLiveVideo(roomId)
.then(data => {
layer.msg(data.message, { icon: (data.status == 100 ? 1 : 0) },function(){
location.reload();
});
})
} else {
startLiveVideo(roomId)
.then(data => {
layer.msg(data.message, { icon: (data.status == 100 ? 1 : 0) },function(){
location.reload();
});
})
}
}, function () {
});
}
function clickDanmu(roomId, status) {
const title = "是否" + (status ? "停止" : "启动") + "录制弹幕?"
layer.confirm(title, { icon: 3 }, function () {
if (status) {
stopLiveDanmu(roomId)
.then(data => {
layer.msg(data.message, { icon: (data.status == 100 ? 1 : 0) },function(){
location.reload();
});
})
} else {
startLiveDanmu(roomId)
.then(data => {
layer.msg(data.message, { icon: (data.status == 100 ? 1 : 0) },function(){
location.reload();
});
})
}
}, function () {
layer.msg('点击取消的回调');
});
}
</script>
<script>
function onButton(){
getLiveVideoList()
.then(data=>{
layui.use(['laytpl'], function () {
var laytpl = layui.laytpl;
function initCard() {
getAllLive()
.then(data => {
console.log(data)
var view = $("#card").get(0);
laytpl($('#liveCard').get(0).innerHTML).render(data, function (html) {
view.innerHTML = html
});
})
}
}
function init() {
initCard()
}
init()
})
function onButton() {
}
</script>
<style>
</style>
</html>

View File

@ -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);
// 可以在这里设置一个默认图片或者显示错误信息
});
}

View File

@ -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)
}
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

View File

@ -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;
}
}

View File

@ -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")

View File

@ -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());

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<String> keywordList;
@JSONField(name = "week")
private List<String> 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;
}
}

View File

@ -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;

View File

@ -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")

View File

@ -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;

View File

@ -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));

View File

@ -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;
}
}

View File

@ -41,7 +41,7 @@ public class BiliLiveConfigDatabase extends SQLiteManager {
update(bean);
}
public LiveConfigDatabaseBean getConfig(BigInteger roomId) {
public LiveConfigDatabaseBean getConfig(String roomId) {
List<LiveConfigDatabaseBean> 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;

View File

@ -44,18 +44,18 @@ public class BiliLiveNetApiManager extends BaseApi {
return createApi(LiveApi.class);
}
public Map<BigInteger, LiveAnchorInfo> getAnchorInfos(String loginUid,List<BigInteger> anchorIds) {
public Map<String, LiveAnchorInfo> getAnchorInfos(String loginUid,List<BigInteger> 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<BigInteger, LiveAnchorInfo> map = new HashMap<>();
Map<String, LiveAnchorInfo> 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;
}

View File

@ -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");

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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+"";
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<File> 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()));
}

View File

@ -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<LiveData> getLiveList() {
List<LiveConfigDatabaseBean> allConfig = liveConfigDatabase.getAllConfig();
List<LiveData> 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;
}
}

View File

@ -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<String> 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<Runnable>(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<VideoFilePath> 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));
}

View File

@ -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();