This commit is contained in:
Yutousama 2024-11-03 15:32:20 +08:00
parent 51f961b054
commit 3b190b8a44
7 changed files with 120 additions and 41 deletions

View File

@ -119,8 +119,8 @@
layui.use(['laytpl', 'laypage'], function () {
var laytpl = layui.laytpl;
var laypage = layui.laypage;
var pageIndex = 0;
var pageMax = 8;
var pageIndex = 1;
var pageMax = 16;
var listCount=10;
var listMax=pageMax;
var initPage=true;
@ -150,8 +150,8 @@
function initPageView(){
laypage.render({
elem: 'page',
limit: 8,
curr: pageIndex + 1,
limit: 16,
curr: pageIndex,
limits: [4, 8, 16, 24, 32, 40],
layout: ['prev', 'page', 'next', 'limit'],
count: listCount, // 数据总数

View File

@ -8,6 +8,9 @@ import com.yutou.common.okhttp.HttpBody;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
/**
* 直播间相关API
* <a href="https://socialsisteryi.github.io/bilibili-API-collect/docs/live/info.html#%E8%8E%B7%E5%8F%96%E7%9B%B4%E6%92%AD%E9%97%B4%E4%BF%A1%E6%81%AF">文档地址</a>
@ -55,8 +58,13 @@ public interface LiveApi {
@GET("/xlive/web-room/v1/giftPanel/giftConfig?platform=pc")
Call<HttpBody<BaseBean>> getLiveGiftConfig();
/**
* 批量查询直播间状态
* @param uids 要查询的主播 mid
* @return <a href="https://socialsisteryi.github.io/bilibili-API-collect/docs/live/info.html#%E6%89%B9%E9%87%8F%E6%9F%A5%E8%AF%A2%E7%9B%B4%E6%92%AD%E9%97%B4%E7%8A%B6%E6%80%81">文档</a>
*/
@POST("/room/v1/Room/get_status_info_by_uids")
Call<HttpBody<BaseBean>> getLiveRoomStatus( @Body
Call<HttpBody<Map<String,LiveAnchorInfo>>> getLiveRoomStatus(@Body
JSONObject uids);
}

View File

@ -1,5 +1,6 @@
package com.yutou.biliapi.databases;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.util.DateUtils;
import com.yutou.biliapi.bean.live.*;
import com.yutou.biliapi.bean.live.database.*;
@ -66,7 +67,8 @@ public class BiliLiveDatabase extends SQLiteManager {
new LiveInteractWordDatabaseBean(),
new LiveSuperChatDatabaseBean(),
new LiveSourceDatabaseBean(),
new LiveVideoDatabaseBean()
new LiveVideoDatabaseBean(),
new LiveGuardBuyBean()
);
}
@ -136,19 +138,31 @@ public class BiliLiveDatabase extends SQLiteManager {
}
return super.get(tableName, where, clazz);
}
public static void main(String[] args) {
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("5265"));
public void resetSQL(){
List<AbsDatabasesBean> list = List.of(
new LiveInfoDatabaseBean(),
new LiveDanmuDatabaseBean(),
new LiveGiftDatabaseBean(),
new LiveGuardBuyBean(),
new LiveInteractWordDatabaseBean(),
new LiveSuperChatDatabaseBean()
);
for (AbsDatabasesBean item : list) {
biliLiveDatabase.clearTable(item.getTableName());
clearTable(item.getTableName());
}
recreateSql(list);
}
public void resetData(){
List<LiveSourceDatabaseBean> list = get(new LiveSourceDatabaseBean().getTableName(), LiveSourceDatabaseBean.class);
for (LiveSourceDatabaseBean item : list) {
WSData data = WSData.parse(JSONObject.parseObject(item.getJson()));
addData(data);
}
}
public static void main(String[] args) {
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("5265"));
// biliLiveDatabase.resetSQL();
biliLiveDatabase.resetData();
}
}

View File

@ -74,6 +74,7 @@ public class VideoFileController {
public String getTmpImg(String url) {
try {
// 获取图片流
System.out.println("url = " + url);
InputStream inputStream = new URL(url).openStream();
// 将输入流转换为字节数组

View File

@ -1,19 +1,27 @@
package com.yutou.bilibili.services;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.biliapi.api.LiveApi;
import com.yutou.biliapi.bean.live.LiveAnchorInfo;
import com.yutou.biliapi.bean.live.LiveRoomInfo;
import com.yutou.biliapi.bean.live.LiveRoomPlayInfo;
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.BaseBean;
import com.yutou.common.okhttp.HttpLoggingInterceptor;
import com.yutou.common.utils.Log;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@Service
public class LiveService {
@ -32,33 +40,61 @@ public class LiveService {
return liveConfigDatabase.getAllConfig().size();
}
public List<LiveData> getLiveList(int page,int limit) {
List<LiveConfigDatabaseBean> allConfig = liveConfigDatabase.getConfigs(page,limit);
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(videoDownloadService.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());
}
JSONArray uids=new JSONArray();
JSONObject param=new JSONObject();
for (LiveConfigDatabaseBean bean : allConfig) {
uids.add(bean.getAnchorUid());
}
param.put("uids",uids);
try {
Map<String, LiveAnchorInfo> map = api.getLiveRoomStatus(param).execute().body().getData();
List<LiveAnchorInfo> onlineList = new ArrayList<>();
List<LiveAnchorInfo> offlineList = new ArrayList<>();
for (LiveAnchorInfo info : map.values()) {
if(info.getLiveStatus()==1){
onlineList.add(info);
}else{
offlineList.add(info);
}
}
onlineList.addAll(offlineList);
int totalSize = onlineList.size();
int fromIndex = (page - 1) * limit;
int toIndex = Math.min(fromIndex + limit, totalSize);
if (fromIndex >= totalSize) {
return new ArrayList<>(); // 返回空列表
}
List<LiveAnchorInfo> list = onlineList.subList(fromIndex, toIndex);
for (LiveAnchorInfo info : list) {
LiveData liveData = new LiveData();
liveData.setRoomId(info.getRoomId());
liveData.setAnchorUid(info.getUid());
liveData.setAnchorName(info.getUname());
liveData.setAnchorFace(info.getFace());
liveData.setDownloadVideo(videoDownloadService.checkDownload(info.getRoomId()));
liveData.setDanmu(danmuService.check(info.getRoomId()));
liveData.setTitle(info.getTitle());
liveData.setLive(info.getLiveStatus() == 1);
if (info.getLiveStatus() == 1 && StringUtils.hasText(info.getKeyframe())) {
liveData.setCover(info.getKeyframe());
} else {
liveData.setCover(info.getCoverFromUser());
}
liveDataList.add(liveData);
} catch (IOException e) {
Log.e(e);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
liveDataList.sort(Comparator.comparing(LiveData::isLive).reversed());
return liveDataList;
}
public static void main(String[] args) {
HttpLoggingInterceptor.setLog(true);
LiveService service=new LiveService();
List<LiveData> data = service.getLiveList(1, 16);
System.out.println(data.size());
}
}

View File

@ -175,10 +175,17 @@ public class LiveVideoDownloadService {
config.setRoomInfo(roomInfo);
config.setRootPath(bean.getRecordPath());
database = new BiliLiveDatabase(config);
HttpDownloadUtils.download(new HttpDownloadUtils.Builder().setUrl(roomInfo.getKeyframe())
.setPath(rootPath.getAbsolutePath())
.setFileName("poster.jpg"));
LiveInfoNfoTools.saveLiveInfoNfo(roomInfo, rootPath.getAbsolutePath(), new File(savePath).getName().replace(".flv", ".nfo"));
try {
var keyframe = roomInfo.getKeyframe();
if(!StringUtils.hasText(keyframe)){
keyframe= roomInfo.getUserCover();
}
HttpDownloadUtils.download(new HttpDownloadUtils.Builder().setUrl(keyframe)
.setPath(rootPath.getAbsolutePath())
.setFileName("poster.jpg"));
}catch (Exception e){
e.printStackTrace();
}
saveLiveInfo(roomInfo);
api.getLiveRoomPlayInfo(
bean.getRoomId().toString(),
@ -292,6 +299,8 @@ public class LiveVideoDownloadService {
videoDatabaseBean.setRoomInfoJson(JSONObject.toJSONString(roomInfo));
videoDatabaseBean.setStartTime(new Date());
database.addLiveInfo(videoDatabaseBean);
LiveInfoNfoTools.saveLiveInfoNfo(roomInfo, rootPath.getAbsolutePath(), new File(savePath).getName().replace(".flv", ".nfo"));
}
}

View File

@ -29,8 +29,7 @@ public abstract class SQLiteManager {
public abstract String getFileName();
public void init() {
List<AbsDatabasesBean> data = getDataBean();
private BuildSql createBuildSQL(List<AbsDatabasesBean> data){
List<BuildSqlItem> items;
List<BuildSqlTable> tables = new ArrayList<>();
for (AbsDatabasesBean bean : data) {
@ -62,12 +61,17 @@ public abstract class SQLiteManager {
tables.add(BuildSqlTable.create().setName(bean.getTableName()).setItem(items));
}
BuildSql sql = BuildSql.create()
return BuildSql.create()
.setFileName(getFileName())
.setTable(tables);
build(sql);
}
public void init() {
build(createBuildSQL(getDataBean()));
}
public void recreateSql(List<AbsDatabasesBean> beans){
createSql(createBuildSQL(beans));
}
public void startBatch() {
try {
@ -156,6 +160,13 @@ public abstract class SQLiteManager {
protected <T extends AbsDatabasesBean> void update(T t) {
try {
String id = DateUtils.format(t.getSql_time(), "yyyy-MM-dd HH:mm:ss.SSS");
if(id.endsWith("0")){
id=id.substring(0,id.length()-1);
}else if(id.endsWith("00")){
id=id.substring(0,id.length()-2);
}else if(id.endsWith("000")){
id=id.substring(0,id.length()-4);
}
Statement statement = conn.createStatement();
StringBuilder sb = new StringBuilder();
sb.append("UPDATE `").append(t.getTableName()).append("` ");
@ -294,7 +305,7 @@ public abstract class SQLiteManager {
*/
public void clearTable(String tableName) {
try {
String sql = "DELETE FROM " + tableName;
String sql = "DROP TABLE IF EXISTS " + tableName;
try (Statement stmt = conn.createStatement()) {
int rowsDeleted = stmt.executeUpdate(sql);
stmt.close();