update
This commit is contained in:
@@ -55,6 +55,35 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
|
||||
return checkRecordTime(recordLiveDate);
|
||||
}
|
||||
|
||||
public boolean verifyDanmuTimer() {
|
||||
return verifyTimer(recordDanmuDate);
|
||||
}
|
||||
|
||||
public boolean verifyLiveTimer() {
|
||||
return verifyTimer(recordLiveDate);
|
||||
}
|
||||
|
||||
private boolean verifyTimer(String val) {
|
||||
int _length = val.length();
|
||||
boolean isFullDate = (_length - val.replace("*", "").length()) == 3
|
||||
&& (_length - val.replace("*", "").trim().length()) == 0;
|
||||
String[] split = val.split(" ");
|
||||
if (isFullDate) {
|
||||
return true;
|
||||
}
|
||||
String minute = split[0];
|
||||
String hour = split[1];
|
||||
String day = split[2];
|
||||
try {
|
||||
Integer.parseInt(minute);
|
||||
Integer.parseInt(hour);
|
||||
Integer.parseInt(day);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkRecordTime(String recordDate) {
|
||||
int _length = recordDate.length();
|
||||
boolean isFullDate = (_length - recordDate.replace("*", "").length()) == 3;
|
||||
@@ -70,7 +99,7 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
|
||||
boolean isFullDay = "*".equals(day);
|
||||
Calendar today = Calendar.getInstance();
|
||||
if (!isFullDay) {
|
||||
if (today.get(Calendar.DAY_OF_WEEK) != Integer.parseInt(day)) {
|
||||
if (today.get(Calendar.DAY_OF_WEEK) != Integer.parseInt(day) + 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.yutou.biliapi.databases;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.biliapi.bean.login.LoginCookieDatabaseBean;
|
||||
import com.yutou.biliapi.bean.login.LoginUserDatabaseBean;
|
||||
import com.yutou.biliapi.bean.login.UserInfoBean;
|
||||
import com.yutou.common.databases.AbsDatabasesBean;
|
||||
import com.yutou.common.databases.SQLiteManager;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BiliBiliLoginDatabase extends SQLiteManager {
|
||||
@@ -52,7 +56,7 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
|
||||
}
|
||||
|
||||
public LoginUserDatabaseBean getUser(String userId) {
|
||||
List<LoginUserDatabaseBean> list = super.get(cookie.getTableName(), LoginUserDatabaseBean.class);
|
||||
List<LoginUserDatabaseBean> list = getAllUser();
|
||||
if (userId == null && !list.isEmpty()) {
|
||||
return list.getFirst();
|
||||
}
|
||||
@@ -64,6 +68,16 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<LoginUserDatabaseBean> getAllUser() {
|
||||
JSONArray jsonArray = super.getJSONArray(new LoginUserDatabaseBean(null).getTableName());
|
||||
List<LoginUserDatabaseBean> list = new ArrayList<>();
|
||||
for (Object o : jsonArray) {
|
||||
JSONObject json= (JSONObject) o;
|
||||
list.add(new LoginUserDatabaseBean(json.to(UserInfoBean.class)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return "bilibili_login.db";
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.yutou.common.databases;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.alibaba.fastjson2.util.DateUtils;
|
||||
@@ -183,11 +184,57 @@ public abstract class SQLiteManager {
|
||||
|
||||
}
|
||||
|
||||
protected JSONArray getJSONArray(String table) {
|
||||
return getJSONArray(table, null);
|
||||
}
|
||||
|
||||
protected JSONArray getJSONArray(String table, String where) {
|
||||
JSONArray array = new JSONArray();
|
||||
try {
|
||||
Statement statement = conn.createStatement();
|
||||
String sql = "SELECT * FROM `" + table + "`";
|
||||
if (where != null) {
|
||||
sql += " WHERE " + where;
|
||||
}
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
while (resultSet.next()) {
|
||||
array.add(getSQL(resultSet));
|
||||
}
|
||||
resultSet.close();
|
||||
statement.closeOnCompletion();
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private JSONObject getSQL(ResultSet resultSet) throws SQLException {
|
||||
JSONObject json = new JSONObject();
|
||||
for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) {
|
||||
String name = resultSet.getMetaData().getColumnName(i + 1);
|
||||
Object value = resultSet.getObject(name);
|
||||
if (value instanceof String && ((String) value).startsWith("[")) {
|
||||
try {
|
||||
json.put(name, JSON.parseArray((String) value));
|
||||
} catch (Exception e) {
|
||||
json.put(name, value);
|
||||
}
|
||||
} else {
|
||||
json.put(name, value);
|
||||
if (json.get(name) == null || "null".equals(json.get(name).toString())) {
|
||||
json.put(name, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
protected <T extends AbsDatabasesBean> List<T> get(String table, Class<T> tClass) {
|
||||
return get(table, null, tClass);
|
||||
}
|
||||
|
||||
protected <T extends AbsDatabasesBean> List<T> get(String table, String where, Class<T> tClass) {
|
||||
protected <T extends AbsDatabasesBean> List<T> get(String table, String where, Class<T> tClass) {
|
||||
List<T> list = new ArrayList<>();
|
||||
try {
|
||||
Statement statement = conn.createStatement();
|
||||
@@ -197,24 +244,7 @@ public abstract class SQLiteManager {
|
||||
}
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
while (resultSet.next()) {
|
||||
JSONObject json = new JSONObject();
|
||||
for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) {
|
||||
String name = resultSet.getMetaData().getColumnName(i + 1);
|
||||
Object value = resultSet.getObject(name);
|
||||
if (value instanceof String && ((String) value).startsWith("[")) {
|
||||
try {
|
||||
json.put(name, JSON.parseArray((String) value));
|
||||
} catch (Exception e) {
|
||||
json.put(name, value);
|
||||
}
|
||||
} else {
|
||||
json.put(name, value);
|
||||
if (json.get(name) == null || "null".equals(json.get(name).toString())) {
|
||||
json.put(name, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
list.add(json.to(tClass));
|
||||
list.add(getSQL(resultSet).to(tClass));
|
||||
}
|
||||
resultSet.close();
|
||||
statement.closeOnCompletion();
|
||||
|
||||
@@ -18,20 +18,7 @@ import java.util.logging.Level;
|
||||
|
||||
public class HttpDownloadUtils {
|
||||
public static void download(Builder builder) {
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(2, TimeUnit.MINUTES)
|
||||
.readTimeout(2, TimeUnit.MINUTES)
|
||||
.build();
|
||||
Request.Builder rb = new Request.Builder()
|
||||
.get()
|
||||
.addHeader("User-Agent", ConfigTools.getUserAgent())
|
||||
.url(builder.url);
|
||||
if (StringUtils.hasText(builder.cookie)) {
|
||||
rb.addHeader("Set-Cookie", builder.cookie);
|
||||
}
|
||||
Request request = rb.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
call.enqueue(new Callback() {
|
||||
createHttpClient(builder).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
if (builder.downloadInterface != null) {
|
||||
@@ -79,6 +66,50 @@ public class HttpDownloadUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static File downloadSync(Builder builder) {
|
||||
createHttpClient(builder);
|
||||
try {
|
||||
Response response = createHttpClient(builder).execute();
|
||||
InputStream inputStream = Objects.requireNonNull(response.body()).byteStream();
|
||||
File target;
|
||||
if (StringUtils.hasText(builder.fileName)) {
|
||||
target = new File(builder.path, builder.fileName);
|
||||
} else {
|
||||
target = new File(builder.path);
|
||||
}
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(target)) {
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = inputStream.read(buffer)) != -1) {
|
||||
fileOutputStream.write(buffer, 0, len);
|
||||
}
|
||||
fileOutputStream.flush();
|
||||
return target;
|
||||
} catch (IOException e) {
|
||||
Log.e("download error:" + builder.url, e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Call createHttpClient(Builder builder) {
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(2, TimeUnit.MINUTES)
|
||||
.readTimeout(2, TimeUnit.MINUTES)
|
||||
.build();
|
||||
Request.Builder rb = new Request.Builder()
|
||||
.get()
|
||||
.addHeader("User-Agent", ConfigTools.getUserAgent())
|
||||
.url(builder.url);
|
||||
if (StringUtils.hasText(builder.cookie)) {
|
||||
rb.addHeader("Set-Cookie", builder.cookie);
|
||||
}
|
||||
Request request = rb.build();
|
||||
return okHttpClient.newCall(request);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Builder {
|
||||
String url;
|
||||
|
||||
Reference in New Issue
Block a user