70 lines
2.4 KiB
Java
70 lines
2.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 jakarta.annotation.Resource;
|
||
|
import org.springframework.stereotype.Service;
|
||
|
import org.springframework.util.StringUtils;
|
||
|
|
||
|
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.setAnchorFace(infoBean.getInfo().getFace());
|
||
|
bean.setAnchorName(infoBean.getInfo().getUname());
|
||
|
database.setConfig(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);
|
||
|
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);
|
||
|
}
|
||
|
}
|