#include #include #include #include #include // g++ -std=c++20 rename.cpp -o rename // title 字段需要,可以先随便填 constexpr auto Template = R"( 黑色五叶草 黑色五叶草 {} {} {} )"; struct SeasonRange { int start; int end; int season; }; const std::vector ranges = { {1, 170, 1}, // 001-048 season 1 48集 }; // 文件夹内有 001.mkv-328.mkv 文件,使用C++ STL filesystem 根据上面的对应关系生成 001.nfo-328.nfo, 使用 std::format 传入字符串 // Template 输出最终内容写入对应的nfo文件 int main(int argc, char const *argv[]) { std::cout << "this is a simple rename app." << std::endl; for (const auto &entry : std::filesystem::directory_iterator(".")) { if (!entry.is_regular_file()) continue; const auto &path = entry.path(); if (path.extension() != ".mkv") continue; const std::string filename = path.filename().string(); const std::string stem = path.stem().string(); std::cout <<"stem: "<= range.start && episode_number <= range.end) { season = range.season; episode_in_season = episode_number - range.start + 1; break; } } if (season == -1) { std::cerr << "未找到对应的季度: " << episode_number << std::endl; continue; } // 生成XML内容 std::string xml_content = std::format(Template, season, episode_in_season, filename); // 写入.nfo文件 std::filesystem::path nfo_path = path; nfo_path.replace_extension(".nfo"); std::ofstream out_file(nfo_path); out_file << xml_content; std::cout <<"filename: "<