Compare commits

...

2 Commits

Author SHA1 Message Date
526cf7e25f update 2024-10-31 18:28:19 +08:00
34a41f50ac update 2024-10-31 18:23:39 +08:00
31 changed files with 569 additions and 223 deletions

View File

@ -37,35 +37,15 @@
$('#header').load("/html/header.html"); $('#header').load("/html/header.html");
</script> </script>
<script> <script>
function showImage(url, imgElement) { function createRoom(roomId) {
getHttpImage(url)
.then(imageUrl => {
imgElement.src = imageUrl;
})
.catch(error => {
console.error("Error loading image:", error);
// 可以在这里设置一个默认图片或者显示错误信息
imgElement.src = 'default-image.jpg';
});
}
function createRoom() {
layer.open({ layer.open({
type: 2, type: 2,
title:"添加新房间", title: "添加新房间",
area: ['500px', '400px'], area: ['500px', '400px'],
content: '/html/ui/createConfig.html' content: '/html/ui/createConfig.html?roomId=' + roomId
});
// createUi("/html/ui/createConfig.html")
// .then(html => {
// layer.open({
// type: 1,
// area: ['500px', '300px'],
// content: '/html/ui/createConfig.html'
// });
// })
}
});
}
</script> </script>
<script> <script>
layui.use(['table', 'dropdown'], function () { layui.use(['table', 'dropdown'], function () {
@ -93,16 +73,16 @@
}, },
cols: [[ cols: [[
{ type: 'checkbox', fixed: 'left' }, { 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: '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: '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: 'recordPath', title: '保存路径', width: 120 },
{ field: 'recordDanmu', title: '录制弹幕', width: 120, sort: true }, { field: 'recordDanmu', title: '录制弹幕', width: 120, sort: true },
{ field: 'recordLive', title: '录制视频', width: 120, sort: true }, { field: 'recordLive', title: '录制视频', width: 120, sort: true },
{ field: 'recordDanmuDate', title: '弹幕录制预定时间', width: 170, sort: true }, { field: 'recordDanmuDate', title: '弹幕录制预定时间', width: 100, sort: true },
{ field: 'recordLiveDate', title: '视频录制预定时间', width: 170, sort: true }, { field: 'recordLiveDate', title: '视频录制预定时间', width: 100, sort: true },
{ field: 'recordUid', title: '录制账号', width: 120, 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: 'recordDanmu', title: '录制弹幕', width: 120, sort: true },
{ field: 'sql_time', title: '添加时间', width: 100 }, { field: 'sql_time', title: '添加时间', width: 100 },
{ fixed: "right", title: "操作", width: 190, align: "center", toolbar: "#toolDemo" } { fixed: "right", title: "操作", width: 190, align: "center", toolbar: "#toolDemo" }
@ -133,14 +113,9 @@
// 触发单元格工具事件 // 触发单元格工具事件
table.on('tool(roomTable)', function (obj) { // 双击 toolDouble table.on('tool(roomTable)', function (obj) { // 双击 toolDouble
var data = obj.data; // 获得当前行数据 var data = obj.data; // 获得当前行数据
// console.log(obj) console.log(obj)
if (obj.event === 'edit') { if (obj.event === 'edit') {
layer.open({ createRoom(obj.data.live_room_id)
title: '编辑 - id:' + data.id,
type: 1,
area: ['80%', '80%'],
content: '<div style="padding: 16px;">自定义表单元素</div>'
});
} else if (obj.event === 'more') { } else if (obj.event === 'more') {
// 更多 - 下拉菜单 // 更多 - 下拉菜单
dropdown.render({ dropdown.render({
@ -155,11 +130,18 @@
}], }],
click: function (menudata) { click: function (menudata) {
if (menudata.id === 'detail') { if (menudata.id === 'detail') {
layer.msg('查看操作,当前行 ID:' + data.id); layer.msg('查看操作,当前行 ID:' + data.live_room_id);
} else if (menudata.id === 'del') { } else if (menudata.id === 'del') {
layer.confirm('真的删除行 [id: ' + data.id + '] 么', function (index) { layer.confirm('真的删除行 [' + data.anchorName + '] 么', function (index) {
obj.del(); // 删除对应行tr的DOM结构 deleteRoomConfig(data.live_room_id)
layer.close(index); .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> <body>
<input id="value" value="" type="hidden" /> <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"> <div class="layui-form-item">
<label class="layui-form-label">直播房间地址</label> <label class="layui-form-label">直播房间地址</label>
<div class="layui-input-block"> <div class="layui-input-inline" style="width: 60%;">
<input type="text" name="url" autocomplete="off" placeholder="https://live.bilibili.com/xxxxx" <input type="text" id="url" name="url" autocomplete="off" placeholder="https://live.bilibili.com/xxxxx"
lay-verify="required" class="layui-input"> lay-verify="required" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item" pane> <div class="layui-form-item" pane>
<label class="layui-form-label">录制弹幕</label> <label class="layui-form-label">录制弹幕</label>
<div class="layui-input-block"> <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> </div>
<div class="layui-form-item" pane> <div class="layui-form-item" pane>
<label class="layui-form-label">录制视频</label> <label class="layui-form-label">录制视频</label>
<div class="layui-input-block"> <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> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">弹幕预定录制时间</label> <label class="layui-form-label">弹幕录制时间</label>
<div class="layui-input-inline"> <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>
<div class="layui-form-mid layui-text-em" onclick="timeTips(this)"><i <div class="layui-form-mid layui-text-em" onclick="timeTips(this)"><i
class="layui-icon layui-icon-help"></i> </div> class="layui-icon layui-icon-help"></i> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">视频预定录制时间</label> <label class="layui-form-label">视频录制时间</label>
<div class="layui-input-inline"> <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>
<div class="layui-form-mid layui-text-em" onclick="timeTips(this)"><i <div class="layui-form-mid layui-text-em" onclick="timeTips(this)"><i
class="layui-icon layui-icon-help"></i> </div> class="layui-icon layui-icon-help"></i> </div>
@ -47,7 +68,7 @@
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<button class="layui-btn" lay-submit lay-filter="submit-form">确认</button> <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> </div>
</form> </form>
@ -55,8 +76,8 @@
</body> </body>
<script id="selectUser" type="text/html"> <script id="selectUser" type="text/html">
<select id="recordUid" name="recordUid" lay-verify="required" lay-search> <select id="recordUid" name="recordUid" lay-search>
<option value="">直接选择或搜索选择</option> <option value="">不登陆</option>
{{# layui.each(d.data, function(index, item){ }} {{# layui.each(d.data, function(index, item){ }}
<option value="{{= item.uid}}">[{{=item.uid}}]{{= item.uname}}</option> <option value="{{= item.uid}}">[{{=item.uid}}]{{= item.uname}}</option>
{{# }); }} {{# }); }}
@ -66,41 +87,89 @@
<script src="/layui/layui.js"></script> <script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script> <script src="/js/jquery-3.2.1.js"></script>
<script src="/js/httpUtils.js"></script> <script src="/js/httpUtils.js"></script>
<script src="/js/CommonConfig.js"></script>
<script> <script>
function timeTips(that) { function timeTips(that) {
layer.tips('填写[分钟][小时][星期],空格分割,例如预定每周6晚上8点之后才开始录制则填写:* 8 6', 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 form = layui.form;
var layer = layui.layer; 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) { form.on('submit(submit-form)', function (data) {
var field = data.field; // 获取表单字段值 var field = data.field; // 获取表单字段值
windowsIndex = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
// 显示填写结果,仅作演示用 // 显示填写结果,仅作演示用
// 此处可执行 Ajax 等操作 // 此处可执行 Ajax 等操作
// … // …
addRoomConfig(field) console.log(field)
.then(json=>{ // addRoomConfig(field)
console.log(json) // .then(json => {
}) // layer.msg(json.message, function () {
// if (json.status == 100) {
// close()
// }
// })
// })
return false; // 阻止默认 form 跳转 return false; // 阻止默认 form 跳转
}); });
function close(){ function close() {
var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引 parent.layer.close(windowsIndex);
parent.layer.close(index);
} }
getBiliAllUser() laydate.render({
.then(data => { elem: '#recordDanmuDate',
var view = $("#selects").get(0); type: 'time',
laytpl($('#selectUser').get(0).innerHTML).render(data, function (html) { range: true
view.innerHTML=html });
form.render('select'); 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> </script>

View File

@ -1,33 +1,141 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-CN"> <html lang="zh-CN">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>DD监视器</title> <title>DD监视器</title>
<link rel="stylesheet" href="/layui/css/layui.css"> <link rel="stylesheet" href="/layui/css/layui.css">
</head> </head>
<body> <body>
<div id="header"></div> <div id="header"></div>
<button id="btn" type="button" class="layui-btn" onclick="onButton()">默认按钮</button> <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="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script> <script src="/js/jquery-3.2.1.js"></script>
<script src="/js/CommonConfig.js"></script> <script src="/js/CommonConfig.js"></script>
<script src="/js/httpUtils.js"></script> <script src="/js/httpUtils.js"></script>
<script> <script>
headerModel=0; headerModel = 0;
$('#header').load("/html/header.html"); $('#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>
<script> <script>
function onButton(){ layui.use(['laytpl'], function () {
getLiveVideoList() var laytpl = layui.laytpl;
.then(data=>{
function initCard() {
getAllLive()
.then(data => {
console.log(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> </script>
<style> <style>
</style> </style>
</html> </html>

View File

@ -6,4 +6,23 @@ function createUi(html){
.then(htmlText=>{ .then(htmlText=>{
return 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; // 重新抛出错误以便外部捕获 throw error; // 重新抛出错误以便外部捕获
}); });
} }
function getLiveVideoList() { function buildFormData(json){
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 = new FormData(); const formData = new FormData();
Object.keys(json).forEach(key => { Object.keys(json).forEach(key => {
@ -73,5 +56,56 @@ function addRoomConfig(json){
formData.append(key, value); 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; 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") @JSONField(name = "title")
private String title; private String title;
@JSONField(name = "room_id") @JSONField(name = "room_id")
private BigInteger roomId; private String roomId;
@JSONField(name = "uid") @JSONField(name = "uid")
private BigInteger uid; private String uid;
@JSONField(name = "online") @JSONField(name = "online")
private int online; private int online;
@JSONField(name = "live_time") @JSONField(name = "live_time")

View File

@ -11,7 +11,7 @@ import java.util.Objects;
@Data @Data
public class LiveRoomConfig { public class LiveRoomConfig {
String loginUid; String loginUid;
BigInteger roomId; String roomId;
String anchorName; String anchorName;
boolean isLogin; boolean isLogin;
String rootPath="live"; String rootPath="live";
@ -44,7 +44,7 @@ public class LiveRoomConfig {
public static LiveRoomConfig buildConfig(String roomId){ public static LiveRoomConfig buildConfig(String roomId){
BiliLiveConfigDatabase database = new BiliLiveConfigDatabase(); BiliLiveConfigDatabase database = new BiliLiveConfigDatabase();
LiveConfigDatabaseBean bean = database.getConfig(new BigInteger(roomId)); LiveConfigDatabaseBean bean = database.getConfig(new String(roomId));
LiveRoomConfig config = new LiveRoomConfig(); LiveRoomConfig config = new LiveRoomConfig();
config.setLoginUid(bean.getRecordUid()); config.setLoginUid(bean.getRecordUid());

View File

@ -9,10 +9,10 @@ import java.util.List;
@Data @Data
public class LiveRoomInfo { public class LiveRoomInfo {
@JSONField(name = "uid") @JSONField(name = "uid")
private BigInteger uid; private String uid;
@JSONField(name = "room_id") @JSONField(name = "room_id")
private BigInteger roomId; private String roomId;
@JSONField(name = "short_id") @JSONField(name = "short_id")
private int shortId; private int shortId;

View File

@ -12,13 +12,13 @@ import java.util.List;
@Data @Data
public class LiveRoomPlayInfo extends BaseBean { public class LiveRoomPlayInfo extends BaseBean {
@JSONField(name = "room_id") @JSONField(name = "room_id")
private BigInteger roomId; private String roomId;
@JSONField(name = "short_id") @JSONField(name = "short_id")
private int shortId; private int shortId;
@JSONField(name = "uid") @JSONField(name = "uid")
private BigInteger uid; private String uid;
@JSONField(name = "is_hidden") @JSONField(name = "is_hidden")
private boolean isHidden; private boolean isHidden;

View File

@ -29,7 +29,7 @@ public class LiveRoomStatus {
private int online; private int online;
@JSONField(name = "roomid") @JSONField(name = "roomid")
private BigInteger roomid; private String roomid;
@JSONField(name = "broadcast_type") @JSONField(name = "broadcast_type")
private int broadcastType; private int broadcastType;

View File

@ -41,7 +41,7 @@ public class MasterInfoBean extends BaseBean {
@Data @Data
public static class Info { public static class Info {
@JSONField(name = "uid") @JSONField(name = "uid")
private BigInteger uid; private String uid;
@JSONField(name = "uname") @JSONField(name = "uname")
private String uname; private String uname;

View File

@ -2,12 +2,18 @@ package com.yutou.biliapi.bean.live.database;
import com.alibaba.fastjson2.annotation.JSONField; import com.alibaba.fastjson2.annotation.JSONField;
import com.alibaba.fastjson2.util.DateUtils; import com.alibaba.fastjson2.util.DateUtils;
import com.yutou.bilibili.Tools.DateFormatUtils;
import com.yutou.common.databases.AbsDatabasesBean; import com.yutou.common.databases.AbsDatabasesBean;
import com.yutou.common.utils.Log;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.io.File; import java.io.File;
import java.math.BigInteger; import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -18,9 +24,9 @@ import static com.alibaba.fastjson2.util.DateUtils.DateTimeFormatPattern.DATE_FO
@Data @Data
public class LiveConfigDatabaseBean extends AbsDatabasesBean { public class LiveConfigDatabaseBean extends AbsDatabasesBean {
@JSONField(name = "live_room_id") @JSONField(name = "live_room_id")
private BigInteger roomId; private String roomId;
@JSONField(name = "anchorUid") @JSONField(name = "anchorUid")
private BigInteger anchorUid; private String anchorUid;
@JSONField(name = "anchorName") @JSONField(name = "anchorName")
private String anchorName; private String anchorName;
@JSONField(name = "anchorFace") @JSONField(name = "anchorFace")
@ -31,6 +37,8 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
private boolean isRecordDanmu; private boolean isRecordDanmu;
@JSONField(name = "keyword") @JSONField(name = "keyword")
private List<String> keywordList; private List<String> keywordList;
@JSONField(name = "week")
private List<String> weeks;
@JSONField(name = "recordPath") @JSONField(name = "recordPath")
private String recordPath = "live"; private String recordPath = "live";
@JSONField(name = "recordUid") @JSONField(name = "recordUid")
@ -38,9 +46,9 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
@JSONField(name = "recordLiveModel") @JSONField(name = "recordLiveModel")
private int recordLiveModel;//0 - ffmpeg 1 - java private int recordLiveModel;//0 - ffmpeg 1 - java
@JSONField(name = "recordDanmuDate") @JSONField(name = "recordDanmuDate")
private String recordDanmuDate = "* * *";// * * * 星期 | 周日是1 private String recordDanmuDate = null;// 时间范围 20:00:00 - 23:59:59
@JSONField(name = "recordLiveDate") @JSONField(name = "recordLiveDate")
private String recordLiveDate = "* * *";// * * * 星期 | 周日是1 private String recordLiveDate = null;// 时间范围 20:00:00 - 23:59:59
public LiveConfigDatabaseBean() { public LiveConfigDatabaseBean() {
@ -64,55 +72,49 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
} }
private boolean verifyTimer(String val) { 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];
try { try {
Integer.parseInt(minute); String[] time = val.split(" - ");
Integer.parseInt(hour); Date start = DateFormatUtils.parseTimer(time[0]);
Integer.parseInt(day); Date end = DateFormatUtils.parseTimer(time[1]);
if (start != null && end != null) {
return true;
}
} catch (Exception e) { } catch (Exception e) {
return false; Log.e(e);
} }
return true; return false;
} }
private boolean checkRecordTime(String recordDate) { private boolean checkRecordTime(String recordDate) {
int _length = recordDate.length(); //TODO 待测试
boolean isFullDate = (_length - recordDate.replace("*", "").length()) == 3; String[] parts = recordDate.split(" - ");
if (isFullDate) { LocalTime startTime = LocalTime.parse(parts[0], DateTimeFormatter.ofPattern("HH:mm:ss"));
return true; LocalTime endTime = LocalTime.parse(parts[1], DateTimeFormatter.ofPattern("HH:mm:ss"));
}
String[] split = recordDate.split(" ");
String minute = split[0]; // 获取当前时间
String hour = split[1]; LocalTime currentTime = LocalTime.now();
String day = split[2]; LocalDate currentDate = LocalDate.now();
boolean isFullMinute = "*".equals(minute);
boolean isFullHour = "*".equals(hour);
boolean isFullDay = "*".equals(day); // 获取当前日期对应的星期几1-7分别对应周一到周日
Calendar today = Calendar.getInstance(); int currentWeekDay = currentDate.getDayOfWeek().getValue();
if (!isFullDay) {
if (today.get(Calendar.DAY_OF_WEEK) != Integer.parseInt(day) + 1) { // 判断当前日期是否在指定的星期列表中
return false; boolean isSpecifiedWeekDay = weeks.contains(String.valueOf(currentWeekDay));
}
}
if (!isFullHour) { // 判断当前时间是否在指定的时间范围内
if (today.get(Calendar.HOUR_OF_DAY) != Integer.parseInt(hour)) { boolean isWithinRange = (currentTime.isAfter(startTime) || currentTime.equals(startTime)) &&
return false; (currentTime.isBefore(endTime) || currentTime.equals(endTime));
} return isWithinRange && isSpecifiedWeekDay;
} }
if (!isFullMinute) {
if (today.get(Calendar.MINUTE) != Integer.parseInt(minute)) { public static void main(String[] args) {
return false; String t = "18:00:00 - 23:59:59";
} List<String> weeks = Arrays.asList("1", "2", "3", "9", "5", "6", "7");
} LiveConfigDatabaseBean bean=new LiveConfigDatabaseBean();
return true; bean.setWeeks(weeks);
System.out.println(bean.checkRecordTime(t));
} }
} }

View File

@ -25,7 +25,7 @@ public class LiveDanmuDatabaseBean extends AbsDatabasesBean {
@JSONField(name = "time") @JSONField(name = "time")
private long time; private long time;
@JSONField(name = "uid") @JSONField(name = "uid")
private BigInteger uid; private String uid;
@JSONField(name = "uname") @JSONField(name = "uname")
private String uname; private String uname;

View File

@ -18,9 +18,9 @@ public class LiveInfoDatabaseBean extends AbsDatabasesBean {
@JSONField(name = "id") @JSONField(name = "id")
int id; int id;
@JSONField(name = "roomId") @JSONField(name = "roomId")
private BigInteger roomId; private String roomId;
@JSONField(name = "anchorUid") @JSONField(name = "anchorUid")
private BigInteger anchorUid; private String anchorUid;
@JSONField(name = "title") @JSONField(name = "title")
private String title; private String title;
@JSONField(name = "record_time_start") @JSONField(name = "record_time_start")

View File

@ -32,7 +32,7 @@ public class UserInfoBean extends BaseBean {
private LevelInfo levelInfo; private LevelInfo levelInfo;
@JSONField(name = "mid") @JSONField(name = "mid")
private BigInteger mid; private String mid;
@JSONField(name = "mobile_verified") @JSONField(name = "mobile_verified")
private int mobileVerified; private int mobileVerified;

View File

@ -23,7 +23,7 @@ public class WSDanmuData extends WSData {
private long time; private long time;
private String uCode; private String uCode;
private String danmu; private String danmu;
private BigInteger uid; private String uid;
private String uname; private String uname;
private WSUserMedal medal; private WSUserMedal medal;
@ -36,7 +36,7 @@ public class WSDanmuData extends WSData {
setTime(infoData.getJSONArray(0).getLong(4)); setTime(infoData.getJSONArray(0).getLong(4));
setUCode(infoData.getJSONArray(0).getString(7)); setUCode(infoData.getJSONArray(0).getString(7));
setDanmu(infoData.getString(1)); setDanmu(infoData.getString(1));
setUid(infoData.getJSONArray(2).getBigInteger(0)); setUid(infoData.getJSONArray(2).getFirst().toString());
setUname(infoData.getJSONArray(2).getString(1)); setUname(infoData.getJSONArray(2).getString(1));
try { try {
medal = WSUserMedal.create(infoData.getJSONArray(3)); medal = WSUserMedal.create(infoData.getJSONArray(3));

View File

@ -61,7 +61,7 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
return list.getFirst(); return list.getFirst();
} }
for (LoginUserDatabaseBean bean : list) { for (LoginUserDatabaseBean bean : list) {
if (bean.getUserInfo().getMid().equals(new BigInteger(userId))) { if (bean.getUserInfo().getMid().equals(new String(userId))) {
return bean; return bean;
} }
} }

View File

@ -41,7 +41,7 @@ public class BiliLiveConfigDatabase extends SQLiteManager {
update(bean); update(bean);
} }
public LiveConfigDatabaseBean getConfig(BigInteger roomId) { public LiveConfigDatabaseBean getConfig(String roomId) {
List<LiveConfigDatabaseBean> list = get(getDataBean().get(0).getTableName(), LiveConfigDatabaseBean.class); List<LiveConfigDatabaseBean> list = get(getDataBean().get(0).getTableName(), LiveConfigDatabaseBean.class);
if (list.isEmpty()) { if (list.isEmpty()) {
return null; return null;
@ -54,7 +54,7 @@ public class BiliLiveConfigDatabase extends SQLiteManager {
return null; return null;
} }
public boolean deleteConfig(BigInteger roomId) { public boolean deleteConfig(String roomId) {
LiveConfigDatabaseBean config = getConfig(roomId); LiveConfigDatabaseBean config = getConfig(roomId);
if (config == null) { if (config == null) {
return false; return false;

View File

@ -44,18 +44,18 @@ public class BiliLiveNetApiManager extends BaseApi {
return createApi(LiveApi.class); 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(); JSONObject json = new JSONObject();
json.put("uids", anchorIds); json.put("uids", anchorIds);
try { try {
String src = getApi(loginUid).getLiveRoomStatus(json).execute().body().getSrc(); String src = getApi(loginUid).getLiveRoomStatus(json).execute().body().getSrc();
json = JSONObject.parseObject(src); json = JSONObject.parseObject(src);
if (json.getInteger("code") == 0) { if (json.getInteger("code") == 0) {
Map<BigInteger, LiveAnchorInfo> map = new HashMap<>(); Map<String, LiveAnchorInfo> map = new HashMap<>();
JSONObject data = json.getJSONObject("data"); JSONObject data = json.getJSONObject("data");
for (String key : data.keySet()) { for (String key : data.keySet()) {
LiveAnchorInfo info = JSONObject.parseObject(data.getString(key), LiveAnchorInfo.class); LiveAnchorInfo info = JSONObject.parseObject(data.getString(key), LiveAnchorInfo.class);
map.put(new BigInteger(key), info); map.put(key, info);
} }
return map; return map;
} }

View File

@ -85,7 +85,7 @@ public class WebSocketManager {
public void stopRoom(String roomId, boolean isUser) { public void stopRoom(String roomId, boolean isUser) {
LiveRoomConfig roomConfig = new LiveRoomConfig(); LiveRoomConfig roomConfig = new LiveRoomConfig();
roomConfig.setRoomId(new BigInteger(roomId)); roomConfig.setRoomId(new String(roomId));
if (checkRoom(roomConfig)) { if (checkRoom(roomConfig)) {
roomMap.get(roomConfig).close(); roomMap.get(roomConfig).close();
roomMap.remove(roomConfig); roomMap.remove(roomConfig);
@ -278,7 +278,7 @@ public class WebSocketManager {
String buvid = BiliUserUtils.getBuvid(BiliBiliLoginDatabase.getInstance().getCookie(roomConfig.getLoginUid())); String buvid = BiliUserUtils.getBuvid(BiliBiliLoginDatabase.getInstance().getCookie(roomConfig.getLoginUid()));
if (buvid != null) { if (buvid != null) {
try { try {
json.put("roomid", roomConfig.getRoomId()); json.put("roomid", new BigInteger(roomConfig.getRoomId()));
json.put("protover", 3); json.put("protover", 3);
json.put("buvid", buvid); json.put("buvid", buvid);
json.put("platform", "web"); json.put("platform", "web");

View File

@ -56,7 +56,7 @@ public class LiveConfigController {
return ResultData.fail(ReturnCode.RC999.getCode(),"弹幕录制时间格式错误"); 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) { if (config != null) {
return ResultData.success(config.toJson()); return ResultData.success(config.toJson());
} }
@ -69,7 +69,7 @@ public class LiveConfigController {
if ("0".equals(roomId) || !StringUtils.hasText(roomId)) { if ("0".equals(roomId) || !StringUtils.hasText(roomId)) {
return ResultData.fail(ReturnCode.RC999); return ResultData.fail(ReturnCode.RC999);
} }
LiveConfigDatabaseBean config = configService.getConfig(new BigInteger(roomId)); LiveConfigDatabaseBean config = configService.getConfig(new String(roomId));
if (config != null) { if (config != null) {
return ResultData.success(config.toJson()); return ResultData.success(config.toJson());
} }
@ -88,8 +88,8 @@ public class LiveConfigController {
@RequestMapping(value = "delete", method = RequestMethod.GET) @RequestMapping(value = "delete", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public JSONObject deleteConfig(BigInteger roomId) { public JSONObject deleteConfig(String roomId) {
if (roomId.equals(BigInteger.ZERO)) { if ("0".equals(roomId)|| !StringUtils.hasText(roomId)) {
return ResultData.fail(ReturnCode.RC999); return ResultData.fail(ReturnCode.RC999);
} }
boolean flag = configService.deleteConfig(roomId); 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; package com.yutou.bilibili.Controllers;
import com.yutou.common.okhttp.HttpLoggingInterceptor;
import com.yutou.common.utils.FFmpegUtils; import com.yutou.common.utils.FFmpegUtils;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -12,4 +13,10 @@ public class TestControllers {
public String test(){ public String test(){
return "hello world"; 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; package com.yutou.bilibili.Tools;
import com.yutou.common.utils.Log;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
public class DateFormatUtils { 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); 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)); 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)); 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); 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()); 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)) { if (!StringUtils.hasText(roomId)) {
return null; return null;
} }
bean.setRoomId(new BigInteger(roomId)); bean.setRoomId(new String(roomId));
try { try {
LiveRoomInfo body = BiliLiveNetApiManager.getInstance().getApi(null).getRoomInfo(String.valueOf(bean.getRoomId())).execute().body().getData(); 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(); 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.setAnchorFace(infoBean.getInfo().getFace());
bean.setAnchorName(infoBean.getInfo().getUname()); bean.setAnchorName(infoBean.getInfo().getUname());
database.setConfig(bean); database.setConfig(bean);
downloadFace(bean);
return bean; return bean;
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public LiveConfigDatabaseBean updateConfig(BigInteger roomId, LiveConfigDatabaseBean bean) { public LiveConfigDatabaseBean updateConfig(String roomId, LiveConfigDatabaseBean bean) {
LiveConfigDatabaseBean config = database.getConfig(roomId); LiveConfigDatabaseBean config = database.getConfig(roomId);
if (config == null) { if (config == null) {
return null; return null;
@ -51,11 +50,10 @@ public class LiveConfigService {
bean.setRoomId(roomId); bean.setRoomId(roomId);
bean.setSql_time(config.getSql_time()); bean.setSql_time(config.getSql_time());
database.setConfig(bean); database.setConfig(bean);
downloadFace(bean);
return bean; return bean;
} }
public boolean deleteConfig(BigInteger roomId) { public boolean deleteConfig(String roomId) {
LiveConfigDatabaseBean config = database.getConfig(roomId); LiveConfigDatabaseBean config = database.getConfig(roomId);
if (config == null) { if (config == null) {
return false; return false;
@ -68,32 +66,23 @@ public class LiveConfigService {
return database.getAllConfig(); return database.getAllConfig();
} }
public LiveConfigDatabaseBean getConfig(BigInteger roomId) { public LiveConfigDatabaseBean getConfig(String roomId) {
return database.getConfig(roomId); return database.getConfig(roomId);
} }
public File getFace(String roomId) { public File getFace(String roomId) {
LiveConfigDatabaseBean config = database.getConfig(new BigInteger(roomId)); LiveConfigDatabaseBean config = database.getConfig(new String(roomId));
if (config == null) { if (config == null) {
return null; return null;
} }
return new File(config.getRecordPath() + File.separator + config.getAnchorName() + File.separator + config.getAnchorFace()); 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) { public boolean checkUrl(String url) {
if (!url.startsWith("https://live.bilibili.com/")) { if (!url.startsWith("https://live.bilibili.com/")) {
try { try {
new BigInteger(url); new String(url);
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }

View File

@ -25,6 +25,11 @@ public class LiveDanmuService {
public void start(String roomId,boolean isUser) { public void start(String roomId,boolean isUser) {
WebSocketManager.getInstance().addRoom(LiveRoomConfig.buildConfig(roomId), 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) { public void stop(String roomId,boolean isUser) {
WebSocketManager.getInstance().stopRoom(roomId, isUser); WebSocketManager.getInstance().stopRoom(roomId, isUser);
@ -37,7 +42,7 @@ public class LiveDanmuService {
public List<File> getDanmuFileList(String roomId) { public List<File> getDanmuFileList(String roomId) {
BiliLiveConfigDatabase configDatabase=new BiliLiveConfigDatabase(); BiliLiveConfigDatabase configDatabase=new BiliLiveConfigDatabase();
LiveConfigDatabaseBean bean = configDatabase.getConfig(new BigInteger(roomId)); LiveConfigDatabaseBean bean = configDatabase.getConfig(new String(roomId));
configDatabase.close(); configDatabase.close();
return Tools.scanFile(new File(bean.getRecordPath() + File.separator + bean.getAnchorName())); 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 @Service
public class LiveVideoService { public class LiveVideoService {
ThreadPoolExecutor executor; private final ThreadPoolExecutor executor;
private final List<String> userStopList = new ArrayList<>();//手动停止列表 private final List<String> userStopList = new ArrayList<>();//手动停止列表
AbsVideoRecord videoRecord; private final AbsVideoRecord videoRecord;
public LiveVideoService() { public LiveVideoService() {
Log.i("初始化下载服务"); Log.i("初始化下载服务");
videoRecord=new FFmpegUtils(); videoRecord = new FFmpegUtils();
executor = new ThreadPoolExecutor(2, 4, Long.MAX_VALUE, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100)); 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) { public void start(LiveConfigDatabaseBean bean, boolean isUser) {
if (!isUser && userStopList.contains(bean.getRoomId().toString())) { if (!isUser && userStopList.contains(bean.getRoomId().toString())) {
return; return;
@ -240,15 +244,17 @@ public class LiveVideoService {
cookie = ck.toCookieString(); cookie = ck.toCookieString();
} }
FFmpegUtils command = new FFmpegUtils.Builder() FFmpegUtils.Builder builder = new FFmpegUtils.Builder()
.withParam("-user_agent", ConfigTools.getUserAgent()) .withParam("-user_agent", ConfigTools.getUserAgent())
.withParam("-cookies", cookie)
.withParam("-headers", "Referer: https://live.bilibili.com") .withParam("-headers", "Referer: https://live.bilibili.com")
// .withNotSymbolParam("-progress", "-") // .withNotSymbolParam("-progress", "-")
.withNotSymbolParam("-threads", "8") .withNotSymbolParam("-threads", "8")
.withNotSymbolParam("-c:v", "copy") .withNotSymbolParam("-c:v", "copy")
.withNotSymbolParam("-y", "") .withNotSymbolParam("-y", "");
.build(config.getRoomId().toString(), ffmpegPath, url, savePath); if (ck != null) {
builder = builder.withParam("-cookies", cookie);
}
FFmpegUtils command = builder.build(config.getRoomId(), ffmpegPath, url, savePath);
Log.i(command.getCommand()); Log.i(command.getCommand());
try { try {
command.start(new DownloadInterface() { command.start(new DownloadInterface() {
@ -306,7 +312,7 @@ public class LiveVideoService {
public List<VideoFilePath> getVideoPath(String roomId) { public List<VideoFilePath> getVideoPath(String roomId) {
BiliLiveConfigDatabase configDatabase = new BiliLiveConfigDatabase(); BiliLiveConfigDatabase configDatabase = new BiliLiveConfigDatabase();
LiveConfigDatabaseBean bean = configDatabase.getConfig(new BigInteger(roomId)); LiveConfigDatabaseBean bean = configDatabase.getConfig(new String(roomId));
configDatabase.close(); configDatabase.close();
return new ArrayList<>(getVideoFilePath(bean)); return new ArrayList<>(getVideoFilePath(bean));
} }

View File

@ -54,7 +54,7 @@ public abstract class SQLiteManager {
type = BuildSqlItem.TYPE_BOOLEAN; type = BuildSqlItem.TYPE_BOOLEAN;
} else if (field.getType() == ISqlDatabaseBean.class) { } else if (field.getType() == ISqlDatabaseBean.class) {
type = BuildSqlItem.TYPE_TEXT; type = BuildSqlItem.TYPE_TEXT;
} else if (field.getType() == BigInteger.class) { } else if (field.getType() == String.class) {
type = BuildSqlItem.TYPE_INT; type = BuildSqlItem.TYPE_INT;
} }
items.add(BuildSqlItem.create().setName(name).setType(type).setNull(!"id".equals(name)).setKey("id".equals(name))); 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)); statement.setInt(i++, json.getInteger(key));
} else if (json.get(key) instanceof Long) { } else if (json.get(key) instanceof Long) {
statement.setLong(i++, json.getLong(key)); 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)); statement.setObject(i++, json.get(key));
} else if (json.get(key) instanceof Boolean) { } else if (json.get(key) instanceof Boolean) {
statement.setBoolean(i++, json.getBoolean(key)); statement.setBoolean(i++, json.getBoolean(key));
@ -353,7 +353,7 @@ public abstract class SQLiteManager {
public static void main(String[] args) { public static void main(String[] args) {
LiveConfigDatabaseBean bean = new LiveConfigDatabaseBean(); LiveConfigDatabaseBean bean = new LiveConfigDatabaseBean();
bean.setRoomId(new BigInteger("123")); bean.setRoomId(new String("123"));
bean.setRecordLive(true); bean.setRecordLive(true);
bean.setKeywordList(List.of("111", "22")); bean.setKeywordList(List.of("111", "22"));
JSONObject json = bean.toJson(); JSONObject json = bean.toJson();