struct TimeString {
    uint16_t hour;
    uint16_t minute;
    uint16_t second;
    String   string;
};

Array<TimeString> ParseSrtFile(Arena *arena, String filename) {
    String        content = ReadFile(*arena, filename);
    Array<String> lines   = Split(*arena, content, "\n");

    IterRemove(lines) {
        IterRemovePrepare(lines);
        it = Trim(it);
        if (it.len == 0) remove_item = true;
    }

    long              section_number = 1;
    Array<TimeString> time_strings   = {*arena};
    for (int i = 0; i < lines.len;) {
        String it0 = lines[i++];
        long   num = strtol(it0.data, NULL, 10);
        Assert(section_number == num);
        section_number += 1;

        TimeString item = {};
        String     it1  = lines[i++];
        item.hour       = (uint16_t)strtol(it1.data, NULL, 10);
        item.minute     = (uint16_t)strtol(it1.data + 3, NULL, 10);
        item.second     = (uint16_t)strtol(it1.data + 6, NULL, 10);

        String next_section_number = Format(*arena, "%d", section_number);
        while (i < lines.len && lines[i] != next_section_number) {
            String it   = lines[i];
            item.string = lines[i];
            time_strings.add(item);
            i += 1;
        }
    }

    IterRemove(time_strings) {
        IterRemovePrepare(time_strings);
        if (i > 0 && AreEqual(time_strings[i - 1].string, time_strings[i].string, true)) {
            remove_item = true;
        }
    }

    return time_strings;
}

String FindVideoForSRT(Array<String> &filenames, String srt_path) {
    String base = ChopLastPeriod(srt_path); // .srt
    base        = ChopLastPeriod(base);     // .en

    For(filenames) {
        if (StartsWith(it, base)) {
            if (EndsWith(it, ".mkv") || EndsWith(it, ".webm") || EndsWith(it, ".mp4")) {
                return it;
            }
        }
    }
    return {};
}
