Skip to content

Commit

Permalink
improve lyrics parsing
Browse files Browse the repository at this point in the history
ignore drawings and new lines
  • Loading branch information
odrling committed Aug 10, 2024
1 parent 02577e8 commit 5103106
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
5 changes: 4 additions & 1 deletion dakara_check_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ int main(int argc, char *argv[]) {
return EXIT_SUCCESS;
}


dakara_check_sub_results *res = dakara_check_subtitle_file(argv[1]);
if (res != NULL) {
printf("%s\n", res->lyrics);
}

dakara_check_sub_results_free(res);

return EXIT_SUCCESS;
Expand Down
33 changes: 28 additions & 5 deletions libdakara_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,43 @@ void dakara_check_subtitle_events(ASS_Track *track, dakara_check_sub_results *re

unsigned long write_head = 0;
bool tags = false;
bool drawing = false;

for (unsigned long read_head = 0; line[read_head] != '\0'; read_head++) {
if (tags) {
switch (line[read_head]) {
case '{':
tags = false;
break;
case '\\':
if (line[read_head + 1] == 'p') {
// \p0, disables \pn is valid and enables drawing mode
drawing = line[read_head + 2] != '0';
}
break;
}
if (line[read_head] == '}') {
tags = false;
}
} else {
if (line[read_head] == '{') {
switch (line[read_head]) {
case '{':
tags = true;
} else {
if (read_head != write_head) {
line[write_head] = line[read_head];
break;
case '\\':
read_head++;
if (line[read_head] != 'n' && line[read_head] != 'N') {
goto write;
}
break;
default:
write:
if (!drawing) {
if (read_head != write_head) {
line[write_head] = line[read_head];
}
write_head++;
}
write_head++;
}
}
}
Expand Down

0 comments on commit 5103106

Please sign in to comment.