update
This commit is contained in:
parent
96acb5826d
commit
6d00813311
12
pom.xml
12
pom.xml
@ -120,6 +120,18 @@
|
|||||||
<artifactId>log4j-core</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
<version>2.24.1</version>
|
<version>2.24.1</version>
|
||||||
</dependency>
|
</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 -->
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
@ -100,7 +100,7 @@ public class BiliLiveDatabase extends SQLiteManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addSource(WSData bean) {
|
public void addSource(WSData bean) {
|
||||||
Log.i("BiliLiveDatabase.addSource");
|
Log.i("BiliLiveDatabase.addSource",config.getRoomId());
|
||||||
add(new LiveSourceDatabaseBean(bean));
|
add(new LiveSourceDatabaseBean(bean));
|
||||||
addData(bean);
|
addData(bean);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import com.yutou.biliapi.api.LiveApi;
|
|||||||
import com.yutou.biliapi.bean.live.LiveDanmuInfo;
|
import com.yutou.biliapi.bean.live.LiveDanmuInfo;
|
||||||
import com.yutou.biliapi.bean.live.LiveRoomConfig;
|
import com.yutou.biliapi.bean.live.LiveRoomConfig;
|
||||||
import com.yutou.biliapi.bean.live.LiveRoomInfo;
|
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.WebSocketBody;
|
||||||
import com.yutou.biliapi.bean.websocket.WebSocketHeader;
|
import com.yutou.biliapi.bean.websocket.WebSocketHeader;
|
||||||
import com.yutou.biliapi.bean.websocket.live.WSData;
|
import com.yutou.biliapi.bean.websocket.live.WSData;
|
||||||
@ -66,6 +67,7 @@ public class WebSocketManager {
|
|||||||
array.addAll(roomMap.keySet());
|
array.addAll(roomMap.keySet());
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearUserStopList() {
|
public void clearUserStopList() {
|
||||||
userStopList.clear();
|
userStopList.clear();
|
||||||
}
|
}
|
||||||
@ -170,7 +172,7 @@ public class WebSocketManager {
|
|||||||
heartbeatTask.setSocket(this);
|
heartbeatTask.setSocket(this);
|
||||||
heartbeatTask.sendInitAuthData();
|
heartbeatTask.sendInitAuthData();
|
||||||
new Timer().schedule(heartbeatTask, 1000, 30000);
|
new Timer().schedule(heartbeatTask, 1000, 30000);
|
||||||
Log.i("WebSocketClientTh.onOpen");
|
Log.i("WebSocketClientTh.onOpen", roomConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -180,15 +182,14 @@ public class WebSocketManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(ByteBuffer bytes) {
|
public void onMessage(ByteBuffer bytes) {
|
||||||
// Log.i("WebSocketClientTh.onMessage: " + roomConfig.getAnchorName());
|
// Log.i("WebSocketClientTh.onMessage: " + roomConfig.getAnchorName());
|
||||||
super.onMessage(bytes);
|
super.onMessage(bytes);
|
||||||
decompress(bytes.array());
|
decompress(bytes.array());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose(int i, String s, boolean b) {
|
public void onClose(int i, String s, boolean b) {
|
||||||
Log.i("WebSocketClientTh.onClose");
|
Log.e("WebSocketClientTh.onClose", "i = " + i + ", s = " + s + ", b = " + b, roomConfig.getRoomId(), heartbeatTask.socket.isOpen());
|
||||||
Log.i("i = " + i + ", s = " + s + ", b = " + b);
|
|
||||||
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
||||||
liveDatabase.close();
|
liveDatabase.close();
|
||||||
heartbeatTask.cancel();
|
heartbeatTask.cancel();
|
||||||
@ -196,7 +197,7 @@ public class WebSocketManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception e) {
|
public void onError(Exception e) {
|
||||||
Log.i("WebSocketClientTh.onError");
|
Log.i("WebSocketClientTh.onError", roomConfig.getRoomId());
|
||||||
Log.e(e);
|
Log.e(e);
|
||||||
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
WebSocketManager.getInstance().roomMap.remove(roomConfig);
|
||||||
liveDatabase.close();
|
liveDatabase.close();
|
||||||
@ -280,7 +281,9 @@ public class WebSocketManager {
|
|||||||
} else {
|
} else {
|
||||||
json.put("uid", 0);
|
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) {
|
if (buvid != null) {
|
||||||
try {
|
try {
|
||||||
json.put("roomid", new BigInteger(roomConfig.getRoomId()));
|
json.put("roomid", new BigInteger(roomConfig.getRoomId()));
|
||||||
@ -298,7 +301,7 @@ public class WebSocketManager {
|
|||||||
outputStream.write(json.toJSONString().getBytes(StandardCharsets.UTF_8));
|
outputStream.write(json.toJSONString().getBytes(StandardCharsets.UTF_8));
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
// BytesUtils.printHex(outputStream.toByteArray());
|
// BytesUtils.printHex(outputStream.toByteArray());
|
||||||
Log.i(socket.isOpen());
|
Log.i(socket.isOpen(), json.toString());
|
||||||
socket.send(outputStream.toByteArray());
|
socket.send(outputStream.toByteArray());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -282,7 +282,7 @@ public class LiveVideoDownloadService {
|
|||||||
@Override
|
@Override
|
||||||
public void onDownload(File file) {
|
public void onDownload(File file) {
|
||||||
super.onDownload(file);
|
super.onDownload(file);
|
||||||
Log.e("下载完成 ");
|
Log.d("下载完成 ");
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -322,9 +322,9 @@ public class LiveVideoDownloadService {
|
|||||||
VideoFilePath path = createVideoRootFilePath(configBean, recordDir);
|
VideoFilePath path = createVideoRootFilePath(configBean, recordDir);
|
||||||
if (recordDir.exists()) {
|
if (recordDir.exists()) {
|
||||||
List<LiveVideoDatabaseBean> infos = database.getLiveInfos();
|
List<LiveVideoDatabaseBean> infos = database.getLiveInfos();
|
||||||
database.close();
|
|
||||||
path.setChildren(getVideoInfo(infos));
|
path.setChildren(getVideoInfo(infos));
|
||||||
}
|
}
|
||||||
|
database.close();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,6 +374,7 @@ public class LiveVideoDownloadService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
liveDatabase.close();
|
||||||
if(videoInfo != null) {
|
if(videoInfo != null) {
|
||||||
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath, new File(videoInfo.getPath()), ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
|
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath, new File(videoInfo.getPath()), ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
|
||||||
System.out.println(ffmpeg.getCommand());
|
System.out.println(ffmpeg.getCommand());
|
||||||
|
@ -29,7 +29,7 @@ public abstract class SQLiteManager {
|
|||||||
|
|
||||||
public abstract String getFileName();
|
public abstract String getFileName();
|
||||||
|
|
||||||
private BuildSql createBuildSQL(List<AbsDatabasesBean> data){
|
private BuildSql createBuildSQL(List<AbsDatabasesBean> data) {
|
||||||
List<BuildSqlItem> items;
|
List<BuildSqlItem> items;
|
||||||
List<BuildSqlTable> tables = new ArrayList<>();
|
List<BuildSqlTable> tables = new ArrayList<>();
|
||||||
for (AbsDatabasesBean bean : data) {
|
for (AbsDatabasesBean bean : data) {
|
||||||
@ -61,15 +61,16 @@ public abstract class SQLiteManager {
|
|||||||
tables.add(BuildSqlTable.create().setName(bean.getTableName()).setItem(items));
|
tables.add(BuildSqlTable.create().setName(bean.getTableName()).setItem(items));
|
||||||
}
|
}
|
||||||
|
|
||||||
return BuildSql.create()
|
return BuildSql.create()
|
||||||
.setFileName(getFileName())
|
.setFileName(getFileName())
|
||||||
.setTable(tables);
|
.setTable(tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
build(createBuildSQL(getDataBean()));
|
build(createBuildSQL(getDataBean()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recreateSql(List<AbsDatabasesBean> beans){
|
public void recreateSql(List<AbsDatabasesBean> beans) {
|
||||||
createSql(createBuildSQL(beans));
|
createSql(createBuildSQL(beans));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +152,7 @@ public abstract class SQLiteManager {
|
|||||||
statement.execute();
|
statement.execute();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Log.e(e);
|
Log.e(e,sb);
|
||||||
Log.e(sb);
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,12 +160,12 @@ public abstract class SQLiteManager {
|
|||||||
protected <T extends AbsDatabasesBean> void update(T t) {
|
protected <T extends AbsDatabasesBean> void update(T t) {
|
||||||
try {
|
try {
|
||||||
String id = DateUtils.format(t.getSql_time(), "yyyy-MM-dd HH:mm:ss.SSS");
|
String id = DateUtils.format(t.getSql_time(), "yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
if(id.endsWith("0")){
|
if (id.endsWith("0")) {
|
||||||
id=id.substring(0,id.length()-1);
|
id = id.substring(0, id.length() - 1);
|
||||||
}else if(id.endsWith("00")){
|
} else if (id.endsWith("00")) {
|
||||||
id=id.substring(0,id.length()-2);
|
id = id.substring(0, id.length() - 2);
|
||||||
}else if(id.endsWith("000")){
|
} else if (id.endsWith("000")) {
|
||||||
id=id.substring(0,id.length()-4);
|
id = id.substring(0, id.length() - 4);
|
||||||
}
|
}
|
||||||
Statement statement = getConnection().createStatement();
|
Statement statement = getConnection().createStatement();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@ -392,10 +392,11 @@ public abstract class SQLiteManager {
|
|||||||
config.enforceForeignKeys(true);
|
config.enforceForeignKeys(true);
|
||||||
conn = config.createConnection(url + sql.getAbsolutePath());
|
conn = config.createConnection(url + sql.getAbsolutePath());
|
||||||
}
|
}
|
||||||
protected Connection getConnection(){
|
|
||||||
|
protected Connection getConnection() {
|
||||||
try {
|
try {
|
||||||
if(conn.isClosed()){
|
if (conn.isClosed()) {
|
||||||
linkDB();
|
linkDB();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -55,7 +55,7 @@ public class HttpDownloadUtils {
|
|||||||
}
|
}
|
||||||
fileOutputStream.flush();
|
fileOutputStream.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e("download error:" + builder.url, e);
|
Log.e(e,"download error:", builder.url);
|
||||||
} finally {
|
} finally {
|
||||||
if (builder.downloadInterface != null) {
|
if (builder.downloadInterface != null) {
|
||||||
builder.downloadInterface.onDownload(target);
|
builder.downloadInterface.onDownload(target);
|
||||||
@ -86,7 +86,7 @@ public class HttpDownloadUtils {
|
|||||||
fileOutputStream.flush();
|
fileOutputStream.flush();
|
||||||
return target;
|
return target;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e("download error:" + builder.url, e);
|
Log.e(e,"download error:" , builder.url);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -259,10 +259,10 @@ public class AppTools {
|
|||||||
File srcFile = new File(srcFileName);
|
File srcFile = new File(srcFileName);
|
||||||
// 判断源文件是否存在
|
// 判断源文件是否存在
|
||||||
if (!srcFile.exists()) {
|
if (!srcFile.exists()) {
|
||||||
Log.e("源文件不存在:"+srcFile.getAbsolutePath()+" > "+destFileName);
|
Log.d(AppTools.class,"源文件不存在:",srcFile.getAbsolutePath()," > ",destFileName);
|
||||||
return false;
|
return false;
|
||||||
} else if (!srcFile.isFile()) {
|
} else if (!srcFile.isFile()) {
|
||||||
Log.e("源文件是目录:"+srcFile.getAbsolutePath());
|
Log.d("源文件是目录:"+srcFile.getAbsolutePath());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ public class AppTools {
|
|||||||
// 目标文件所在目录不存在
|
// 目标文件所在目录不存在
|
||||||
if (!destFile.mkdirs()) {
|
if (!destFile.mkdirs()) {
|
||||||
// 复制文件失败:创建目标文件所在目录失败
|
// 复制文件失败:创建目标文件所在目录失败
|
||||||
Log.e("创建文件夹失败:"+destFile.getAbsolutePath());
|
Log.d("创建文件夹失败:"+destFile.getAbsolutePath());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
//获取视频时长:ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
|
||||||
//获取到结果:5372.432000
|
//获取到结果:5372.432000
|
||||||
if (downloadInterface != null) {
|
if (downloadInterface != null) {
|
||||||
Log.i("触发下载完成");
|
Log.i("触发下载完成",command);
|
||||||
downloadInterface.onDownload(null);
|
downloadInterface.onDownload(null);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1,62 +1,69 @@
|
|||||||
package com.yutou.common.utils;
|
package com.yutou.common.utils;
|
||||||
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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 {
|
public class Log {
|
||||||
private static Logger logger = LoggerFactory.getLogger("Biliob");
|
|
||||||
|
|
||||||
public static void i() {
|
public static void i() {
|
||||||
i("\n");
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void i(String tag, Object log) {
|
public static void i(Object... log) {
|
||||||
i('[' + tag + ']' + log);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void i(Object log) {
|
|
||||||
if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "logcat"))) {
|
if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "logcat"))) {
|
||||||
return;
|
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)) {
|
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
|
||||||
return;
|
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) {
|
public static void e(Throwable e) {
|
||||||
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
|
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
|
||||||
return;
|
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) {
|
public static void d(Object... log) {
|
||||||
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
|
if (!ConfigTools.load(ConfigTools.CONFIG, "logcat", Boolean.class)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (log.length > 1) {
|
LogManager.getLogger().debug(buildLog(log));
|
||||||
logger.debug(log[0].toString(), log);
|
|
||||||
} else {
|
|
||||||
logger.debug(log[0].toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getStackTrace() {
|
private static String getStackTrace() {
|
||||||
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
|
StackTraceElement element = StackLocatorUtil.getStackTraceElement(3);
|
||||||
if (stackTrace.length > 3) {
|
return "(" + element.getFileName() + ":" + element.getLineNumber() + ")";
|
||||||
StackTraceElement element = stackTrace[3];
|
}
|
||||||
return " " + element.getClassName() + "." + element.getMethodName() + "#" + 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1,3 @@
|
|||||||
server.port=8880
|
server.port=8880
|
||||||
|
logging.file.path=./logs
|
||||||
|
logging.level.com.log.controller = trace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user