aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2026-07-28 19:14:42 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2026-07-28 19:14:42 +0200
commit8c453842ff211e1d918eecdf828320fa258bc593 (patch)
tree252599b7b30ee5c05075660930f4145eff1a6b78
parent093f2afaf06712e4e52d275973188e1f5febba5f (diff)
rewrite labels2lrc in python because gawk broke :/
-rwxr-xr-x.local/share/bin/labels2lrc33
1 files changed, 23 insertions, 10 deletions
diff --git a/.local/share/bin/labels2lrc b/.local/share/bin/labels2lrc
index 38630c1..c8abc1c 100755
--- a/.local/share/bin/labels2lrc
+++ b/.local/share/bin/labels2lrc
@@ -1,17 +1,30 @@
-#!/bin/gawk -f
-BEGIN { FS = "\t" }
-{
- time = $1
- time = gensub(/([0-9]+)\.([0-9]{,2})([0-9]*)/, "\\1\\2.\\3", "g", time)
- time = int(time + 0.5)
+#!/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 = int(time / 100)
+ time //= 100
seconds = time % 60
- time = int(time / 60)
+ time //= 60
minutes = time % 100
- printf("[%02d:%02d.%02d]%s\n", minutes, seconds, millis, $3)
-}
+ print(f"[{minutes:02d}:{seconds:02d}.{millis:02d}]{fields[2]}")