mirror of
https://github.com/zhaarey/apple-music-downloader.git
synced 2025-10-23 15:11:05 +00:00
Merge pull request #69 from WorldObservationLog/main
fix: unable to collect information about albums with more than 300 tracks
This commit is contained in:
60
main.go
60
main.go
@@ -356,36 +356,36 @@ func getMeta(albumId string, token string, storefront string) (*structs.AutoGene
|
||||
}
|
||||
if strings.Contains(albumId, "pl.") {
|
||||
obj.Data[0].Attributes.ArtistName = "Apple Music"
|
||||
if len(obj.Data[0].Relationships.Tracks.Next) > 0 {
|
||||
next = obj.Data[0].Relationships.Tracks.Next
|
||||
for {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/%s&l=%s&include=albums", next, Config.Language), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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")
|
||||
do, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer do.Body.Close()
|
||||
if do.StatusCode != http.StatusOK {
|
||||
return nil, errors.New(do.Status)
|
||||
}
|
||||
obj2 := new(structs.AutoGeneratedTrack)
|
||||
err = json.NewDecoder(do.Body).Decode(&obj2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, value := range obj2.Data {
|
||||
obj.Data[0].Relationships.Tracks.Data = append(obj.Data[0].Relationships.Tracks.Data, value)
|
||||
}
|
||||
next = obj2.Next
|
||||
if len(next) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(obj.Data[0].Relationships.Tracks.Next) > 0 {
|
||||
next = obj.Data[0].Relationships.Tracks.Next
|
||||
for {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/%s&l=%s&include=albums", next, Config.Language), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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")
|
||||
do, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer do.Body.Close()
|
||||
if do.StatusCode != http.StatusOK {
|
||||
return nil, errors.New(do.Status)
|
||||
}
|
||||
obj2 := new(structs.AutoGeneratedTrack)
|
||||
err = json.NewDecoder(do.Body).Decode(&obj2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, value := range obj2.Data {
|
||||
obj.Data[0].Relationships.Tracks.Data = append(obj.Data[0].Relationships.Tracks.Data, value)
|
||||
}
|
||||
next = obj2.Next
|
||||
if len(next) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user