Merge pull request #34 from itouakirai/main
add artist-folder-format tag {ArtistName}/{UrlArtistName}
This commit is contained in:
commit
1edcb1d770
@ -29,7 +29,7 @@ playlist-folder-format: "{PlaylistName}"
|
|||||||
#{SongId} {SongNumer} {SongName} {DiscNumber} {TrackNumber} {Quality} {Codec} {Tag}
|
#{SongId} {SongNumer} {SongName} {DiscNumber} {TrackNumber} {Quality} {Codec} {Tag}
|
||||||
#example: Disk {DiscNumber} - Track {TrackNumber} {SongName} [{Quality}]{{Tag}}"
|
#example: Disk {DiscNumber} - Track {TrackNumber} {SongName} [{Quality}]{{Tag}}"
|
||||||
song-file-format: "{SongNumer}. {SongName}"
|
song-file-format: "{SongNumer}. {SongName}"
|
||||||
#{ArtistId} {ArtistName}
|
#{ArtistId} {ArtistName}/{UrlArtistName}
|
||||||
#if artist-folder-format set "",will not make artist folder
|
#if artist-folder-format set "",will not make artist folder
|
||||||
artist-folder-format: "{ArtistName}"
|
artist-folder-format: "{ArtistName}"
|
||||||
#if set "" will not add tag
|
#if set "" will not add tag
|
||||||
|
44
main.go
44
main.go
@ -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,14 +1432,17 @@ 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}", "",
|
||||||
|
"{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(
|
||||||
|
"{UrlArtistName}", LimitString(meta.Data[0].Attributes.ArtistName),
|
||||||
"{ArtistName}", 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(
|
||||||
|
"{UrlArtistName}", LimitString(meta.Data[0].Attributes.ArtistName),
|
||||||
"{ArtistName}", LimitString(meta.Data[0].Attributes.ArtistName),
|
"{ArtistName}", LimitString(meta.Data[0].Attributes.ArtistName),
|
||||||
"{ArtistId}", "",
|
"{ArtistId}", "",
|
||||||
).Replace(config.ArtistFolderFormat)
|
).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)
|
fmt.Printf("Track %d of %d:\n", trackNum, trackTotal)
|
||||||
manifest, err := getInfoFromAdam(track.ID, token, storefront)
|
manifest, err := getInfoFromAdam(track.ID, token, storefront)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to get manifest.\n", err)
|
fmt.Println("\u26A0 Failed to get manifest:", err)
|
||||||
counter.NotSong++
|
counter.NotSong++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if manifest.Attributes.ExtendedAssetUrls.EnhancedHls == "" {
|
if manifest.Attributes.ExtendedAssetUrls.EnhancedHls == "" {
|
||||||
fmt.Println("Unavailable.")
|
fmt.Println("\u26A0 Unavailable.")
|
||||||
counter.Unavailable++
|
counter.Unavailable++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -1731,8 +1758,8 @@ func rip(albumId string, token string, storefront string, userToken string) erro
|
|||||||
|
|
||||||
trackUrl, keys, err := extractMedia(manifest.Attributes.ExtendedAssetUrls.EnhancedHls)
|
trackUrl, keys, err := extractMedia(manifest.Attributes.ExtendedAssetUrls.EnhancedHls)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to extract info from manifest.\n", err)
|
fmt.Println("\u26A0 Failed to extract info from manifest:", err)
|
||||||
counter.Error++
|
counter.Unavailable++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
info, err := extractSong(trackUrl)
|
info, err := extractSong(trackUrl)
|
||||||
@ -1894,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.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user