Compare commits

..

7 Commits

Author SHA1 Message Date
ZHAAREY 1edcb1d770
Merge pull request #34 from itouakirai/main 2 months ago
itouakirai fa3295a1c1
add artist-folder-format tag {ArtistName}/{UrlArtistName} 2 months ago
itouakirai 5f2bb60b63
add artist-folder-format tag {ArtistName}/{UrlArtistName} 2 months ago
itouakirai e607240dca
警告时添加图标 2 months ago
itouakirai 330d0a1f89
add artist-folder-format tag {ArtistName}/{ArtistsName} 2 months ago
itouakirai d1c576847b
add artist-folder-format tag {ArtistName}/{ArtistsName} 2 months ago
itouakirai 3caeaa66a4
修复warning统计 2 months ago
  1. 2
      config.yaml
  2. 44
      main.go

@ -29,7 +29,7 @@ playlist-folder-format: "{PlaylistName}"
#{SongId} {SongNumer} {SongName} {DiscNumber} {TrackNumber} {Quality} {Codec} {Tag}
#example: Disk {DiscNumber} - Track {TrackNumber} {SongName} [{Quality}]{{Tag}}"
song-file-format: "{SongNumer}. {SongName}"
#{ArtistId} {ArtistName}
#{ArtistId} {ArtistName}/{UrlArtistName}
#if artist-folder-format set "",will not make artist folder
artist-folder-format: "{ArtistName}"
#if set "" will not add tag

@ -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.")

Loading…
Cancel
Save