93 lines
3.4 KiB
Java
93 lines
3.4 KiB
Java
package com.yutou.bilibili.services;
|
|
|
|
import com.yutou.biliapi.bean.live.LiveRoomInfo;
|
|
import com.yutou.biliapi.bean.live.MasterInfoBean;
|
|
import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
|
|
import com.yutou.biliapi.databases.BiliLiveConfigDatabase;
|
|
import com.yutou.biliapi.net.BiliLiveNetApiManager;
|
|
import com.yutou.common.okhttp.HttpDownloadUtils;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.math.BigInteger;
|
|
import java.util.List;
|
|
|
|
@Service
|
|
public class LiveConfigService {
|
|
BiliLiveConfigDatabase database = new BiliLiveConfigDatabase();
|
|
|
|
public LiveConfigDatabaseBean addConfig(String url, LiveConfigDatabaseBean bean) {
|
|
if (!StringUtils.hasText(url)) {
|
|
return null;
|
|
}
|
|
String roomId = url.replace("https://live.bilibili.com/", "").split("\\?")[0];
|
|
if (!StringUtils.hasText(roomId)) {
|
|
return null;
|
|
}
|
|
bean.setRoomId(new BigInteger(roomId));
|
|
try {
|
|
LiveRoomInfo body = BiliLiveNetApiManager.getInstance().getApi(null).getRoomInfo(String.valueOf(bean.getRoomId())).execute().body().getData();
|
|
MasterInfoBean infoBean = BiliLiveNetApiManager.getInstance().getApi(null).getMasterInfo(String.valueOf(body.getUid())).execute().body().getData();
|
|
bean.setAnchorUid(body.getUid());
|
|
bean.setRoomId(body.getRoomId());
|
|
bean.setAnchorFace(infoBean.getInfo().getFace());
|
|
bean.setAnchorName(infoBean.getInfo().getUname());
|
|
database.setConfig(bean);
|
|
downloadFace(bean);
|
|
return bean;
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
|
|
public LiveConfigDatabaseBean updateConfig(BigInteger roomId, LiveConfigDatabaseBean bean) {
|
|
LiveConfigDatabaseBean config = database.getConfig(roomId);
|
|
if (config == null) {
|
|
return null;
|
|
}
|
|
bean.setRoomId(roomId);
|
|
bean.setSql_time(config.getSql_time());
|
|
database.setConfig(bean);
|
|
downloadFace(bean);
|
|
return bean;
|
|
}
|
|
|
|
public boolean deleteConfig(BigInteger roomId) {
|
|
LiveConfigDatabaseBean config = database.getConfig(roomId);
|
|
if (config == null) {
|
|
return false;
|
|
|
|
}
|
|
return database.deleteConfig(roomId);
|
|
}
|
|
|
|
public List<LiveConfigDatabaseBean> getAllConfig() {
|
|
return database.getAllConfig();
|
|
}
|
|
|
|
public LiveConfigDatabaseBean getConfig(BigInteger roomId) {
|
|
return database.getConfig(roomId);
|
|
}
|
|
|
|
public File getFace(String roomId){
|
|
LiveConfigDatabaseBean config = database.getConfig(new BigInteger(roomId));
|
|
if (config == null) {
|
|
return null;
|
|
}
|
|
return new File(config.getRecordPath() + File.separator + config.getAnchorName() + File.separator + config.getAnchorFace());
|
|
}
|
|
|
|
private void downloadFace(LiveConfigDatabaseBean bean) {
|
|
HttpDownloadUtils.download(
|
|
new HttpDownloadUtils.Builder()
|
|
.setPath(bean.getRecordPath() + File.separator + bean.getAnchorName())
|
|
.setUrl(bean.getAnchorFace())
|
|
.setFileName("face.jpg")
|
|
);
|
|
bean.setAnchorFace(bean.getRecordPath() + File.separator + bean.getAnchorName() + File.separator + "face.jpg");
|
|
}
|
|
}
|