Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions ytt_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ inline Color getRandomColor(const std::string &username) {
}

// dumb and simple way to parse CSV
inline std::vector<ChatMessage> parseCSV(const std::filesystem::path &filename, int timeMultiplier) {
inline std::vector<ChatMessage> parseCSV(const std::filesystem::path &filename, int timeMultiplier, int shiftTime) {
std::vector<ChatMessage> messages;
std::ifstream file(filename);
std::string line;
Expand All @@ -700,7 +700,12 @@ inline std::vector<ChatMessage> 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, ',');

Expand Down