diff --git a/cli_main.cpp b/cli_main.cpp index 9a38e31..19d049c 100644 --- a/cli_main.cpp +++ b/cli_main.cpp @@ -10,6 +10,7 @@ int main(int argc, char *argv[]) { std::filesystem::path configPath, csvPath, outputPath; std::string timeUnit; + int shiftTime; app.add_option("-c,--config", configPath, "Path to INI config file") ->required() @@ -22,6 +23,7 @@ int main(int argc, char *argv[]) { app.add_option("-u,--time-unit", timeUnit, "Time unit inside CSV: “ms” or “sec”") ->required() ->check(CLI::IsMember({"ms", "sec"}, CLI::ignore_case)); + app.add_option("-s,--shift",shiftTime, "Time in sec to shift the subtitles by"); CLI11_PARSE(app, argc, argv); @@ -33,7 +35,7 @@ int main(int argc, char *argv[]) { return 1; } - auto chat = parseCSV(csvPath, multiplier); + auto chat = parseCSV(csvPath, multiplier, shiftTime); if (chat.empty()) { std::cerr << "Error: Failed to parse chat CSV or it's empty: " << csvPath << "\n"; return 1; diff --git a/gui_main.cpp b/gui_main.cpp index bbc179d..1064b71 100644 --- a/gui_main.cpp +++ b/gui_main.cpp @@ -257,7 +257,7 @@ int main(int, char **) { nfdresult_t result = NFD_OpenDialogU8_With(&outPath, &args); if (result == NFD_OKAY) { int multiplier = 1; // TODO: some way to customize time units - text_overlay.messages = parseCSV(outPath, multiplier); + text_overlay.messages = parseCSV(outPath, multiplier,0); text_overlay.revalidatePreview = true; NFD_FreePathU8(outPath); } else if (result == NFD_CANCEL) { diff --git a/ytt_generator.h b/ytt_generator.h index 411608b..1d95c2b 100644 --- a/ytt_generator.h +++ b/ytt_generator.h @@ -678,7 +678,7 @@ inline Color getRandomColor(const std::string &username) { } // dumb and simple way to parse CSV -inline std::vector parseCSV(const std::filesystem::path &filename, int timeMultiplier) { +inline std::vector parseCSV(const std::filesystem::path &filename, int timeMultiplier, int shiftTime) { std::vector messages; std::ifstream file(filename); std::string line; @@ -700,7 +700,12 @@ inline std::vector parseCSV(const std::filesystem::path &filename, ChatMessage msg; std::getline(ss, field, ','); - msg.time = std::stoi(field) * timeMultiplier; + msg.time = std::stoi(field) * timeMultiplier; + // would the message be shifted to a time < 0? then skip it + if(shiftTime < 0 && msg.time < -shiftTime){ + continue; + } + msg.time += shiftTime*1000; std::getline(ss, msg.user.name, ',');