update
This commit is contained in:
@@ -3,10 +3,12 @@ package com.yutou.biliapi.bean.live.database;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.alibaba.fastjson2.util.DateUtils;
|
||||
import com.yutou.bilibili.Tools.DateFormatUtils;
|
||||
import com.yutou.bilibili.Tools.Tools;
|
||||
import com.yutou.common.databases.AbsDatabasesBean;
|
||||
import com.yutou.common.utils.Log;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigInteger;
|
||||
@@ -37,7 +39,7 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
|
||||
private boolean isRecordDanmu;
|
||||
@JSONField(name = "keyword")
|
||||
private List<String> keywordList;
|
||||
@JSONField(name = "week")
|
||||
@JSONField(name = "weeks")
|
||||
private List<String> weeks;
|
||||
@JSONField(name = "recordPath")
|
||||
private String recordPath = "live";
|
||||
@@ -56,11 +58,11 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
|
||||
}
|
||||
|
||||
public boolean checkRecordDanmuTime() {
|
||||
return checkRecordTime(recordDanmuDate);
|
||||
return DateFormatUtils.checkTime(weeks,recordDanmuDate);
|
||||
}
|
||||
|
||||
public boolean checkRecordLiveTime() {
|
||||
return checkRecordTime(recordLiveDate);
|
||||
return DateFormatUtils.checkTime(weeks,recordLiveDate);
|
||||
}
|
||||
|
||||
public boolean verifyDanmuTimer() {
|
||||
@@ -85,36 +87,13 @@ public class LiveConfigDatabaseBean extends AbsDatabasesBean {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkRecordTime(String recordDate) {
|
||||
//TODO 待测试
|
||||
String[] parts = recordDate.split(" - ");
|
||||
LocalTime startTime = LocalTime.parse(parts[0], DateTimeFormatter.ofPattern("HH:mm:ss"));
|
||||
LocalTime endTime = LocalTime.parse(parts[1], DateTimeFormatter.ofPattern("HH:mm:ss"));
|
||||
|
||||
|
||||
// 获取当前时间
|
||||
LocalTime currentTime = LocalTime.now();
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
|
||||
|
||||
// 获取当前日期对应的星期几(1-7分别对应周一到周日)
|
||||
int currentWeekDay = currentDate.getDayOfWeek().getValue();
|
||||
|
||||
// 判断当前日期是否在指定的星期列表中
|
||||
boolean isSpecifiedWeekDay = weeks.contains(String.valueOf(currentWeekDay));
|
||||
|
||||
|
||||
// 判断当前时间是否在指定的时间范围内
|
||||
boolean isWithinRange = (currentTime.isAfter(startTime) || currentTime.equals(startTime)) &&
|
||||
(currentTime.isBefore(endTime) || currentTime.equals(endTime));
|
||||
return isWithinRange && isSpecifiedWeekDay;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String t = "18:00:00 - 23:59:59";
|
||||
List<String> weeks = Arrays.asList("1", "2", "3", "9", "5", "6", "7");
|
||||
String t = "18:00:00 - 19:59:59";
|
||||
t=null;
|
||||
List<String> weeks = Arrays.asList("1", "2", "3", "4", "5", "6", "7");
|
||||
LiveConfigDatabaseBean bean=new LiveConfigDatabaseBean();
|
||||
bean.setWeeks(weeks);
|
||||
System.out.println(bean.checkRecordTime(t));
|
||||
System.out.println(DateFormatUtils.checkTime(weeks,t));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class BiliLiveConfigDatabase extends SQLiteManager {
|
||||
}
|
||||
|
||||
public LiveConfigDatabaseBean getConfig(String roomId) {
|
||||
List<LiveConfigDatabaseBean> list = get(getDataBean().get(0).getTableName(), LiveConfigDatabaseBean.class);
|
||||
List<LiveConfigDatabaseBean> list = get(getDataBean().getFirst().getTableName(), LiveConfigDatabaseBean.class);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -61,14 +61,23 @@ public class BiliLiveConfigDatabase extends SQLiteManager {
|
||||
}
|
||||
return delete(config);
|
||||
}
|
||||
|
||||
public List<LiveConfigDatabaseBean> getAllConfig() {
|
||||
List<LiveConfigDatabaseBean> list = get(getDataBean().get(0).getTableName(), LiveConfigDatabaseBean.class);
|
||||
public List<LiveConfigDatabaseBean> getConfigs(int page,int limit) {
|
||||
int offset = (page - 1) * limit;
|
||||
List<LiveConfigDatabaseBean> list = get(getDataBean().getFirst().getTableName(),"`sql_time` >0 limit "+limit+" offset "+offset, LiveConfigDatabaseBean.class);
|
||||
if (list.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<LiveConfigDatabaseBean> getAllConfig() {
|
||||
List<LiveConfigDatabaseBean> list = get(getDataBean().getFirst().getTableName(), LiveConfigDatabaseBean.class);
|
||||
if (list.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public int getConfigCount() {
|
||||
return getCount(getDataBean().getFirst().getTableName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ public class WebSocketManager {
|
||||
array.addAll(roomMap.keySet());
|
||||
return array;
|
||||
}
|
||||
public void clearUserStopList() {
|
||||
userStopList.clear();
|
||||
}
|
||||
|
||||
public void addRoom(LiveRoomConfig roomConfig, boolean isUser) {
|
||||
if (!isUser && userStopList.contains(roomConfig.getRoomId().toString())) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.yutou.bilibili.datas.ResultData;
|
||||
import com.yutou.bilibili.datas.ReturnCode;
|
||||
import com.yutou.bilibili.services.LiveConfigService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.val;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@@ -69,19 +71,19 @@ public class LiveConfigController {
|
||||
if ("0".equals(roomId) || !StringUtils.hasText(roomId)) {
|
||||
return ResultData.fail(ReturnCode.RC999);
|
||||
}
|
||||
LiveConfigDatabaseBean config = configService.getConfig(new String(roomId));
|
||||
LiveConfigDatabaseBean config = configService.getConfig(roomId);
|
||||
if (config != null) {
|
||||
return ResultData.success(config.toJson());
|
||||
return ResultData.success(config);
|
||||
}
|
||||
return ResultData.fail(ReturnCode.RC999);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "all", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public JSONObject getAllConfig() {
|
||||
List<LiveConfigDatabaseBean> config = configService.getAllConfig();
|
||||
public JSONObject getAllConfig(int page,int limit) {
|
||||
List<LiveConfigDatabaseBean> config = configService.getConfigs(page, limit);
|
||||
if (config != null) {
|
||||
return ResultData.success(config);
|
||||
return ResultData.success(config,configService.getConfigCount());
|
||||
}
|
||||
return ResultData.fail(ReturnCode.RC999);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.yutou.bilibili.services.LiveDanmuService;
|
||||
import com.yutou.bilibili.services.LiveService;
|
||||
import com.yutou.bilibili.services.LiveVideoService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.val;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@@ -25,8 +26,7 @@ public class LiveController {
|
||||
|
||||
@RequestMapping("/live/list")
|
||||
@ResponseBody
|
||||
public JSONObject getLiveList(){
|
||||
|
||||
return ResultData.success(liveService.getLiveList());
|
||||
public JSONObject getLiveList(int page,int limit) {
|
||||
return ResultData.success(liveService.getLiveList(page,limit), liveService.getConfigCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.yutou.common.utils.AppTools;
|
||||
import com.yutou.common.utils.Base64Tools;
|
||||
import com.yutou.common.utils.Log;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.val;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -21,9 +22,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@@ -72,5 +77,35 @@ public class VideoFileController {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@RequestMapping(value = "/file/imgTmp", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public String getTmpImg(String url) {
|
||||
try {
|
||||
// 获取图片流
|
||||
InputStream inputStream = new URL(url).openStream();
|
||||
|
||||
// 将输入流转换为字节数组
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer)) != -1) {
|
||||
byteArrayOutputStream.write(buffer, 0, length);
|
||||
}
|
||||
byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
||||
|
||||
// 关闭输入流
|
||||
inputStream.close();
|
||||
byteArrayOutputStream.close();
|
||||
|
||||
// 将字节数组编码为 Base64 字符串
|
||||
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
|
||||
|
||||
// 返回带有 MIME 类型的数据 URI
|
||||
return base64Image;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.yutou.bilibili.Tools;
|
||||
|
||||
import com.yutou.common.utils.Log;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DateFormatUtils {
|
||||
public static String format(Date date, String format) {
|
||||
@@ -38,4 +43,37 @@ public class DateFormatUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkTime(List<String> weeks, String recordDate) {
|
||||
if (!StringUtils.hasText(recordDate)) {
|
||||
recordDate = "00:00:00 - 23:59:59";
|
||||
}
|
||||
String[] parts = recordDate.split(" - ");
|
||||
LocalTime startTime = LocalTime.parse(parts[0], DateTimeFormatter.ofPattern("HH:mm:ss"));
|
||||
LocalTime endTime = LocalTime.parse(parts[1], DateTimeFormatter.ofPattern("HH:mm:ss"));
|
||||
|
||||
|
||||
// 获取当前时间
|
||||
LocalTime currentTime = LocalTime.now();
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
|
||||
|
||||
// 获取当前日期对应的星期几(1-7分别对应周一到周日)
|
||||
int currentWeekDay = currentDate.getDayOfWeek().getValue();
|
||||
|
||||
// 判断当前日期是否在指定的星期列表中
|
||||
boolean isSpecifiedWeekDay;
|
||||
if (weeks == null) {
|
||||
isSpecifiedWeekDay = true;
|
||||
} else {
|
||||
isSpecifiedWeekDay = weeks.contains(String.valueOf(currentWeekDay));
|
||||
}
|
||||
|
||||
// 判断当前时间是否在指定的时间范围内
|
||||
boolean isWithinRange = (currentTime.isAfter(startTime) || currentTime.equals(startTime)) &&
|
||||
(currentTime.isBefore(endTime) || currentTime.equals(endTime));
|
||||
return isWithinRange && isSpecifiedWeekDay;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,11 @@ public class ResultData<T> {
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
public static <T> JSONObject success(T data) {
|
||||
return success(data, -1);
|
||||
}
|
||||
|
||||
public static <T> JSONObject success(T data, int count) {
|
||||
ResultData<T> resultData = new ResultData<>();
|
||||
resultData.setStatus(ReturnCode.RC100.getCode());
|
||||
resultData.setMessage(ReturnCode.RC100.getMessage());
|
||||
@@ -28,6 +31,9 @@ public class ResultData<T> {
|
||||
if (data instanceof Collection<?>) {
|
||||
resultData.count = ((Collection<?>) data).size();
|
||||
}
|
||||
if (count != -1) {
|
||||
resultData.count = count;
|
||||
}
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(resultData));
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,9 @@ public class LiveConfigService {
|
||||
public List<LiveConfigDatabaseBean> getAllConfig() {
|
||||
return database.getAllConfig();
|
||||
}
|
||||
public List<LiveConfigDatabaseBean> getConfigs(int page,int limit) {
|
||||
return database.getConfigs(page, limit);
|
||||
}
|
||||
|
||||
public LiveConfigDatabaseBean getConfig(String roomId) {
|
||||
return database.getConfig(roomId);
|
||||
@@ -97,4 +100,8 @@ public class LiveConfigService {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int getConfigCount() {
|
||||
return database.getConfigCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,9 @@ public class LiveDanmuService {
|
||||
public JSONArray getLiveRoomList() {
|
||||
return WebSocketManager.getInstance().getLiveRoomList();
|
||||
}
|
||||
|
||||
public void clearUserList(){
|
||||
WebSocketManager.getInstance().clearUserStopList();
|
||||
}
|
||||
|
||||
public List<File> getDanmuFileList(String roomId) {
|
||||
BiliLiveConfigDatabase configDatabase=new BiliLiveConfigDatabase();
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.yutou.common.okhttp.HttpBody;
|
||||
import com.yutou.common.utils.AppTools;
|
||||
import com.yutou.common.utils.Log;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.val;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -29,9 +30,11 @@ public class LiveService {
|
||||
liveConfigDatabase = new BiliLiveConfigDatabase();
|
||||
api = BiliLiveNetApiManager.getInstance().getApi(null);
|
||||
}
|
||||
|
||||
public List<LiveData> getLiveList() {
|
||||
List<LiveConfigDatabaseBean> allConfig = liveConfigDatabase.getAllConfig();
|
||||
public int getConfigCount(){
|
||||
return liveConfigDatabase.getAllConfig().size();
|
||||
}
|
||||
public List<LiveData> getLiveList(int page,int limit) {
|
||||
List<LiveConfigDatabaseBean> allConfig = liveConfigDatabase.getConfigs(page,limit);
|
||||
List<LiveData> liveDataList = new ArrayList<>();
|
||||
for (LiveConfigDatabaseBean config : allConfig) {
|
||||
LiveData liveData = new LiveData();
|
||||
|
||||
@@ -60,6 +60,9 @@ public class LiveVideoService {
|
||||
public boolean checkDownload(String roomId) {
|
||||
return videoRecord.check(roomId);
|
||||
}
|
||||
public void clearUserStopList() {
|
||||
userStopList.clear();
|
||||
}
|
||||
|
||||
public void start(LiveConfigDatabaseBean bean, boolean isUser) {
|
||||
if (!isUser && userStopList.contains(bean.getRoomId().toString())) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
|
||||
import com.yutou.biliapi.databases.BiliLiveConfigDatabase;
|
||||
import com.yutou.biliapi.net.BiliLiveNetApiManager;
|
||||
import com.yutou.biliapi.net.WebSocketManager;
|
||||
import com.yutou.bilibili.Tools.DateFormatUtils;
|
||||
import com.yutou.bilibili.databases.SystemConfigDatabases;
|
||||
import com.yutou.bilibili.datas.SystemConfigDatabaseBean;
|
||||
import com.yutou.common.okhttp.HttpBody;
|
||||
@@ -45,6 +46,8 @@ public class SystemService {
|
||||
return config.getTimerLoop();
|
||||
}
|
||||
|
||||
private final String resetTimer = "00:00:00 - 00:01:00";
|
||||
|
||||
public void start() {
|
||||
if (timer == null) {
|
||||
timer = Executors.newScheduledThreadPool(1);
|
||||
@@ -56,6 +59,10 @@ public class SystemService {
|
||||
scheduled = timer.scheduleAtFixedRate(() -> {
|
||||
List<LiveConfigDatabaseBean> list = liveConfigDatabase.getAllConfig();
|
||||
Log.i("循环任务:" + list.size());
|
||||
if(DateFormatUtils.checkTime(null,resetTimer)){
|
||||
videoService.clearUserStopList();
|
||||
danmuService.clearUserList();
|
||||
}
|
||||
for (LiveConfigDatabaseBean bean : list) {
|
||||
try {
|
||||
if (bean.isRecordDanmu() && bean.checkRecordDanmuTime()) {
|
||||
|
||||
@@ -234,6 +234,22 @@ public abstract class SQLiteManager {
|
||||
return get(table, null, tClass);
|
||||
}
|
||||
|
||||
protected int getCount(String table) {
|
||||
try (PreparedStatement preparedStatement = conn.prepareStatement("SELECT count(*) FROM "+table)) {
|
||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt(1);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Log.e(e);
|
||||
throw new RuntimeException("Error executing SQL query", e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected <T extends AbsDatabasesBean> List<T> get(String table, String where, Class<T> tClass) {
|
||||
List<T> list = new ArrayList<>();
|
||||
try {
|
||||
@@ -242,6 +258,7 @@ public abstract class SQLiteManager {
|
||||
if (where != null) {
|
||||
sql += " WHERE " + where;
|
||||
}
|
||||
System.out.println("sql = " + sql);
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
while (resultSet.next()) {
|
||||
list.add(getSQL(resultSet).to(tClass));
|
||||
|
||||
Reference in New Issue
Block a user