add info checker.
Some checks failed
Deploy Applications / PullDocker (push) Failing after 9s
Deploy Applications / Build (push) Failing after 4s
Windows CI / build (push) Has been cancelled

This commit is contained in:
2025-11-10 19:29:40 +08:00
parent 8c2c912d3a
commit 482e5495f0
4 changed files with 132 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
CompileFlags:
CompilationDatabase: build
Add: [
"-I/opt/Libraries/boost_1_89_0/include",
"-I/opt/3rdparty/boost_1_89_0/include",
]

View File

@@ -19,3 +19,7 @@ add_executable(shifter
target_link_libraries(shifter
PRIVATE Boost::program_options
)
add_executable(infoer
Infoer.cpp
)

124
Infoer.cpp Normal file
View File

@@ -0,0 +1,124 @@
#include <algorithm>
#include <filesystem>
#include <iostream>
#include <map>
#include <string>
#include <vector>
namespace fs = std::filesystem;
class AdvancedNfoFileChecker {
private:
std::vector<std::string> videoExtensions = {".avi", ".m2ts", ".mkv", ".mp4", ".ts"};
std::map<std::string, bool> checkResults;
public:
bool isVideoFile(const fs::path &filePath) {
std::string extension = filePath.extension().string();
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
return std::find(videoExtensions.begin(), videoExtensions.end(), extension) != videoExtensions.end();
}
bool hasNfoFile(const fs::path &videoPath) {
fs::path nfoPath = videoPath;
nfoPath.replace_extension(".nfo");
return fs::exists(nfoPath);
}
void checkFolderRecursive(const std::string &folderPath, bool recursive = false) {
checkResults.clear();
int totalVideoFiles = 0;
int missingNfoCount = 0;
try {
auto iterator = fs::directory_iterator(folderPath);
for (const auto &entry : iterator) {
if (entry.is_regular_file()) {
fs::path filePath = entry.path();
if (isVideoFile(filePath)) {
totalVideoFiles++;
bool hasNfo = hasNfoFile(filePath);
checkResults[filePath.string()] = hasNfo;
if (!hasNfo) {
missingNfoCount++;
}
}
}
}
printResults(totalVideoFiles, missingNfoCount);
} catch (const fs::filesystem_error &ex) {
std::cerr << "错误:无法访问文件夹 '" << folderPath << "'" << std::endl;
std::cerr << "详细信息: " << ex.what() << std::endl;
}
}
private:
void printResults(int totalVideoFiles, int missingNfoCount) {
std::cout << "检查结果:" << std::endl;
std::cout << "==========================================" << std::endl;
std::cout << "总视频文件数: " << totalVideoFiles << std::endl;
std::cout << "缺少.nfo的文件数: " << missingNfoCount << std::endl;
std::cout << "完整率: " << (totalVideoFiles - missingNfoCount) * 100 / std::max(1, totalVideoFiles) << "%"
<< std::endl;
std::cout << "==========================================" << std::endl;
if (missingNfoCount > 0) {
std::cout << "缺少.nfo文件的视频文件" << std::endl;
for (const auto &[filepath, hasNfo] : checkResults) {
if (!hasNfo) {
std::cout << "" << fs::path(filepath).filename().string() << std::endl;
}
}
} else if (totalVideoFiles > 0) {
std::cout << "✓ 所有视频文件都有对应的.nfo文件" << std::endl;
} else {
std::cout << "! 在指定文件夹中未找到视频文件" << std::endl;
}
}
};
int main(int argc, char *argv[]) {
AdvancedNfoFileChecker checker;
std::string folderPath;
bool recursive = false;
// 解析命令行参数
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "-r" || arg == "--recursive") {
recursive = true;
} else if (arg == "-h" || arg == "--help") {
std::cout << "用法: " << argv[0] << " [文件夹路径] [-r]" << std::endl;
std::cout << "选项:" << std::endl;
std::cout << " -r, --recursive 递归检查子文件夹" << std::endl;
std::cout << " -h, --help 显示帮助信息" << std::endl;
return 0;
} else {
folderPath = arg;
}
}
if (folderPath.empty()) {
std::cout << "请输入要检查的文件夹路径(留空使用当前目录): ";
std::getline(std::cin, folderPath);
if (folderPath.empty()) {
folderPath = ".";
}
}
std::cout << "正在检查文件夹: " << fs::absolute(folderPath) << std::endl;
if (recursive) {
std::cout << "模式: 递归检查(包含子文件夹)" << std::endl;
}
std::cout << "支持的视频格式: .avi, .m2ts, .mkv, .mp4, .ts" << std::endl;
std::cout << "==========================================" << std::endl;
checker.checkFolderRecursive(folderPath, recursive);
return 0;
}

View File

@@ -2,13 +2,7 @@
base_path=$(pwd)
build_path=${base_path}/build
libraries_root="/opt/Libraries"
if command -v cmake >/dev/null 2>&1; then
cmake_exe=cmake
else
cmake_exe=/opt/Qt/Tools/CMake/bin/cmake
fi
libraries_root="/opt/3rdparty"
function cmake_scan() {
echo "scanning the project..."
@@ -16,7 +10,7 @@ function cmake_scan() {
mkdir -p ${build_path}
fi
cd ${build_path}
${cmake_exe} -G Ninja -S ${base_path} -B ${build_path} \
cmake -G Ninja -S ${base_path} -B ${build_path} \
-DCMAKE_BUILD_TYPE=Debug \
-DMbedTLS_DIR=${libraries_root}/mbedtls-3.6.5/lib/cmake/MbedTLS \
-Dnng_DIR=${libraries_root}/nng-1.11/lib/cmake/nng \
@@ -31,7 +25,7 @@ function build() {
if [ $? -ne 0 ]; then
exit 1
fi
${cmake_exe} --build ${build_path} --target all
cmake --build ${build_path} --target all
if [ $? -ne 0 ]; then
exit 1
fi