chore: prepare for srt support + force sync lrc timestamp if timeline length mismatch
This commit is contained in:
parent
6875b43b78
commit
00deeaf425
2 changed files with 28 additions and 41 deletions
25
convert.go
Normal file
25
convert.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue