Compare commits

...

5 Commits

Author SHA1 Message Date
903ba44bbb 调整UI 2024-11-27 18:17:14 +08:00
38854993d0 完善批量设置 2024-11-27 18:06:15 +08:00
ad84c71a30 更新layui到v2.9.20 2024-11-27 17:40:14 +08:00
e8cceef419 完善web一些功能 2024-11-27 17:39:02 +08:00
48a15c8769 完善切片存储 2024-11-27 17:38:45 +08:00
23 changed files with 715 additions and 209 deletions

View File

@ -15,7 +15,9 @@
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" onclick="createRoom()">添加新房间</button>
<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
<button class="layui-btn layui-btn-sm" lay-event="editArray">批量编辑</button>
<button class="layui-btn layui-btn-sm" lay-event="deleteArray">批量删除</button>
<button class="layui-btn layui-btn-sm layui-bg-red" lay-event="deleteAll">全部删除</button>
</div>
</script>
<script type="text/html" id="toolDemo">
@ -46,6 +48,15 @@
});
}
function editArrayRoom(array) {
layer.open({
type: 2,
title: "批量编辑",
area: ['600px', '500px'],
content: '/html/ui/createConfig.html?array=' + array
});
}
</script>
<script>
layui.use(['table', 'dropdown'], function () {
@ -105,10 +116,56 @@
var id = obj.config.id;
var checkStatus = table.checkStatus(id);
var othis = lay(this);
var data = checkStatus.data;
var array = data.map(function (item) {
return item.live_room_id
})
var arrayName = data.map(function (item) {
return item.anchorName
})
switch (obj.event) {
case 'getCheckData':
var data = checkStatus.data;
layer.alert(layui.util.escape(JSON.stringify(data)));
case 'deleteArray':
if (array.length === 0) {
layer.msg('没有数据', { icon: 2 })
return
}
layer.confirm('确定删除 ' + arrayName + "?", { icon: 3 }, function () {
var loadIndex = showLoadingDialog();
deleteArrayRoomConfig(array)
.then(json => {
layer.close(loadIndex)
layer.msg(json.data, { icon: 1 });
table.reloadData('roomList', {}, false)
})
}, function () {
});
break;
case 'editArray':
if (array.length === 0) {
layer.msg('没有数据', { icon: 2 })
return
}
editArrayRoom(array)
break;
case 'deleteAll':
layer.confirm('确定删除所有配置?', { icon: 3 }, function () {
var loadIndex = showLoadingDialog();
deleteAllRoomConfig()
.then(json => {
layer.close(loadIndex)
if (json.status === -1) {
layer.msg(json.message, { icon: 2 });
} else {
layer.msg(json.data, { icon: 1 });
}
table.reloadData('roomList', {}, false)
})
}, function () {
});
break;
};
});

View File

@ -24,7 +24,11 @@
<script type="text/html" id="toolDemo">
<div class="layui-clear-space">
<a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
<a class="layui-btn layui-btn-xs" lay-event="input">导入关注</a>
<!-- <a class="layui-btn layui-btn-xs" lay-event="input">导入关注</a> -->
<a class="layui-btn layui-btn-xs" lay-event="more">
导入
<i class="layui-icon layui-icon-down"></i>
</a>
</div>
</script>
<script>
@ -143,8 +147,28 @@
var checkStatus = table.checkStatus(id);
var othis = lay(this);
switch (obj.event) {
case 'input':
onClickInput(data.uid)
case 'more':
dropdown.render({
elem: this, // 触发事件的 DOM 对象
show: true, // 外部事件触发即显示
data: [{
title: '关注列表',
id: 'follow'
}, {
title: '正在开播',
id: 'live'
}],
click: function (menudata) {
if (menudata.id === 'follow') {
onClickInput(data.uid)
} else if (menudata.id === 'live') {
onClickFollow(data.uid)
}
},
align: 'right', // 右对齐弹出
style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' // 设置额外样式
})
break;
};
});
@ -172,10 +196,33 @@
window.location.href = url.toString();
}
});
}
function onClickFollow(uid) {
layer.open({
type: 2, // page 层类型
area: ['650px', '400px'],
title: '选择主播',
shade: 0.6, // 遮罩透明度
shadeClose: false, // 点击遮罩区域,关闭弹层
maxmin: true, // 允许全屏最小化
anim: 1, // 0-6 的动画形式,-1 不开启
// btn: ['确定', '取消'],
content: '/html/ui/userFollowLive.html?uid=' + uid,
yes: function (index, layero) {
var iframeWin = window[layero.find('iframe')[0]['name']];
var anchorRoomId = iframeWin.$('#anchorRoomId')[0].value;
if (!hasString(anchorRoomId)) {
layer.msg("请选择")
return
}
let url = new URL(window.location.href);
url.searchParams.set('roomId', anchorRoomId);
window.location.href = url.toString();
}
});
}
});
</script>

View File

