Skip to content

Commit

Permalink
Merge pull request #37 from itouakirai/main
Browse files Browse the repository at this point in the history
ttml不内嵌、自定义元数据语言
  • Loading branch information
zhaarey authored Sep 28, 2024
2 parents 23cae57 + 370f71c commit 24b9ef1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -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
language: "" #supportedLanguage by each storefront --> https://gist.github.com/itouakirai/c8ba9df9dc65bd300094103b058731d0
lrc-type: "lyrics" #lyrics or syllable-lyrics
lrc-format: "lrc" #lrc or ttml
embed-lrc: true
embed-lrc: true #Unable to embed ttml lyrics
save-lrc-file: false
save-artist-cover: false
save-animated-artwork: false # If enabled, requires ffmpeg
Expand Down
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
type Config struct {
MediaUserToken string `yaml:"media-user-token"`
AuthorizationToken string `yaml:"authorization-token"`
Language string `yaml:"language"`
SaveLrcFile bool `yaml:"save-lrc-file"`
LrcType string `yaml:"lrc-type"`
LrcFormat string `yaml:"lrc-format"`
Expand Down Expand Up @@ -1119,6 +1120,8 @@ func getUrlArtistName(artistUrl string, token string) (string, error) {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
req.Header.Set("Origin", "https://music.apple.com")
query := url.Values{}
query.Set("l", config.Language)
do, err := http.DefaultClient.Do(req)
if err != nil {
return "", err
Expand All @@ -1143,7 +1146,7 @@ func checkArtist(artistUrl string, token string) ([]string, error) {
var urls []string
var options []string
for {
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/artists/%s/albums?limit=100&offset=%d", storefront, artistId, Num), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/artists/%s/albums?limit=100&offset=%d&l=%s", storefront, artistId, Num, config.Language), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1263,7 +1266,7 @@ func getMeta(albumId string, token string, storefront string) (*AutoGenerated, e
query.Set("fields[albums:albums]", "artistName,artwork,name,releaseDate,url")
query.Set("fields[record-labels]", "name")
query.Set("extend", "editorialVideo")
// query.Set("l", "en-gb")
query.Set("l", config.Language)
req.URL.RawQuery = query.Encode()
do, err := http.DefaultClient.Do(req)
if err != nil {
Expand All @@ -1285,7 +1288,7 @@ func getMeta(albumId string, token string, storefront string) (*AutoGenerated, e
for {
page = page + 100
pageStr := strconv.Itoa(page)
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/%s/%s/tracks?offset=%s", storefront, mtype, albumId, pageStr), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/%s/%s/tracks?offset=%s&l=%s", storefront, mtype, albumId, pageStr, config.Language), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1726,9 +1729,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro
if err != nil {
fmt.Printf("Failed to write lyrics")
}
if !config.EmbedLrc {
lrc = ""
}
lrc = ""
}
} else {
lrc, err = conventTTMLToLRC(ttml)
Expand Down Expand Up @@ -2599,6 +2600,7 @@ func getInfoFromAdam(adamId string, token string, storefront string) (*SongData,
query := url.Values{}
query.Set("extend", "extendedAssetUrls")
query.Set("include", "albums")
query.Set("l", config.Language)
request.URL.RawQuery = query.Encode()

request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
Expand Down

0 comments on commit 24b9ef1

Please sign in to comment.