|
|
|
@ -1109,6 +1109,30 @@ func checkUrlArtist(url string) (string, string) { |
|
|
|
|
return matches[0][1], matches[0][2] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
func getUrlArtistName(artistUrl string, token string) (string, error) { |
|
|
|
|
storefront, artistId := checkUrlArtist(artistUrl) |
|
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/artists/%s", storefront, artistId), nil) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", 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 "", err |
|
|
|
|
} |
|
|
|
|
defer do.Body.Close() |
|
|
|
|
if do.StatusCode != http.StatusOK { |
|
|
|
|
return "", errors.New(do.Status) |
|
|
|
|
} |
|
|
|
|
obj := new(AutoGeneratedArtist) |
|
|
|
|
err = json.NewDecoder(do.Body).Decode(&obj) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
return obj.Data[0].Attributes.Name, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func checkArtist(artistUrl string, token string) ([]string, error) { |
|
|
|
|
storefront, artistId := checkUrlArtist(artistUrl) |
|
|
|
@ -1408,14 +1432,17 @@ func rip(albumId string, token string, storefront string, userToken string) erro |
|
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
|
"{ArtistName}", "Apple Music", |
|
|
|
|
"{ArtistId}", "", |
|
|
|
|
"{UrlArtistName}", "Apple Music", |
|
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
|
} else if len(meta.Data[0].Relationships.Artists.Data) > 0 { |
|
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
|
"{UrlArtistName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
|
"{ArtistName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
|
"{ArtistId}", meta.Data[0].Relationships.Artists.Data[0].ID, |
|
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
|
} else { |
|
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
|
"{UrlArtistName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
|
"{ArtistName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
|
"{ArtistId}", "", |
|
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
@ -1613,12 +1640,12 @@ func rip(albumId string, token string, storefront string, userToken string) erro |
|
|
|
|
fmt.Printf("Track %d of %d:\n", trackNum, trackTotal) |
|
|
|
|
manifest, err := getInfoFromAdam(track.ID, token, storefront) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("Failed to get manifest.\n", err) |
|
|
|
|
fmt.Println("\u26A0 Failed to get manifest:", err) |
|
|
|
|
counter.NotSong++ |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
if manifest.Attributes.ExtendedAssetUrls.EnhancedHls == "" { |
|
|
|
|
fmt.Println("Unavailable.") |
|
|
|
|
fmt.Println("\u26A0 Unavailable.") |
|
|
|
|
counter.Unavailable++ |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
@ -1731,8 +1758,8 @@ func rip(albumId string, token string, storefront string, userToken string) erro |
|
|
|
|
|
|
|
|
|
trackUrl, keys, err := extractMedia(manifest.Attributes.ExtendedAssetUrls.EnhancedHls) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("Failed to extract info from manifest.\n", err) |
|
|
|
|
counter.Error++ |
|
|
|
|
fmt.Println("\u26A0 Failed to extract info from manifest:", err) |
|
|
|
|
counter.Unavailable++ |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
info, err := extractSong(trackUrl) |
|
|
|
@ -1894,6 +1921,15 @@ func main() { |
|
|
|
|
} |
|
|
|
|
os.Args = args |
|
|
|
|
if strings.Contains(os.Args[0], "/artist/") { |
|
|
|
|
urlArtistName, err := getUrlArtistName(os.Args[0], token) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("Failed to get artistname.") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
//fmt.Println("get artistname:", urlArtistName)
|
|
|
|
|
config.ArtistFolderFormat = strings.NewReplacer( |
|
|
|
|
"{UrlArtistName}", LimitString(urlArtistName), |
|
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
|
newArgs, err := checkArtist(os.Args[0], token) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println("Failed to get artist.") |
|
|
|
|