完善web一些功能

This commit is contained in:
zlzw 2024-11-27 17:39:02 +08:00
parent 48a15c8769
commit e8cceef419
12 changed files with 647 additions and 143 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

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

@ -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: '350px',
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,7 +59,10 @@
</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>
<p>开播时长:{{= item.liveTime}}</p>

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

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 int 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

@ -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,41 @@ public class LiveConfigController {
return ResultData.success(ReturnCode.RC100);
}
@RequestMapping(value = "set/array", method = RequestMethod.POST)
@ResponseBody
public JSONObject addArrayConfig(@RequestBody JSONObject jsonObject) {
LiveConfigDatabaseBean bean = jsonObject.getJSONObject("config").to(LiveConfigDatabaseBean.class);
if (!bean.verifyLiveTimer()) {
return ResultData.fail(ReturnCode.RC999.getCode(), "视频录制时间格式错误");
}
if (!bean.verifyDanmuTimer()) {
return ResultData.fail(ReturnCode.RC999.getCode(), "弹幕录制时间格式错误");
}
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

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

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