Update main_select.go

pull/3/head
itouakirai 7 months ago committed by GitHub
parent dc130fbf1e
commit dcef5022b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      main_select.go

@ -15,6 +15,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort" "sort"
@ -1139,21 +1140,16 @@ func rip(albumId string, token string, storefront string, userToken string) erro
continue continue
} }
filename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_")) filename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
lrcFilename := fmt.Sprintf("%02d. %s.lrc", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
trackPath := filepath.Join(sanAlbumFolder, filename) trackPath := filepath.Join(sanAlbumFolder, filename)
var lrc string = ""
if userToken != "" { if userToken != "" {
ttml, err := getSongLyrics(track.ID, storefront, token, userToken) ttml, err := getSongLyrics(track.ID, storefront, token, userToken)
if err != nil { if err != nil {
fmt.Println("Failed to get lyrics") fmt.Println("Failed to get lyrics")
} else { } else {
lrc, err := conventTTMLToLRC(ttml) lrc, err = conventTTMLToLRC(ttml)
if err != nil { if err != nil {
fmt.Printf("Failed to parse lyrics: %s \n", err) fmt.Printf("Failed to parse lyrics: %s \n", err)
} else {
err := writeLyrics(sanAlbumFolder, lrcFilename, lrc)
if err != nil {
fmt.Printf("Failed to write lyrics")
}
} }
} }
} }
@ -1193,6 +1189,16 @@ func rip(albumId string, token string, storefront string, userToken string) erro
fmt.Println("Failed to decrypt track.\n", err) fmt.Println("Failed to decrypt track.\n", err)
continue continue
} }
tags := []string{
fmt.Sprintf("lyrics=%s", lrc),
fmt.Sprintf("cover=%s/cover.jpg", sanAlbumFolder),
}
tagsString := strings.Join(tags, ":")
cmd := exec.Command("MP4Box","-itags", tagsString, trackPath)
if err := cmd.Run(); err != nil {
fmt.Printf("Embed failed: %v\n", err)
continue
}
} }
} }
return err return err

Loading…
Cancel
Save