import re

LRC_FILE = "Enemies.lrc.HR"
LABEL_FILE = "Enemies.labels"

# Regex for [start|end]word
pattern = re.compile(r"\[(\d+):(\d+\.\d+)\|(\d+):(\d+\.\d+)\](.+)")

with open(LRC_FILE, "r", encoding="utf-8") as f_in, open(LABEL_FILE, "w", encoding="utf-8") as f_out:
    for line in f_in:
        match = pattern.match(line.strip())
        if match:
            start_min = int(match.group(1))
            start_sec = float(match.group(2))
            end_min = int(match.group(3))
            end_sec = float(match.group(4))
            word = match.group(5).strip()

            start_time = start_min * 60 + start_sec
            end_time = end_min * 60 + end_sec

            # Audacity labels: start_time \t end_time \t label
            f_out.write(f"{start_time:.3f}\t{end_time:.3f}\t{word}\n")

print(f"Labels saved to {LABEL_FILE}")
