Files
Bilby/Infoer.cpp
amass 482e5495f0
Some checks failed
Deploy Applications / PullDocker (push) Failing after 9s
Deploy Applications / Build (push) Failing after 4s
Windows CI / build (push) Has been cancelled
add info checker.
2025-11-10 19:29:40 +08:00

124 lines
4.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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;
}