StartConfig.java
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package top.panll.assist.config;
import net.bramp.ffmpeg.FFmpeg;
import net.bramp.ffmpeg.FFprobe;
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import top.panll.assist.dto.UserSettings;
import top.panll.assist.service.FFmpegExecUtils;
import top.panll.assist.service.VideoFileService;
import java.io.File;
import java.io.IOException;
/**
* 用于启动检查环境
*/
@Component
@Order(value=1)
public class StartConfig implements CommandLineRunner {
private final static Logger logger = LoggerFactory.getLogger(StartConfig.class);
@Autowired
private UserSettings userSettings;
@Autowired
private VideoFileService videoFileService;
@Override
public void run(String... args) {
String record = userSettings.getRecord();
File recordFile = new File(record);
if (!recordFile.exists() || !recordFile.isDirectory()) {
logger.error("[userSettings.record]配置错误,请检查路径是否存在");
System.exit(1);
}
if (!recordFile.canRead()) {
logger.error("[userSettings.record]路径无法读取");
System.exit(1);
}
if (!recordFile.canWrite()) {
logger.error("[userSettings.record]路径无法写入");
System.exit(1);
}
try {
String ffmpegPath = userSettings.getFfmpeg();
String ffprobePath = userSettings.getFfprobe();
FFmpeg ffmpeg = new FFmpeg(ffmpegPath);
FFprobe ffprobe = new FFprobe(ffprobePath);
logger.info("wvp-pro辅助程序启动成功。 \n{}\n{} ", ffmpeg.version(), ffprobe.version());
FFmpegExecUtils.getInstance().ffmpeg = ffmpeg;
FFmpegExecUtils.getInstance().ffprobe = ffprobe;
// 对目录进行预整理
File[] appFiles = recordFile.listFiles();
if (appFiles != null && appFiles.length > 0) {
for (File appFile : appFiles) {
File[] streamFiles = appFile.listFiles();
if (streamFiles != null && streamFiles.length > 0) {
for (File streamFile : streamFiles) {
File[] dateFiles = streamFile.listFiles();
if (dateFiles != null && dateFiles.length > 0) {
for (File dateFile : dateFiles) {
File[] files = dateFile.listFiles();
if (files != null && files.length > 0) {
for (File file : files) {
videoFileService.handFile(file);
}
}
}
}
}
}
}
}
}catch (IOException exception){
System.out.println(exception.getMessage());
if (exception.getMessage().indexOf("ffmpeg") > 0 ) {
logger.error("[userSettings.ffmpeg]配置错误,请检查是否已安装ffmpeg并正确配置");
System.exit(1);
}
if (exception.getMessage().indexOf("ffprobe") > 0 ) {
logger.error("[userSettings.ffprobe]配置错误,请检查是否已安装ffprobe并正确配置");
System.exit(1);
}
}catch (Exception exception){
exception.printStackTrace();
logger.error("环境错误: " + exception.getMessage());
}
}
}