Update add Embed cover and lrc

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

@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort" "sort"
@ -1103,21 +1104,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")
}
} }
} }
} }
@ -1158,6 +1154,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
}
oktrackNum += 1 oktrackNum += 1
} }
return err return err

Loading…
Cancel
Save