From 460255c88d66ba601ec2a351280f26c56f141ad2 Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Fri, 27 Sep 2024 04:27:18 +0800 Subject: [PATCH 1/2] Update main.go --- main.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 24af3d5..0440692 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,7 @@ type Config struct { MediaUserToken string `yaml:"media-user-token"` AuthorizationToken string `yaml:"authorization-token"` SaveLrcFile bool `yaml:"save-lrc-file"` + LrcType string `yaml:"lrc-type"` LrcFormat string `yaml:"lrc-format"` SaveAnimatedArtwork bool `yaml:"save-animated-artwork"` EmbyAnimatedArtwork bool `yaml:"emby-animated-artwork"` @@ -1318,7 +1319,7 @@ func getMeta(albumId string, token string, storefront string) (*AutoGenerated, e func getSongLyrics(songId string, storefront string, token string, userToken string) (string, error) { req, err := http.NewRequest("GET", - fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/songs/%s/%s", storefront, songId, config.LrcFormat), nil) + fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/songs/%s/%s", storefront, songId, config.LrcType), nil) if err != nil { return "", err } @@ -1710,7 +1711,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro filename = fmt.Sprintf("%s.ec3", forbiddenNames.ReplaceAllString(songName, "_")) } m4afilename := fmt.Sprintf("%s.m4a", forbiddenNames.ReplaceAllString(songName, "_")) - lrcFilename := fmt.Sprintf("%s.lrc", forbiddenNames.ReplaceAllString(songName, "_")) + lrcFilename := fmt.Sprintf("%s.%s", forbiddenNames.ReplaceAllString(songName, "_"), config.LrcFormat) trackPath := filepath.Join(sanAlbumFolder, filename) m4atrackPath := filepath.Join(sanAlbumFolder, m4afilename) var lrc string = "" @@ -1718,6 +1719,17 @@ func rip(albumId string, token string, storefront string, userToken string) erro ttml, err := getSongLyrics(track.ID, storefront, token, userToken) if err != nil { fmt.Println("Failed to get lyrics") + } else if config.LrcFormat == "ttml"{ + if config.SaveLrcFile { + lrc = ttml + err := writeLyrics(sanAlbumFolder, lrcFilename, lrc) + if err != nil { + fmt.Printf("Failed to write lyrics") + } + if !config.EmbedLrc { + lrc = "" + } + } } else { lrc, err = conventTTMLToLRC(ttml) if err != nil { From cc315c593d5f603e1bafac4e52b6a483b6c9813e Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Fri, 27 Sep 2024 04:31:24 +0800 Subject: [PATCH 2/2] add ttml lyrics --- config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 664d828..5391e69 100644 --- a/config.yaml +++ b/config.yaml @@ -1,8 +1,9 @@ media-user-token: "your-media-user-token" #If you need to obtain the lyrics, need to change it authorization-token: "your-authorization-token" #You don't need to change it; it can automatically obtain token +lrc-type: "lyrics" #lyrics or syllable-lyrics +lrc-format: "lrc" #lrc or ttml embed-lrc: true save-lrc-file: false -lrc-format: "lyrics" #lyrics syllable-lyrics save-artist-cover: false save-animated-artwork: false # If enabled, requires ffmpeg emby-animated-artwork: false # If enabled, requires ffmpeg