-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (49 loc) · 949 Bytes
/
main.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bufio"
"flag"
"fmt"
"log/slog"
"os"
"time"
)
func main() {
path := flag.String("path", "", "path to .lrc file")
flag.Parse()
if *path == "" {
slog.Error("path to .lrc is required")
os.Exit(1)
}
file, err := os.Open(*path)
if err != nil {
slog.Error("error opening file: %s", err)
}
reader := bufio.NewReader(file)
slog.Info("parsing LRC file")
donech := make(chan bool)
ticker := time.NewTicker(time.Millisecond * 20)
lyrics, err := ParseLRC(reader)
if err != nil {
slog.Error("error parsing LRC file: %s", err)
}
go playLRC(lyrics, ticker, donech)
<-donech
ticker.Stop()
}
func playLRC(lines []Lyric, ticker *time.Ticker, done chan bool) {
now := time.Now()
idx := 0
for {
select {
case t := <-ticker.C:
if t.After(now.Add(lines[idx].Time.Duration)) {
fmt.Println(lines[idx].Text)
idx += 1
}
if idx >= len(lines) {
done <- true
return
}
}
}
}