update
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.yutou.bilibili.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.biliapi.bean.login.LoginUserDatabaseBean;
|
||||
import com.yutou.bilibili.datas.ResultData;
|
||||
import com.yutou.bilibili.services.LiveLoginService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class BiliUserController {
|
||||
@Resource
|
||||
LiveLoginService loginService;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/user/list")
|
||||
public JSONObject getAllUser() {
|
||||
JSONArray array = new JSONArray();
|
||||
List<LoginUserDatabaseBean> allUser = loginService.getAllUser();
|
||||
for (LoginUserDatabaseBean bean : allUser) {
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("uid",bean.getUserInfo().getMid());
|
||||
json.put("uname",bean.getUserInfo().getUname());
|
||||
array.add(json);
|
||||
}
|
||||
return ResultData.success(array);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,17 @@ public class LiveConfigController {
|
||||
@RequestMapping(value = "set", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public JSONObject setConfig(String url, LiveConfigDatabaseBean bean) {
|
||||
if(!bean.verifyLiveTimer()){
|
||||
return ResultData.fail(ReturnCode.RC999.getCode(),"视频录制时间格式错误");
|
||||
}
|
||||
if(!bean.verifyDanmuTimer()){
|
||||
return ResultData.fail(ReturnCode.RC999.getCode(),"弹幕录制时间格式错误");
|
||||
}
|
||||
if(!url.startsWith("https://live.bilibili.com/")){
|
||||
if(!configService.checkUrl(url)){
|
||||
return ResultData.fail(ReturnCode.RC999.getCode(),"房间地址/房间号错误");
|
||||
}
|
||||
}
|
||||
LiveConfigDatabaseBean config = configService.addConfig(url, bean);
|
||||
if (config != null) {
|
||||
return ResultData.success(config.toJson());
|
||||
@@ -38,6 +49,13 @@ public class LiveConfigController {
|
||||
@RequestMapping(value = "update", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public JSONObject updateConfig(String roomId, LiveConfigDatabaseBean bean) {
|
||||
if(!bean.verifyLiveTimer()){
|
||||
return ResultData.fail(ReturnCode.RC999.getCode(),"视频录制时间格式错误");
|
||||
}
|
||||
if(!bean.verifyDanmuTimer()){
|
||||
return ResultData.fail(ReturnCode.RC999.getCode(),"弹幕录制时间格式错误");
|
||||
}
|
||||
|
||||
LiveConfigDatabaseBean config = configService.updateConfig(new BigInteger(roomId), bean);
|
||||
if (config != null) {
|
||||
return ResultData.success(config.toJson());
|
||||
|
||||
@@ -6,6 +6,9 @@ import com.yutou.bilibili.Tools.Tools;
|
||||
import com.yutou.bilibili.datas.ResultData;
|
||||
import com.yutou.bilibili.datas.VideoFilePath;
|
||||
import com.yutou.bilibili.services.LiveVideoService;
|
||||
import com.yutou.common.okhttp.HttpDownloadUtils;
|
||||
import com.yutou.common.utils.AppTools;
|
||||
import com.yutou.common.utils.Base64Tools;
|
||||
import com.yutou.common.utils.Log;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
@@ -15,9 +18,12 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@@ -36,6 +42,7 @@ public class VideoFileController {
|
||||
}
|
||||
return ResultData.success(list);
|
||||
}
|
||||
|
||||
@RequestMapping("/file/{base64}")
|
||||
@ResponseBody
|
||||
public ResponseEntity<FileSystemResource> getFile(@PathVariable String base64) {
|
||||
@@ -44,4 +51,26 @@ public class VideoFileController {
|
||||
return Tools.getFile(file);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/file/img", method = RequestMethod.POST)
|
||||
public ResponseEntity<FileSystemResource> getImg(String url) {
|
||||
url = URLDecoder.decode(url, StandardCharsets.UTF_8);
|
||||
String encode = AppTools.getMD5(url);
|
||||
File img = new File("cache" + File.separator + "image" + File.separator + encode);
|
||||
if (img.exists()) {
|
||||
return Tools.getFile(img);
|
||||
}
|
||||
if (!img.getParentFile().exists()) {
|
||||
img.getParentFile().mkdirs();
|
||||
}
|
||||
File file = HttpDownloadUtils.downloadSync(new HttpDownloadUtils.Builder()
|
||||
.setFileName(encode)
|
||||
.setUrl(url)
|
||||
.setPath(img.getParent())
|
||||
);
|
||||
if (file != null) {
|
||||
return Tools.getFile(file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class LiveConfigService {
|
||||
return database.getConfig(roomId);
|
||||
}
|
||||
|
||||
public File getFace(String roomId){
|
||||
public File getFace(String roomId) {
|
||||
LiveConfigDatabaseBean config = database.getConfig(new BigInteger(roomId));
|
||||
if (config == null) {
|
||||
return null;
|
||||
@@ -89,4 +89,23 @@ public class LiveConfigService {
|
||||
);
|
||||
bean.setAnchorFace(bean.getRecordPath() + File.separator + bean.getAnchorName() + File.separator + "face.jpg");
|
||||
}
|
||||
|
||||
public boolean checkUrl(String url) {
|
||||
if (!url.startsWith("https://live.bilibili.com/")) {
|
||||
try {
|
||||
new BigInteger(url);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
url = url.replace("https://live.bilibili.com/", "").split("\\?")[0];
|
||||
}
|
||||
try {
|
||||
LiveRoomInfo body = BiliLiveNetApiManager.getInstance().getApi(null).getRoomInfo(url).execute().body().getData();
|
||||
return body != null;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,25 @@ package com.yutou.bilibili.services;
|
||||
|
||||
import com.yutou.biliapi.api.LoginApi;
|
||||
import com.yutou.biliapi.bean.login.LoginInfoBean;
|
||||
import com.yutou.biliapi.bean.login.LoginUserDatabaseBean;
|
||||
import com.yutou.biliapi.bean.login.QRCodeGenerateBean;
|
||||
import com.yutou.biliapi.databases.BiliBiliLoginDatabase;
|
||||
import com.yutou.biliapi.net.BiliLoginNetApiManager;
|
||||
import com.yutou.common.okhttp.HttpBody;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LiveLoginService {
|
||||
BiliBiliLoginDatabase loginDatabase;
|
||||
|
||||
public LiveLoginService() {
|
||||
loginDatabase = BiliBiliLoginDatabase.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* loginApi.getQRCodeGenerate().enqueue(new HttpCallback<QRCodeGenerateBean>() {
|
||||
*
|
||||
@@ -41,4 +51,9 @@ public class LiveLoginService {
|
||||
public void login() {
|
||||
|
||||
}
|
||||
|
||||
public List<LoginUserDatabaseBean> getAllUser() {
|
||||
|
||||
return loginDatabase.getAllUser();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user