|
|
@ -1109,6 +1109,30 @@ func checkUrlArtist(url string) (string, string) { |
|
|
|
return matches[0][1], matches[0][2] |
|
|
|
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) { |
|
|
|
func checkArtist(artistUrl string, token string) ([]string, error) { |
|
|
|
storefront, artistId := checkUrlArtist(artistUrl) |
|
|
|
storefront, artistId := checkUrlArtist(artistUrl) |
|
|
@ -1408,18 +1432,18 @@ func rip(albumId string, token string, storefront string, userToken string) erro |
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
"{ArtistName}", "Apple Music", |
|
|
|
"{ArtistName}", "Apple Music", |
|
|
|
"{ArtistId}", "", |
|
|
|
"{ArtistId}", "", |
|
|
|
"{ArtistsName}", "Apple Music", |
|
|
|
"{UrlArtistName}", "Apple Music", |
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
} else if len(meta.Data[0].Relationships.Artists.Data) > 0 { |
|
|
|
} else if len(meta.Data[0].Relationships.Artists.Data) > 0 { |
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
"{ArtistName}", LimitString(meta.Data[0].Relationships.Artists.Data[0].Attributes.Name), |
|
|
|
"{UrlArtistName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
"{ArtistsName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
"{ArtistName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
"{ArtistId}", meta.Data[0].Relationships.Artists.Data[0].ID, |
|
|
|
"{ArtistId}", meta.Data[0].Relationships.Artists.Data[0].ID, |
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
singerFoldername = strings.NewReplacer( |
|
|
|
"{ArtistName}", LimitString(meta.Data[0].Relationships.Artists.Data[0].Attributes.Name), |
|
|
|
"{UrlArtistName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
"{ArtistsName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
"{ArtistName}", LimitString(meta.Data[0].Attributes.ArtistName), |
|
|
|
"{ArtistId}", "", |
|
|
|
"{ArtistId}", "", |
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
).Replace(config.ArtistFolderFormat) |
|
|
|
} |
|
|
|
} |
|
|
@ -1897,6 +1921,15 @@ func main() { |
|
|
|
} |
|
|
|
} |
|
|
|
os.Args = args |
|
|
|
os.Args = args |
|
|
|
if strings.Contains(os.Args[0], "/artist/") { |
|
|
|
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) |
|
|
|
newArgs, err := checkArtist(os.Args[0], token) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Println("Failed to get artist.") |
|
|
|
fmt.Println("Failed to get artist.") |
|
|
|