aboutsummaryrefslogtreecommitdiff
path: root/home/dot_local/share/bin/executable_labels2lrc
blob: c8abc1c44002a0b4834a68ccd649309da2faa798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/python3

import re
import sys

for line in sys.stdin:
	line = line.rstrip("\n")
	fields = line.split("\t")

	if len(fields) < 3:
		continue

	time = fields[0]

	# Equivalent of:
	# gensub(/([0-9]+)\.([0-9]{,2})([0-9]*)/, "\\1\\2.\\3", "g", time)
	time = re.sub(r'(\d+)\.(\d{0,2})(\d*)', r'\1\2.\3', time)

	# AWK rounds by adding 0.5 then truncating.
	time = int(float(time) + 0.5)

	millis = time % 100
	time //= 100

	seconds = time % 60
	time //= 60

	minutes = time % 100

	print(f"[{minutes:02d}:{seconds:02d}.{millis:02d}]{fields[2]}")