This commit is contained in:
zlzw 2024-11-04 18:21:16 +08:00
parent 96acb5826d
commit 6d00813311
10 changed files with 83 additions and 57 deletions

12
pom.xml
View File

@ -120,6 +120,18 @@
<artifactId>log4j-core</artifactId>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.24.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.24.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>

View File

@ -100,7 +100,7 @@ public class BiliLiveDatabase extends SQLiteManager {
}
public void addSource(WSData bean) {
Log.i("BiliLiveDatabase.addSource");
Log.i("BiliLiveDatabase.addSource",config.getRoomId());
add(new LiveSourceDatabaseBean(bean));
addData(bean);
}

View File

@ -10,6 +10,7 @@ import com.yutou.biliapi.api.LiveApi;
import com.yutou.biliapi.bean.live.LiveDanmuInfo;
import com.yutou.biliapi.bean.live.LiveRoomConfig;
import com.yutou.biliapi.bean.live.LiveRoomInfo;
import com.yutou.biliapi.bean.login.LoginCookieDatabaseBean;
import com.yutou.biliapi.bean.websocket.WebSocketBody;
import com.yutou.biliapi.bean.websocket.WebSocketHeader;
import com.yutou.biliapi.bean.websocket.live.WSData;
@ -66,6 +67,7 @@ public class WebSocketManager {
array.addAll(roomMap.keySet());
return array;
}
public void clearUserStopList() {
userStopList.clear();
}
@ -170,7 +172,7 @@ public class WebSocketManager {
heartbeatTask.setSocket(this);
heartbeatTask.sendInitAuthData();
new Timer().schedule(heartbeatTask, 1000, 30000);
Log.i("WebSocketClientTh.onOpen");
Log.i("WebSocketClientTh.onOpen", roomConfig);
}
@Override
@ -180,15 +182,14 @@ public class WebSocketManager {
@Override
public void onMessage(ByteBuffer bytes) {
// Log.i("WebSocketClientTh.onMessage: " + roomConfig.getAnchorName());
// Log.i("WebSocketClientTh.onMessage: " + roomConfig.getAnchorName());
super.onMessage(bytes);
decompress(bytes.array());
}
@Override
public void onClose(int i, String s, boolean b) {
Log.i("WebSocketClientTh.onClose");
Log.i("i = " + i + ", s = " + s + ", b = " + b);
Log.e("WebSocketClientTh.onClose", "i = " + i + ", s = " + s + ", b = " + b, roomConfig.getRoomId(), heartbeatTask.socket.isOpen());
WebSocketManager.getInstance().roomMap.remove(roomConfig);
liveDatabase.close();
heartbeatTask.cancel();
@ -196,7 +197,7 @@ public class WebSocketManager {
@Override
public void onError(Exception e) {
Log.i("WebSocketClientTh.onError");
Log.i("WebSocketClientTh.onError", roomConfig.getRoomId());
Log.e(e);
WebSocketManager.getInstance().roomMap.remove(roomConfig);
liveDatabase.close();
@ -280,7 +281,9 @@ public class WebSocketManager {
} else {
json.put("uid", 0);
}
String buvid = BiliUserUtils.getBuvid(BiliBiliLoginDatabase.getInstance().getCookie(roomConfig.getLoginUid()));
LoginCookieDatabaseBean cookie = BiliBiliLoginDatabase.getInstance().getCookie(roomConfig.getLoginUid());
Log.d("cookie:", cookie, "RoomId:" + roomConfig);
String buvid = BiliUserUtils.getBuvid(cookie);
if (buvid != null) {
try {
json.put("roomid", new BigInteger(roomConfig.getRoomId()));
@ -298,7 +301,7 @@ public class WebSocketManager {
outputStream.write(json.toJSONString().getBytes(StandardCharsets.UTF_8));
outputStream.flush();
// BytesUtils.printHex(outputStream.toByteArray());
Log.i(socket.isOpen());
Log.i(socket.isOpen(), json.toString());
socket.send(outputStream.toByteArray());
} catch (Exception e) {

View File

@ -282,7 +282,7 @@ public class LiveVideoDownloadService {
@Override
public void onDownload(File file) {
super.onDownload(file);
Log.e("下载完成 ");
Log.d("下载完成 ");
stop();
}
});
@ -322,9 +322,9 @@ public class LiveVideoDownloadService {
VideoFilePath path = createVideoRootFilePath(configBean, recordDir);
if (recordDir.exists()) {
List<LiveVideoDatabaseBean> infos = database.getLiveInfos();
database.close();
path.setChildren(getVideoInfo(infos));
}
database.close();
return path;
}
@ -374,6 +374,7 @@ public class LiveVideoDownloadService {
break;
}
}
liveDatabase.close();
if(videoInfo != null) {
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath, new File(videoInfo.getPath()), ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
System.out.println(ffmpeg.getCommand());

View File

@ -29,7 +29,7 @@ public abstract class SQLiteManager {
public abstract String getFileName();
private BuildSql createBuildSQL(List<AbsDatabasesBean> data){
private BuildSql createBuildSQL(List<AbsDatabasesBean> data) {
List<BuildSqlItem> items;
List<BuildSqlTable> tables = new ArrayList<>();
for (AbsDatabasesBean bean : data) {
@ -61,15 +61,16 @@ public abstract class SQLiteManager {
tables.add(BuildSqlTable.create().setName(bean.getTableName()).setItem(items));
}
return BuildSql.create()
return BuildSql.create()
.setFileName(getFileName())
.setTable(tables);
}
public void init() {
build(createBuildSQL(getDataBean()));
}
public void recreateSql(List<AbsDatabasesBean> beans){
public void recreateSql(List<AbsDatabasesBean> beans) {
createSql(createBuildSQL(beans));
}
@ -151,8 +152,7 @@ public abstract class SQLiteManager {
statement.execute();
statement.close();
} catch (SQLException e) {
Log.e(e);
Log.e(sb);
Log.e(e,sb);
throw new RuntimeException(e);
}
}
@ -160,12 +160,12 @@ public abstract class SQLiteManager {
protected <T extends AbsDatabasesBean> void update(T t) {
try {
String id = DateUtils.format(t.getSql_time(), "yyyy-MM-dd HH:mm:ss.SSS");
if(id.endsWith("0")){
id=id.substring(0,id.length()-1);
}else if(id.endsWith("00")){
id=id.substring(0,id.length()-2);
}else if(id.endsWith("000")){
id=id.substring(0,id.length()-4);
if (id.endsWith("0")) {
id = id.substring(0, id.length() - 1);
} else if (id.endsWith("00")) {
id = id.substring(0, id.length() - 2);
} else if (id.endsWith("000")) {
id = id.substring(0, id.length() - 4);
}
Statement statement = getConnection().createStatement();
StringBuilder sb = new StringBuilder();
@ -392,10 +392,11 @@ public abstract class SQLiteManager {
config.enforceForeignKeys(true);
conn = config.createConnection(url + sql.getAbsolutePath());
}
protected Connection getConnection(){
protected Connection getConnection() {
try {
if(conn.isClosed()){
linkDB();
if (conn.isClosed()) {
linkDB();
}
} catch (SQLException e) {
throw new RuntimeException(e);

View File

@ -55,7 +55,7 @@ public class HttpDownloadUtils {
}
fileOutputStream.flush();
} catch (IOException e) {
Log.e("download error:" + builder.url, e);
Log.e(e,"download error:", builder.url);
} finally {
if (builder.downloadInterface != null) {
builder.downloadInterface.onDownload(target);
@ -86,7 +86,7 @@ public class HttpDownloadUtils {
fileOutputStream.flush();
return target;
} catch (IOException e) {
Log.e("download error:" + builder.url, e);
Log.e(e,"download error:" , builder.url);
}
} catch (IOException e) {
throw new RuntimeException(e);

View File

@ -259,10 +259,10 @@ public class AppTools {
File srcFile = new File(srcFileName);
// 判断源文件是否存在
if (!srcFile.exists()) {
Log.e("源文件不存在:"+srcFile.getAbsolutePath()+" > "+destFileName);
Log.d(AppTools.class,"源文件不存在:",srcFile.getAbsolutePath()," > ",destFileName);
return false;
} else if (!srcFile.isFile()) {
Log.e("源文件是目录:"+srcFile.getAbsolutePath());
Log.d("源文件是目录:"+srcFile.getAbsolutePath());
return false;
}
@ -273,7 +273,7 @@ public class AppTools {
// 目标文件所在目录不存在
if (!destFile.mkdirs()) {
// 复制文件失败创建目标文件所在目录失败
Log.e("创建文件夹失败:"+destFile.getAbsolutePath());
Log.d("创建文件夹失败:"+destFile.getAbsolutePath());
return false;
}

View File

@ -161,7 +161,7 @@ public class FFmpegUtils extends AbsVideoRecord {
//获取视频时长ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
//获取到结果:5372.432000
if (downloadInterface != null) {
Log.i("触发下载完成");
Log.i("触发下载完成",command);
downloadInterface.onDownload(null);
}
} catch (Exception e) {

View File

@ -1,62 +1,69 @@
package com.yutou.common.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.util.StackLocatorUtil;
public class Log {
private static Logger logger = LoggerFactory.getLogger("Biliob");
public static void i() {
i("\n");
System.out.println();
}
public static void i(String tag, Object log) {
i('[' + tag + ']' + log);
}
public static void i(Object log) {
public static void i(Object... log) {
if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "logcat"))) {
return;
}
logger.info(log.toString());
LogManager.getLogger(getStackTrace()).info(buildLog(log));
}
public static void e(Object log) {
public static void e(Object... log) {
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
return;
}
logger.error(getStackTrace(),log);
LogManager.getLogger(getStackTrace()).error(buildLog(log));
}
public static void e(Throwable e, Object... log) {
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
return;
}
LogManager.getLogger(getStackTrace()).error(buildLog(log), e);
}
public static void e(Throwable e) {
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
return;
}
logger.error(getStackTrace(), e);
LogManager.getLogger().error(getStackTrace(), e);
}
public static void e(String tag, Throwable e) {
logger.error("{}\n{}", tag, getStackTrace(), e);
}
public static void d(Object... log) {
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
return;
}
if (log.length > 1) {
logger.debug(log[0].toString(), log);
} else {
logger.debug(log[0].toString());
}
LogManager.getLogger().debug(buildLog(log));
}
private static String getStackTrace() {
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
if (stackTrace.length > 3) {
StackTraceElement element = stackTrace[3];
return " " + element.getClassName() + "." + element.getMethodName() + "#" + element.getLineNumber();
StackTraceElement element = StackLocatorUtil.getStackTraceElement(3);
return "(" + element.getFileName() + ":" + element.getLineNumber() + ")";
}
private static String buildLog(Object... log) {
StringBuilder sb = new StringBuilder();
for (Object obj : log) {
if (!sb.isEmpty()) {
sb.append("\n");
}
sb.append(obj);
}
return "";
return sb.toString();
}
}

View File

@ -1 +1,3 @@
server.port=8880
server.port=8880
logging.file.path=./logs
logging.level.com.log.controller = trace