diff --git a/convert.go b/convert.go new file mode 100644 index 0000000..55c0e31 --- /dev/null +++ b/convert.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "os" +) + +func lrcToTxt(sourceFile, targetFile string) { + sourceLyrics, err := parseLyrics(sourceFile) + if err != nil { + fmt.Println("Error parsing source lyrics file:", err) + return + } + + file, err := os.Create(targetFile) + if err != nil { + fmt.Println("Error creating target file:", err) + return + } + defer file.Close() + + for _, content := range sourceLyrics.Content { + fmt.Fprintln(file, content) + } +} diff --git a/util.go b/lrc.go similarity index 84% rename from util.go rename to lrc.go index 9e0efc4..072e968 100644 --- a/util.go +++ b/lrc.go @@ -162,16 +162,14 @@ func syncLyrics(args []string) { return } - // Sync timeline - if len(sourceLyrics.Timeline) != len(targetLyrics.Timeline) { - fmt.Println("Warning: Timeline length mismatch") - return - } minLength := len(sourceLyrics.Timeline) if len(targetLyrics.Timeline) < minLength { minLength = len(targetLyrics.Timeline) + fmt.Printf("Warning: Timeline length mismatch. Source: %d lines, Target: %d lines. Will sync the first %d lines.\n", + len(sourceLyrics.Timeline), len(targetLyrics.Timeline), minLength) } + // Sync the timeline for i := 0; i < minLength; i++ { targetLyrics.Timeline[i] = sourceLyrics.Timeline[i] } @@ -185,23 +183,6 @@ func syncLyrics(args []string) { } } -// func printLyricsInfo(lyrics Lyrics) { -// fmt.Println("Metadata:") -// for key, value := range lyrics.Metadata { -// fmt.Printf("%s: %s\n", key, value) -// } - -// fmt.Println("\nTimeline:") -// for _, time := range lyrics.Timeline { -// fmt.Println(time) -// } - -// fmt.Println("\nLyrics Content:") -// for _, content := range lyrics.Content { -// fmt.Println(content) -// } -// } - func convertLyrics(args []string) { if len(args) < 2 { fmt.Println(CONVERT_USAGE) @@ -244,25 +225,6 @@ func fmtLyrics(args []string) { } } -func lrcToTxt(sourceFile, targetFile string) { - sourceLyrics, err := parseLyrics(sourceFile) - if err != nil { - fmt.Println("Error parsing source lyrics file:", err) - return - } - - file, err := os.Create(targetFile) - if err != nil { - fmt.Println("Error creating target file:", err) - return - } - defer file.Close() - - for _, content := range sourceLyrics.Content { - fmt.Fprintln(file, content) - } -} - func timestampToString(ts Timestamp) string { if ts.Hours > 0 { return fmt.Sprintf("[%02d:%02d:%02d.%03d]", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)