mirror of
https://github.com/zhaarey/apple-music-downloader.git
synced 2025-10-23 15:11:05 +00:00
fix: unable to collect information about albums with more than 300 tracks
This commit is contained in:
@@ -48,6 +48,41 @@ func GetAlbumResp(storefront string, id string, language string, token string) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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", next), 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")
|
||||
query := req.URL.Query()
|
||||
query.Set("omit[resource]", "autos")
|
||||
query.Set("include", "artists")
|
||||
query.Set("extend", "editorialVideo,extendedAssetUrls")
|
||||
req.URL.RawQuery = query.Encode()
|
||||
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(TrackResp)
|
||||
err = json.NewDecoder(do.Body).Decode(&obj2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
obj.Data[0].Relationships.Tracks.Data = append(obj.Data[0].Relationships.Tracks.Data, obj2.Data...)
|
||||
next = obj2.Next
|
||||
if len(next) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
@@ -90,6 +125,41 @@ func GetAlbumRespByHref(href string, language string, token string) (*AlbumResp,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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", next), 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")
|
||||
query := req.URL.Query()
|
||||
query.Set("omit[resource]", "autos")
|
||||
query.Set("include", "artists")
|
||||
query.Set("extend", "editorialVideo,extendedAssetUrls")
|
||||
req.URL.RawQuery = query.Encode()
|
||||
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(TrackResp)
|
||||
err = json.NewDecoder(do.Body).Decode(&obj2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
obj.Data[0].Relationships.Tracks.Data = append(obj.Data[0].Relationships.Tracks.Data, obj2.Data...)
|
||||
next = obj2.Next
|
||||
if len(next) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user