@ -42,15 +42,18 @@
<input type="checkbox" id="danmuCheckBox" title="弹幕" lay-skin="tag" lay-filter="danmuCheckBox" on checked>
</div>
<div class="layui-col-xs5" style="text-align: center;">
<div class="layui-col-xs4" style="text-align: center;">
&nbsp; <div id="slider" lay-options="{value: 100,input:true}"></div>
<span>弹幕透明度</span>
</div>
<div class="layui-col-xs2" style="text-align: right; align-self: center;">
弹幕装载数:<span id="danmuSize">你猜</span>
</div>
</div>
<div class="layui-row">
<div class="layui-col-xs2">&nbsp;</div>
<div class="layui-col-xs7">
<canvas id="giftChart" height="200"></canvas>
<div class="layui-col-xs7" style="width: auto; height: 50%;">
<canvas id="giftChart" style="width: 100%; height: 100%;"></canvas>
</div>
</div>
<div style="margin-bottom: 10vh;"></div>
@ -232,6 +235,7 @@
initChart(roomId, options.id)
});
var chartView = null;
function initChart(roomId, videoId) {
getVideoGiftInfo(roomId, videoId)
.then(data => {
@ -241,20 +245,22 @@
var lables = [];
var values = [];
data.data.guardInfo.forEach(item => {
lables.push(item.gift_name+"\n"+item.total_price/100+"¥")
lables.push(item.gift_name + "\n" + item.total_price / 100 + "¥")
values.push(item.total_num)
});
data.data.giftInfo.forEach(item => {
lables.push(item.gift_name+"\n"+item.total_price/100+"¥")
lables.push(item.gift_name + "\n" + item.total_price / 100 + "¥")
values.push(item.total_gift_num)
});
new Chart($('#giftChart').get(0), {
if(chartView!==null){
chartView.destroy()
}
chartView = new Chart($('#giftChart').get(0), {
type: 'pie',
data: {
labels: lables,
datasets: [{
label: '礼物(总额:'+data.data.price/100+"¥)",
label: '礼物(总额:' + data.data.price / 100 + "¥)",
data: values,
borderWidth: 1
}
@ -313,7 +319,8 @@
}
function playVideo(url) {
var video = document.getElementById('videoElement');
var videoSrc = url;
var videoSrc = window.location.origin + url;
console.log('url = ' + videoSrc)
var hls = new Hls();
hls.loadSource(videoSrc);
hls.attachMedia(video);
@ -328,6 +335,7 @@
getDanmu(getParam('roomId'), videoId)
.then(data => {
barrageRenderer.setBarrages(data.data.danmu);
$('#danmuSize').get(0).innerHTML = data.data.danmu.length
initSC(data.data.superChat)
})

View File

@ -32,13 +32,13 @@
<div class="layui-form-item" pane>
<label class="layui-form-label">录制日期</label>
<div class="layui-input-block">
<input type="checkbox" checked name="week_1" title="周一" lay-skin="tag">
<input type="checkbox" checked name="week_2" title="周二" lay-skin="tag">
<input type="checkbox" checked name="week_3" title="周三" lay-skin="tag">
<input type="checkbox" checked name="week_4" title="周四" lay-skin="tag">
<input type="checkbox" checked name="week_5" title="周五" lay-skin="tag">
<input type="checkbox" checked name="week_6" title="周六" lay-skin="tag">
<input type="checkbox" checked name="week_7" title="周日" lay-skin="tag">
<input type="checkbox" name="week_1" title="周一" lay-skin="tag">
<input type="checkbox" name="week_2" title="周二" lay-skin="tag">
<input type="checkbox" name="week_3" title="周三" lay-skin="tag">
<input type="checkbox" name="week_4" title="周四" lay-skin="tag">
<input type="checkbox" name="week_5" title="周五" lay-skin="tag">
<input type="checkbox" name="week_6" title="周六" lay-skin="tag">
<input type="checkbox" name="week_7" title="周日" lay-skin="tag">
</div>
</div>
<div class="layui-form-item">
@ -89,15 +89,16 @@
<script src="/js/httpUtils.js"></script>
<script src="/js/CommonConfig.js"></script>
<script>
function timeTips(isLive,that) {
if(isLive){
function timeTips(isLive, that) {
if (isLive) {
layer.tips('是从开始到结束时间范围内,主播开播会启动录制,超过结束范围不会中断正在录制的任务', that);
}else{
} else {
layer.tips('仅在当前时间范围内录制,如遇到正在直播,则延迟到下播时停止录制', that);
}
}
var roomId = getParam("roomId");
var editArray = getParam("array")
layui.use(['form', 'laytpl', 'laydate'], function () {
var form = layui.form;
@ -123,15 +124,35 @@
}
field.weeks = weeks;
console.log(field)
addRoomConfig(field)
.then(json => {
layer.msg(json.message, function () {
if (json.status == 100) {
close()
}
})
if (editArray === null) {
var loadIndex=showLoadingDialog();
addRoomConfig(field)
.then(json => {
layer.close(loadIndex)
layer.msg(json.message, function () {
if (json.status == 100) {
close()
}
})
})
} else {
var array = []
editArray.split(',').forEach(element => {
array.push(element)
});
var loadIndex=showLoadingDialog();
setArrayRoomConfig(array, field)
.then(json => {
layer.close(loadIndex)
layer.msg(json.message, function () {
if (json.status == 100) {
close()
}
})
})
}
})
return false; // 阻止默认 form 跳转
});
@ -155,6 +176,9 @@
$('#btn_reset').get(0).disabled = true;
editRoom()
}
if (editArray !== null) {
editArrayRoom()
}
}
function getUserInfo() {
getBiliAllUser()
@ -183,12 +207,20 @@
for (let i = 0; i < json.weeks.length; i++) {
result[`week_${json.weeks[i]}`] = true;
}
form.val('form-filter',result);
form.val('form-filter', result);
$('#url').get(0).disabled = true;
}
})
}
function editArrayRoom() {
$('#btn_reset').get(0).disabled = true;
$('#url').get(0).disabled = true;
var result = {
'url': editArray
};
form.val('form-filter', result);
}
init();
});
</script>

View File

@ -46,7 +46,7 @@
elem: '#followList',
url: '/live/config/follow?userId=' + userId,
toolbar: '#toolbarDemo',
height: '350px',
height: 'full',
totalRow: true, // 开启合计行
page: true,
response: {

View File

@ -0,0 +1,132 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/layui/css/layui.css">
</head>
<table class="layui-hide" id="followList" lay-filter="followTable"></table>
<body>
</body>
<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 type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="select">配置选择项</button>
</div>
</script>
<script type="text/html" id="toolDemo">
<div class="layui-clear-space">
<a class="layui-btn layui-btn-xs" lay-event="add">添加</a>
</div>
</script>
<script>
var userId = getParam("uid");
layui.use(function () {
var laytpl = layui.laytpl;
var table = layui.table;
table.render({
elem: '#followList',
url: '/live/config/followLive?userId=' + userId,
toolbar: '#toolbarDemo',
height: 'full',
totalRow: false, // 开启合计行
page: false,
response: {
statusCode: 100 // 重新规定成功的状态码为 200table 组件默认为 0
},
parseData: function (res) {
return {
"code": res.status, //解析接口状态
"msg": res.message, //解析提示文本
"data": res.data, //解析数据列表
"count": res.count
};
},
cols: [[
{ type: 'checkbox', fixed: 'left' },
{ field: 'uname', title: '用户名', width: 150, fixed: 'left' },
{ field: 'uid', title: 'UID', width: 150, sort: true, templet: '<div><a href="https://space.bilibili.com/{{= d.uid}}" target="_blank">{{= d.uid}}</a>' },
{ field: 'room_id', title: '房间号', width: 150, sort: true, templet: '<div><a href="https://live.bilibili.com/{{= d.room_id}}" target="_blank">{{= d.room_id}}</a>' },
{ field: 'face', title: '头像', width: 80, templet: '<div><image src="" onerror="showImage(\'{{= d.face }}\',this);" style="width: 30px;height: 30px;"></div>' },
{ field: 'title', title: '标题', width: 150, },
{ fixed: "right", title: "操作", width: 50, align: "center", toolbar: "#toolDemo" }
]],
done: function () {
onDone()
},
error: function (res, msg) {
console.log(res, msg)
}
});
function onDone() {
table.on('toolbar(followTable)', function (obj) {
if (obj.event === 'select') {
var data = table.checkStatus(obj.config.id).data;
console.log(data)
var array = []
data.forEach(item => {
array.push({
"roomId": item.room_id,
"uname": item.uname
})
});
var loadIndex = layer.msg('配置中', {
icon: 16,
shade: 0.6
});
addFollowRoomList(JSON.stringify(array))
.then(json => {
layer.close(loadIndex)
layer.msg("已成功配置" + json.count + "个房间")
})
}
})
table.on('tool(followTable)', function (obj) {
if (obj.event === 'add') {
var loadIndex = layer.msg('配置中', {
icon: 16,
shade: 0.6
});
var array = []
array.push({
"roomId": obj.data.room_id,
"uname": obj.data.uname
})
addFollowRoomList(JSON.stringify(array))
.then(data => {
layer.close(loadIndex)
layer.msg("已成功配置" + data.count + "个房间")
})
}
})
}
function openTips(message, mid) {
layer.alert(message, {
title: "提示",
btn: ['打开配置页', '前往UP主页', '取消'],
btnAlign: 'c', // 按钮居中显示
btn1: function () {
window.open("/html/body/live.html?type=createRoom", '_blank')
},
btn2: function () {
window.open("https://space.bilibili.com/" + mid, '_blank')
},
btn3: function () {
}
});
}
})
</script>

View File

@ -59,9 +59,12 @@
</span>
</div>
<div class="layui-card-body">
<img src="#" onerror="showTmpImage('{{= item.cover}}',this)" onclick="toLive('{{= item.roomId}}')" style="width: 100%; height: 100%; object-fit: cover;"/><br>
<div style="overflow: hidden;position: relative; width: 100%; height: 100%; padding-bottom: 52%;">
<img src="#" onerror="showTmpImage('{{= item.cover}}',this)" onclick="toLive('{{= item.roomId}}')" style="max-width: 100%; max-height: 100%; object-fit: cover; display: block; margin: auto; position: absolute; "/><br>
</div>
<!-- <img src="#" onerror="showImage('{{= item.cover}}',this)" onclick="toLive('{{= item.roomId}}')" style="width: 100%; height: 100%;"/><br> -->
{{= item.title}}<br>
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; ">{{= item.title}}</span> <br>
<p>开播时长:{{= item.liveTime}}</p>
直播录制状态:
{{# if(item.downloadVideo){ }}

View File

@ -1,71 +1,86 @@
function get(url){
return fetch(url)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
return data;
})
.catch(error => {
return error;
});
}
function post(url,formData,isJSON) {
return fetch(url, {
method: "POST",
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
if(isJSON){
function get(url) {
return fetch(url)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
return data;
})
.catch(error => {
return error;
});
}
function post(url, formData, isJSON) {
return sendPost(url,true,formData,isJSON)
}
function sendPost(url, isFormData, formData, isJSON) {
var obj = {};
if (isFormData) {
obj = {
method: "POST",
body: formData
}
return response.blob();
})
.then(blob => {
if(isJSON){
return blob;
} else {
obj = {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
}
const imageUrl = URL.createObjectURL(blob);
return imageUrl;
})
.catch(error => {
console.error("There was a problem with the fetch operation:", error);
throw error; // 重新抛出错误以便外部捕获
});
}
return fetch(url, obj)
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
if (isJSON) {
return response.json();
}
return response.blob();
})
.then(blob => {
if (isJSON) {
return blob;
}
const imageUrl = URL.createObjectURL(blob);
return imageUrl;
})
.catch(error => {
console.error("There was a problem with the fetch operation:", error);
throw error; // 重新抛出错误以便外部捕获
});
}
function post2blob(url,formData) {
function post2blob(url, formData) {
return fetch(url, {
method: "POST",
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.text();
})
.then(blob => {
return blob;
})
.catch(error => {
console.error("There was a problem with the fetch operation:", error);
throw error; // 重新抛出错误以便外部捕获
});
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.text();
})
.then(blob => {
return blob;
})
.catch(error => {
console.error("There was a problem with the fetch operation:", error);
throw error; // 重新抛出错误以便外部捕获
});
}
function buildFormData(json){
function buildFormData(json) {
const formData = new FormData();
Object.keys(json).forEach(key => {
const value = json[key];
if (Array.isArray(value)) {
value.forEach((item, index) => {
formData.append(`${key}[${index}]`, item);
@ -81,101 +96,119 @@ function buildFormData(json){
//----------------直播配置相关接口
function getLiveVideoList() {
return get("/live/video/list");
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;
})
return post("/file/img", formData, false)
.then(blob => {
return blob;
})
}
function getHttpTmpImage(url) {
const encode = encodeURI(url);
const formData = new FormData();
formData.append("url", encode);
return post2blob("/file/imgTmp",formData)
.then(blob=>{
return blob;
})
return post2blob("/file/imgTmp", formData)
.then(blob => {
return blob;
})
}
function addRoomConfig(json){
const formData=buildFormData(json)
return post("/live/config/set",formData,true)
function addRoomConfig(config) {
const formData = buildFormData(config)
return post("/live/config/set", formData, true)
}
function getRoomConfig(roomId){
return get("/live/config/get?roomId="+roomId)
function setArrayRoomConfig(rooms, config) {
var json = {
"config": config,
"array": rooms
}
return sendPost("/live/config/set/array", false, json, true)
}
function deleteRoomConfig(roomId){
return get("/live/config/delete?roomId="+roomId)
function deleteArrayRoomConfig(rooms) {
return sendPost("/live/config/delete/array", false,rooms, true)
}
function checkFollowStatus(userId){
return get("/live/config/follow/check?userId="+userId)
function deleteAllRoomConfig() {
return get("/live/config/delete/all")
}
function confirmFollowStatus(userId){
return get("/live/config/follow/confirm?userId="+userId)
function getRoomConfig(roomId) {
return get("/live/config/get?roomId=" + roomId)
}
function addAllFollow(userId){
return get("/live/config/follow/all?userId="+userId)
function deleteRoomConfig(roomId) {
return get("/live/config/delete?roomId=" + roomId)
}
function addFollow(uid,anchorId){
return get("/live/config/follow/add?anchorId="+anchorId+"&uid="+uid)
function checkFollowStatus(userId) {
return get("/live/config/follow/check?userId=" + userId)
}
function addFollowList(uid,array){
function confirmFollowStatus(userId) {
return get("/live/config/follow/confirm?userId=" + userId)
}
function addAllFollow(userId) {
return get("/live/config/follow/all?userId=" + userId)
}
function addFollow(uid, anchorId) {
return get("/live/config/follow/add?anchorId=" + anchorId + "&uid=" + uid)
}
function addFollowList(uid, array) {
const formData = new FormData();
formData.append("array", array);
return post("/live/config/follow/addList?uid="+uid,formData,true)
return post("/live/config/follow/addList?uid=" + uid, formData, true)
}
function addFollowRoomList(array) {
const formData = new FormData();
formData.append("array", array);
return post("/live/config/follow/roomId/addList", formData, true)
}
//----------------直播配置相关接口end
//----------------首页相关接口
function getAllLive(page,limit){
return get("/live/list?page="+page+"&limit="+limit)
function getAllLive(page, limit) {
return get("/live/list?page=" + page + "&limit=" + limit)
}
function getAllConfig(page,limit){
return get("/live/config/all?page="+page+"&limit="+limit)
function getAllConfig(page, limit) {
return get("/live/config/all?page=" + page + "&limit=" + limit)
}
//----------------首页相关接口end
//----------------直播视频相关接口
function startLiveVideo(roomId){
return get("/live/video/start?roomId="+roomId)
function startLiveVideo(roomId) {
return get("/live/video/start?roomId=" + roomId)
}
function stopLiveVideo(roomId){
return get("/live/video/stop?roomId="+roomId)
function stopLiveVideo(roomId) {
return get("/live/video/stop?roomId=" + roomId)
}
function getVideo(roomId,page,limit){
return get("/file/list?roomId="+roomId+"&page="+page+"&limit="+limit)
function getVideo(roomId, page, limit) {
return get("/file/list?roomId=" + roomId + "&page=" + page + "&limit=" + limit)
}
function getPlayerVideo(roomId,videoId){
return get('/video/play?roomId='+roomId+"&videoId="+videoId)
function getPlayerVideo(roomId, videoId) {
return get('/video/play?roomId=' + roomId + "&videoId=" + videoId)
}
//----------------直播视频相关接口end
//----------------弹幕相关接口
function startLiveDanmu(roomId){
return get("/live/danmu/start?roomId="+roomId)
function startLiveDanmu(roomId) {
return get("/live/danmu/start?roomId=" + roomId)
}
function stopLiveDanmu(roomId){
return get("/live/danmu/stop?roomId="+roomId)
function stopLiveDanmu(roomId) {
return get("/live/danmu/stop?roomId=" + roomId)
}
function getDanmu(roomId,videoId){
return get("/live/danmu/get?roomId="+roomId+"&videoId="+videoId)
function getDanmu(roomId, videoId) {
return get("/live/danmu/get?roomId=" + roomId + "&videoId=" + videoId)
}
//----------------弹幕相关接口end
//----------------用户相关接口
function getBiliAllUser(){
function getBiliAllUser() {
return get("/user/list")
}
function login(){
function login() {
return get("/user/login")
}
function refreshCookie(userId){
return get("/user/refreshCookie?uid="+userId)
function refreshCookie(userId) {
return get("/user/refreshCookie?uid=" + userId)
}
//----------------用户相关接口end
//----------------礼物相关接口
function getVideoGiftInfo(roomId,videoId){
return get("/live/gift/info?roomId="+roomId+"&videoId="+videoId)
function getVideoGiftInfo(roomId, videoId) {
return get("/live/gift/info?roomId=" + roomId + "&videoId=" + videoId)
}
//----------------礼物相关接口end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -66,5 +66,9 @@ public interface LiveApi {
@POST("/room/v1/Room/get_status_info_by_uids")
Call<HttpBody<Map<String,LiveAnchorInfo>>> getLiveRoomStatus(@Body
JSONObject uids);
@GET("/xlive/web-ucenter/v1/xfetter/GetWebList")
Call<HttpBody<FollowLive>> getUserFollowLive(
@Query("hit_ab")boolean hit_ab,
@Query("_")long time
);
}

View File

@ -0,0 +1,107 @@
package com.yutou.biliapi.bean.live;
import com.alibaba.fastjson2.annotation.JSONField;
import com.yutou.common.okhttp.BaseBean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
public class FollowLive extends BaseBean {
@JSONField(name = "rooms")
List<Room> rooms;
@JSONField(name = "list")
List<Room> list;
@lombok.Data
public static class Room {
@JSONField(name = "title")
private String title;
@JSONField(name = "room_id")
private String roomId;
@JSONField(name = "uid")
private String uid;
@JSONField(name = "online")
private int online;
@JSONField(name = "live_time")
private String liveTime;
@JSONField(name = "live_status")
private int liveStatus;
@JSONField(name = "short_id")
private int shortId;
@JSONField(name = "area")
private int area;
@JSONField(name = "area_name")
private String areaName;
@JSONField(name = "area_v2_id")
private int areaV2Id;
@JSONField(name = "area_v2_name")
private String areaV2Name;
@JSONField(name = "area_v2_parent_name")
private String areaV2ParentName;
@JSONField(name = "area_v2_parent_id")
private int areaV2ParentId;
@JSONField(name = "uname")
private String uname;
@JSONField(name = "face")
private String face;
@JSONField(name = "tag_name")
private String tagName;
@JSONField(name = "tags")
private String tags;
@JSONField(name = "cover_from_user")
private String coverFromUser;
@JSONField(name = "keyframe")
private String keyframe;
@JSONField(name = "lock_till")
private String lockTill;
@JSONField(name = "hidden_till")
private String hiddenTill;
@JSONField(name = "broadcast_type")
private int broadcastType;
@JSONField(name = "is_encrypt")
private boolean isEncrypt;
@JSONField(name = "link")
private String link;
@JSONField(name = "nickname")
private String nickname;
@JSONField(name = "roomname")
private String roomName;
@JSONField(name = "roomid")
private String roomId2;
@JSONField(name = "liveTime")
private long liveTimeLong;
}
}

View File

@ -14,6 +14,8 @@ public class LiveVideoDatabaseBean extends AbsDatabasesBean {
String roomInfoJson;
@JSONField(name = "start_time")
Date startTime;
@JSONField(name = "stop_time")
Date stopTime;
@JSONField(name = "path")
String path;

View File

@ -118,8 +118,6 @@ public class BiliLiveDatabase extends SQLiteManager {
}
public JSONObject getGiftInfo(long startTimeLong, long endTimeLong) {
String startTime = DateFormatUtils.getInstance().format(startTimeLong);
String endTime = DateFormatUtils.getInstance().format(endTimeLong);
String giftSql = "WITH filtered_gifts AS (" +
"SELECT " +
"`gift_name`," +
@ -132,8 +130,8 @@ public class BiliLiveDatabase extends SQLiteManager {
"FROM " +
"`gift` " +
"WHERE " +
"`sql_time` >= '" + startTime + "' " +
"AND `sql_time` <= '" + endTime + "' " +
"`sql_time` >= '" + startTimeLong + "' " +
"AND `sql_time` <= '" + endTimeLong + "' " +
"GROUP BY " +
"`gift_name`, `coin_type`" +
")" +
@ -147,10 +145,10 @@ public class BiliLiveDatabase extends SQLiteManager {
"GROUP BY " +
"`gift_name`, `icon`;";
String guardSql = "SELECT `gift_name`, SUM(`num`) AS `total_num`,SUM(`price`*`num`) as `total_price`" +
"FROM `guardBuy` where `sql_time` >= '" + startTime + "' and `sql_time` <= '" + endTime + "'" +
"FROM `guardBuy` where `sql_time` >= '" + startTimeLong + "' and `sql_time` <= '" + endTimeLong + "'" +
"GROUP BY `gift_name`;";
String superChatSql = "SELECT SUM(`price`*100) as `total_price`, count(`price`) as `total_count`" +
"FROM `superChat` where `sql_time` >= '" + startTime + "' and `sql_time` <= '" + endTime + "';";
"FROM `superChat` where `sql_time` >= '" + startTimeLong + "' and `sql_time` <= '" + endTimeLong + "';";
JSONObject json = new JSONObject();
JSONArray giftInfo = get(giftSql);
JSONArray guardInfo = get(guardSql);
@ -177,15 +175,14 @@ public class BiliLiveDatabase extends SQLiteManager {
}
private void createInfo(LiveVideoDatabaseBean bean) {
String format = DateFormatUtils.getInstance().format(bean.getSql_time());
if (get(bean.getTableName(), " `sql_time` = '" + format + "'", LiveVideoDatabaseBean.class).isEmpty()) {
if (get(bean.getTableName(), " `sql_time` = '" + bean.getSql_time().getTime() + "'", LiveVideoDatabaseBean.class).isEmpty()) {
add(bean);
} else {
update(bean);
}
}
public <T extends AbsDatabasesBean> List<T> getOfTime(String startTime, String endTime, Class<T> clazz) {
public <T extends AbsDatabasesBean> List<T> getOfTime(Long startTime, Long endTime, Class<T> clazz) {
String tableName = null;
StringBuilder sb = new StringBuilder();
String where = null;

View File

@ -2,9 +2,11 @@ package com.yutou.bilibili.Controllers;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.biliapi.bean.live.FollowLive;
import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
import com.yutou.biliapi.bean.login.LoginUserDatabaseBean;
import com.yutou.biliapi.bean.user.UserFollowingsBean;
import com.yutou.bilibili.Tools.DateFormatUtils;
import com.yutou.bilibili.Tools.Tools;
import com.yutou.bilibili.datas.ResultData;
import com.yutou.bilibili.datas.ReturnCode;
@ -17,13 +19,13 @@ import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/live/config/")
@ -46,6 +48,17 @@ public class LiveConfigController {
return ResultData.success(bean, bean.getTotal());
}
@ResponseBody
@RequestMapping("followLive")
public JSONObject getFollowLive(String userId) {
List<FollowLive.Room> followLive = userService.getUserFollowLive(userId);
if (followLive == null) {
return ResultData.fail(ReturnCode.RC999);
}
followLive.forEach(item -> item.setLiveTime(DateFormatUtils.getInstance().convertSeconds(Long.parseLong(item.getLiveTime()))));
return ResultData.success(followLive, followLive.size());
}
@ResponseBody
@RequestMapping("follow/add")
public JSONObject addFollow(String uid, String anchorId) {
@ -79,7 +92,21 @@ public class LiveConfigController {
follow.setUname(jsonObject.getString("uname"));
return follow;
}).toList();
return ResultData.success(userService.followAll(uid,list));
return ResultData.success(userService.followAll(uid, list));
}
@ResponseBody
@RequestMapping("follow/roomId/addList")
public JSONObject addFollowListToRoomId(String array) {
if (!StringUtils.hasText(array)) {
return ResultData.fail(ReturnCode.RC500);
}
JSONArray jsonArray = JSONArray.parseArray(array);
List<LiveConfigDatabaseBean> list = jsonArray.stream().map(o -> {
JSONObject jsonObject = (JSONObject) o;
return configService.addConfig(jsonObject.getString("roomId"), new LiveConfigDatabaseBean());
}).toList();
return ResultData.success(list, list.size());
}
@ResponseBody
@ -110,6 +137,49 @@ public class LiveConfigController {
return ResultData.success(ReturnCode.RC100);
}
@RequestMapping(value = "set/array", method = RequestMethod.POST)
@ResponseBody
public JSONObject addArrayConfig(@RequestBody JSONObject jsonObject) {
JSONObject config=jsonObject.getJSONObject("config");
LiveConfigDatabaseBean bean = config.to(LiveConfigDatabaseBean.class);
if (!bean.verifyLiveTimer()) {
return ResultData.fail(ReturnCode.RC999.getCode(), "视频录制时间格式错误");
}
if (!bean.verifyDanmuTimer()) {
return ResultData.fail(ReturnCode.RC999.getCode(), "弹幕录制时间格式错误");
}
if("on".equals(config.getString("recordDanmu"))){
bean.setRecordDanmu(true);
}
if("on".equals(config.getString("recordLive"))){
bean.setRecordLive(true);
}
JSONArray jsonArray = jsonObject.getJSONArray("array");
List<LiveConfigDatabaseBean> list = jsonArray.stream().map(roomId -> configService.addConfig(roomId.toString(), bean)).toList();
int countNull = list.stream().filter(Objects::isNull).toList().size();
return ResultData.success("成功配置" + (list.size() - countNull) + "个直播间");
}
@RequestMapping(value = "delete/array", method = RequestMethod.POST)
@ResponseBody
public JSONObject deleteArrayConfig(@RequestBody JSONArray jsonArray) {
List<Boolean> list = jsonArray.stream().map(roomId -> configService.deleteConfig(roomId.toString())).toList();
int countNull = list.stream().filter(it -> !it).toList().size();
return ResultData.success("成功删除" + (list.size() - countNull) + "个直播间");
}
@RequestMapping(value = "delete/all", method = RequestMethod.GET)
@ResponseBody
public JSONObject deleteAllConfig() {
for (LiveConfigDatabaseBean bean : configService.getAllConfig()) {
configService.deleteConfig(bean.getRoomId());
}
if (configService.getAllConfig().isEmpty()) {
return ResultData.success("成功删除");
} else {
return ResultData.fail(-1, "删除失败,剩余:" + configService.getAllConfig().size() + "个直播间");
}
}
@RequestMapping(value = "set", method = RequestMethod.POST)
@ResponseBody

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
@ -109,6 +110,13 @@ public class VideoFileController {
@RequestMapping("/video/play")
@ResponseBody
public JSONObject getVideoUrl(String roomId, String videoId) {
return ResultData.success("/live/"+videoService.getVideoPlay(roomId, videoId));
String url = videoService.getVideoPlay(roomId, videoId);
/* String[] split = url.split("/");
StringBuilder sb=new StringBuilder();
for (String s : split) {
sb.append(URLEncoder.encode(s,StandardCharsets.UTF_8)).append("/");
}
sb.setLength(sb.length()-1);*/
return ResultData.success("/live"+url);
}
}

View File

@ -76,6 +76,17 @@ public class DateFormatUtils {
Date time = parse(date, format);
return format(time, format);
}
public String convertSeconds(long totalSeconds) {
// 计算总小时数
long hours = totalSeconds / 3600;
// 剩余的秒数
long remainingSecondsAfterHours = totalSeconds % 3600;
// 计算分钟数
long minutes = remainingSecondsAfterHours / 60;
// 最后剩余的秒数
long seconds = remainingSecondsAfterHours % 60;
return String.format("%d小时%d分%d秒", hours, minutes, seconds);
}
public String formatMillis(long millis) {
Duration duration = Duration.ofMillis(millis);
int seconds = (int) (duration.getSeconds() % 60);

View File

@ -59,18 +59,21 @@ public class LiveDanmuService {
public void saveDanmuXML(LiveVideoDatabaseBean videoDatabaseBean, BiliLiveDatabase database) {
File videoFile = new File(videoDatabaseBean.getPath());
long videoTime = FFmpegUtils.getVideoTime(videoFile) + videoDatabaseBean.getStartTime().getTime();
long videoTime;
if (videoDatabaseBean.getStopTime() == null) {
videoTime = System.currentTimeMillis();
} else {
videoTime = videoDatabaseBean.getStopTime().getTime();
}
Log.i("开始时间:" + videoDatabaseBean.getStartTime().getTime());
Log.i("结束时间:" + videoTime);
String startTime = DateFormatUtils.getInstance().format(videoDatabaseBean.getStartTime());
String endTime = DateFormatUtils.getInstance().format(videoTime);
List<LiveDanmuDatabaseBean> danmus = database.getOfTime(startTime, endTime, LiveDanmuDatabaseBean.class);
List<LiveDanmuDatabaseBean> danmus = database.getOfTime(videoDatabaseBean.getStartTime().getTime(), videoTime, LiveDanmuDatabaseBean.class);
Log.i("弹幕数量:" + danmus.size());
AssTools assTools = new AssTools(videoFile.getName().replace(".flv", ""), videoDatabaseBean.getStartTime());
AssTools assTools = new AssTools(videoFile.getName().replace(".m3u8", ""), videoDatabaseBean.getStartTime());
for (LiveDanmuDatabaseBean dm : danmus) {
assTools.addDanmu(dm.createDanmuData());
}
assTools.saveDanmu(videoFile.getAbsolutePath().replace(".flv", ".ass"));
assTools.saveDanmu(videoFile.getAbsolutePath().replace(".m3u8", ".ass"));
}
public String toTimeString(long videoTime) {
@ -90,19 +93,10 @@ public class LiveDanmuService {
if (videoBean == null) {
return new LiveVideoDanmu();
}
File videoFile = new File(videoBean.getPath().replace(".flv", ".mp4"));
if (!videoFile.exists()) {
videoFile = new File(videoBean.getPath());
}
long videoTime = FFmpegUtils.getVideoTime(videoFile);
long startTime = Long.parseLong(videoId);
long endTime = Long.parseLong(videoId) + videoTime;
// videoTime = 0;
if (videoTime == 0) {
endTime = System.currentTimeMillis();
}
List<LiveDanmuDatabaseBean> danmuList = liveDatabase.getOfTime(DateFormatUtils.getInstance().format(startTime), DateFormatUtils.getInstance().format(endTime), LiveDanmuDatabaseBean.class);
List<LiveSuperChatDatabaseBean> superChatList = liveDatabase.getOfTime(DateFormatUtils.getInstance().format(startTime), DateFormatUtils.getInstance().format(endTime), LiveSuperChatDatabaseBean.class);
long endTime = videoBean.getStopTime() == null ? System.currentTimeMillis() : videoBean.getStopTime().getTime();
List<LiveDanmuDatabaseBean> danmuList = liveDatabase.getOfTime(startTime, endTime, LiveDanmuDatabaseBean.class);
List<LiveSuperChatDatabaseBean> superChatList = liveDatabase.getOfTime(startTime, endTime, LiveSuperChatDatabaseBean.class);
for (LiveDanmuDatabaseBean bean : danmuList) {
LiveVideoDanmu.Danmu danmu = createDanmu(bean, startTime);
danmus.getDanmu().add(danmu);

View File

@ -87,7 +87,7 @@ public class LiveService {
if (info.getLiveTime() == 0) {
liveData.setLiveTime("未开播");
} else {
liveData.setLiveTime(DateFormatUtils.getInstance().formatMillis(System.currentTimeMillis() - info.getLiveTime()*1000));
liveData.setLiveTime(DateFormatUtils.getInstance().formatMillis(System.currentTimeMillis() - info.getLiveTime() * 1000));
}
liveData.setDownloadVideo(videoDownloadService.checkDownload(info.getRoomId()));
liveData.setDanmu(danmuService.check(info.getRoomId()));
@ -113,16 +113,8 @@ public class LiveService {
if (videoBean == null) {
return null;
}
File videoFile = new File(videoBean.getPath().replace(".flv", ".mp4"));
if (!videoFile.exists()) {
videoFile = new File(videoBean.getPath());
}
long videoTime = FFmpegUtils.getVideoTime(videoFile);
long startTime = Long.parseLong(videoId);
long endTime = Long.parseLong(videoId) + videoTime;
if(videoTime==0){
endTime=System.currentTimeMillis();
}
long startTime = videoBean.getStartTime().getTime();
long endTime = videoBean.getStopTime() == null ? System.currentTimeMillis() : videoBean.getStopTime().getTime();
return database.getGiftInfo(startTime, endTime);
}

View File

@ -1,7 +1,7 @@
package com.yutou.bilibili.services;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.biliapi.api.UserApi;
import com.yutou.biliapi.bean.live.FollowLive;
import com.yutou.biliapi.bean.live.SpiBean;
import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
import com.yutou.biliapi.bean.login.LoginCookieDatabaseBean;
@ -9,7 +9,7 @@ import com.yutou.biliapi.bean.user.UserFollowingsBean;
import com.yutou.biliapi.bean.user.UserHomeInfoBean;
import com.yutou.biliapi.bean.user.UserInfoBean;
import com.yutou.biliapi.databases.BiliBiliLoginDatabase;
import com.yutou.biliapi.net.BiliCookieManager;
import com.yutou.biliapi.net.BiliLiveNetApiManager;
import com.yutou.biliapi.net.BiliUserNetApiManager;
import com.yutou.biliapi.net.WebSignManager;
import com.yutou.bilibili.datas.ResultData;
@ -34,6 +34,14 @@ public class LiveUserService {
@Resource
LiveConfigService configService;
public List<FollowLive.Room> getUserFollowLive(String userId) {
try {
FollowLive followLive = BiliLiveNetApiManager.getInstance().getApi(userId).getUserFollowLive(true, System.currentTimeMillis()).execute().body().getData();
return followLive.getRooms();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public UserFollowingsBean getUserFollowings(String userId, int page, int num) {
LoginCookieDatabaseBean cookie = userLoginService.getCookie(userId);
UserApi api = BiliUserNetApiManager.getInstance().getUserApi(cookie);

View File

@ -120,7 +120,7 @@ public class LiveVideoDownloadService {
File rootPath;
LiveConfigDatabaseBean config;
BiliLiveDatabase database;
LiveVideoDatabaseBean videoDatabaseBean;
LiveVideoDatabaseBean videoDatabaseBean = null;
LiveRoomInfo roomInfo;
public VideoTask(LiveConfigDatabaseBean bean, LiveRoomInfo roomInfo) {
@ -136,8 +136,8 @@ public class LiveVideoDownloadService {
String time = DateUtils.format(new Date().getTime(), DATE_FORMAT_10_DASH);
rootPath = new File(bean.getRecordPath() + File.separator + bean.getAnchorName() + File.separator + time + File.separator + "[" +
DateUtils.format(new Date(),
"yyyy-MM-dd HH-mm-ss") + "]" + roomInfo.getTitle());
savePath = rootPath.getAbsolutePath() + File.separator + roomInfo.getTitle() + "-%04d.ts";
"HH-mm-ss") + "]" + roomInfo.getTitle());
savePath = rootPath.getAbsolutePath() + File.separator + roomInfo.getTitle() + ".m3u8";
if (!rootPath.exists()) {
rootPath.mkdirs();
}
@ -148,14 +148,14 @@ public class LiveVideoDownloadService {
}
private void stop() {
videoRecord.kill(bean.getRoomId().toString());
api.getRoomInfo(config.getRoomId().toString()).enqueue(new HttpCallback<LiveRoomInfo>() {
videoRecord.kill(bean.getRoomId());
api.getRoomInfo(config.getRoomId()).enqueue(new HttpCallback<LiveRoomInfo>() {
@Override
public void onResponse(Headers headers, int code, String status, LiveRoomInfo response, String rawResponse) {
if (response.getLiveStatus() == 1) {
LiveVideoDownloadService.this.start(bean, false);
} else {
LiveVideoDownloadService.this.stop(bean.getRoomId().toString(), false);
LiveVideoDownloadService.this.stop(bean.getRoomId(), false);
}
}
@ -289,20 +289,19 @@ public class LiveVideoDownloadService {
// .withNotSymbolParam("-bufsize", "10M")
.withNotSymbolParam("-f", "segment")
.withNotSymbolParam("-segment_time", "60")
.withNotSymbolParam("-segment_format", "flv")
.withParam("-segment_list", rootPath + File.separator + roomInfo.getTitle() + ".m3u8")
.withNotSymbolParam("-segment_format", "mpegts")
.withNotSymbolParam("-map", "0")
.withParam("-segment_list", savePath)
.withNotSymbolParam("-c", "copy")
.withNotSymbolParam("-bsf:a", "aac_adtstoasc")
// .withNotSymbolParam("-loglevel", "debug")
.withNotSymbolParam("-y", "")
//-reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2
// .withNotSymbolParam("-progress",new File("cache",config.getRoomId()+".txt").getAbsolutePath()); //输出进度日志,暂时没啥用
;
if (ck != null) {
// builder = builder.withParam("-cookies", cookie);
}
FFmpegUtils command = builder.build(config.getRoomId(), ffmpegPath, url, savePath);
FFmpegUtils command = builder.build(config.getRoomId(), ffmpegPath, url, savePath.replace(".m3u8","-%04d.ts"));
Log.i(command.getCommandDecode());
try {
command.start(new DownloadInterface() {
@ -335,6 +334,10 @@ public class LiveVideoDownloadService {
task.cancel();
task = null;
}
if (videoDatabaseBean != null) {
videoDatabaseBean.setStopTime(new Date());
database.addLiveInfo(videoDatabaseBean);
}
}
});
@ -430,8 +433,8 @@ public class LiveVideoDownloadService {
File videoFile = new File(videoInfo.getPath().replace("-%04d.ts", ".m3u8"));
if (!videoFile.exists()) {
videoFile = new File(videoInfo.getPath());
}else{
return videoInfo.getPath().replace(new File("live").getAbsolutePath(),"").replace(File.separator,"/").replace("-%04d.ts", ".m3u8");
} else {
return videoInfo.getPath().replace(new File("live").getAbsolutePath(), "").replace(File.separator, "/").replace("-%04d.ts", ".m3u8");
}
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath, videoFile, ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
System.out.println(ffmpeg.getCommandDecode());

View File

@ -380,11 +380,10 @@ public abstract class SQLiteManager {
protected <T extends AbsDatabasesBean> boolean delete(T t) {
Statement statement = null;
try {
String id = DateUtils.format(t.getSql_time(), "yyyy-MM-dd HH:mm:ss.SSS");
statement = getConnection().createStatement();
StringBuilder sb = new StringBuilder();
sb.append("DELETE FROM `").append(t.getTableName()).append("` ");
sb.append(" WHERE `sql_time` = ").append("'").append(id).append("'");
sb.append(" WHERE `sql_time` = ").append("'").append(t.getSql_time().getTime()).append("'");
int ret = statement.executeUpdate(sb.toString());
return ret != 0;
} catch (Exception e) {

View File

@ -182,7 +182,6 @@ public class FFmpegUtils extends AbsVideoRecord {
process.exitValue();
return (long) (Double.parseDouble(data) * 1000);
} catch (Exception e) {
Log.e(e);
return 0;
}
}