mirror of
https://github.com/zhaarey/apple-music-downloader.git
synced 2025-10-23 15:11:05 +00:00
Update main.go
This commit is contained in:
16
main.go
16
main.go
@@ -52,6 +52,7 @@ type Config struct {
|
|||||||
MediaUserToken string `yaml:"media-user-token"`
|
MediaUserToken string `yaml:"media-user-token"`
|
||||||
AuthorizationToken string `yaml:"authorization-token"`
|
AuthorizationToken string `yaml:"authorization-token"`
|
||||||
SaveLrcFile bool `yaml:"save-lrc-file"`
|
SaveLrcFile bool `yaml:"save-lrc-file"`
|
||||||
|
LrcType string `yaml:"lrc-type"`
|
||||||
LrcFormat string `yaml:"lrc-format"`
|
LrcFormat string `yaml:"lrc-format"`
|
||||||
SaveAnimatedArtwork bool `yaml:"save-animated-artwork"`
|
SaveAnimatedArtwork bool `yaml:"save-animated-artwork"`
|
||||||
EmbyAnimatedArtwork bool `yaml:"emby-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) {
|
func getSongLyrics(songId string, storefront string, token string, userToken string) (string, error) {
|
||||||
req, err := http.NewRequest("GET",
|
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 {
|
if err != nil {
|
||||||
return "", err
|
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, "_"))
|
filename = fmt.Sprintf("%s.ec3", forbiddenNames.ReplaceAllString(songName, "_"))
|
||||||
}
|
}
|
||||||
m4afilename := fmt.Sprintf("%s.m4a", 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)
|
trackPath := filepath.Join(sanAlbumFolder, filename)
|
||||||
m4atrackPath := filepath.Join(sanAlbumFolder, m4afilename)
|
m4atrackPath := filepath.Join(sanAlbumFolder, m4afilename)
|
||||||
var lrc string = ""
|
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)
|
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 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 {
|
} else {
|
||||||
lrc, err = conventTTMLToLRC(ttml)
|
lrc, err = conventTTMLToLRC(ttml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user