From 4a6ec9ef436b7f42507e4be3ba5b54549c8ab769 Mon Sep 17 00:00:00 2001 From: zhaarey <157944548+zhaarey@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:28:28 +0800 Subject: [PATCH] add album-folder-format --- config.yaml | 3 +++ main.go | 10 +++++++++- main_atmos.go | 11 ++++++++++- main_select.go | 10 +++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index 94776ec..35ba6a3 100644 --- a/config.yaml +++ b/config.yaml @@ -11,3 +11,6 @@ force-api: false get-m3u8-from-device: false alac-max: 192000 #192000 96000 48000 44100 atmos-max: 2768 #2768 2448 +#{AlbumId} {AlbumName} {ArtistName} {ReleaseDate} {UPC} {Copyright} +#example: {ReleaseDate} - {ArtistName} - {AlbumName}({AlbumId}) +album-folder-format: "{AlbumName}" diff --git a/main.go b/main.go index 38b253e..7370208 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,7 @@ type Config struct { CoverFormat string `yaml:"cover-format"` AlacSaveFolder string `yaml:"alac-save-folder"` AtmosSaveFolder string `yaml:"atmos-save-folder"` + AlbumFolderFormat string `yaml:"album-folder-format"` ForceApi bool `yaml:"force-api"` Check string `yaml:"check"` GetM3u8FromDevice bool `yaml:"get-m3u8-from-device"` @@ -1163,7 +1164,14 @@ func rip(albumId string, token string, storefront string, userToken string) erro } singerFoldername = strings.TrimSpace(singerFoldername) singerFolder := filepath.Join(config.AlacSaveFolder, forbiddenNames.ReplaceAllString(singerFoldername, "_")) - albumFolder := fmt.Sprintf("%s", meta.Data[0].Attributes.Name) + albumFolder := strings.NewReplacer( + "{ReleaseDate}", meta.Data[0].Attributes.ReleaseDate, + "{ArtistName}", meta.Data[0].Attributes.ArtistName, + "{AlbumName}", meta.Data[0].Attributes.Name, + "{UPC}", meta.Data[0].Attributes.Upc, + "{Copyright}", meta.Data[0].Attributes.Copyright, + "{AlbumId}", albumId, + ).Replace(config.AlbumFolderFormat) if strings.HasSuffix(albumFolder, ".") { albumFolder = strings.ReplaceAll(albumFolder, ".", "") } diff --git a/main_atmos.go b/main_atmos.go index 3703ea1..6f6f575 100644 --- a/main_atmos.go +++ b/main_atmos.go @@ -44,6 +44,7 @@ type Config struct { CoverFormat string `yaml:"cover-format"` AlacSaveFolder string `yaml:"alac-save-folder"` AtmosSaveFolder string `yaml:"atmos-save-folder"` + AlbumFolderFormat string `yaml:"album-folder-format"` AtmosMax int `yaml:"atmos-max"` } @@ -1121,7 +1122,15 @@ func rip(albumId string, token string, storefront string, userToken string) erro } singerFoldername = strings.TrimSpace(singerFoldername) singerFolder := filepath.Join(config.AtmosSaveFolder, forbiddenNames.ReplaceAllString(singerFoldername, "_")) - albumFolder := fmt.Sprintf("%s [Atmos]", meta.Data[0].Attributes.Name) + albumFolder := strings.NewReplacer( + "{ReleaseDate}", meta.Data[0].Attributes.ReleaseDate, + "{ArtistName}", meta.Data[0].Attributes.ArtistName, + "{AlbumName}", meta.Data[0].Attributes.Name, + "{UPC}", meta.Data[0].Attributes.Upc, + "{Copyright}", meta.Data[0].Attributes.Copyright, + "{AlbumId}", albumId, + ).Replace(config.AlbumFolderFormat) + albumFolder = fmt.Sprintf("%s [Atmos]", albumFolder) if strings.HasSuffix(albumFolder, ".") { albumFolder = strings.ReplaceAll(albumFolder, ".", "") } diff --git a/main_select.go b/main_select.go index a05d19f..5381c3c 100644 --- a/main_select.go +++ b/main_select.go @@ -45,6 +45,7 @@ type Config struct { CoverFormat string `yaml:"cover-format"` AlacSaveFolder string `yaml:"alac-save-folder"` AtmosSaveFolder string `yaml:"atmos-save-folder"` + AlbumFolderFormat string `yaml:"album-folder-format"` AlacMax int `yaml:"alac-max"` } @@ -1124,7 +1125,14 @@ func rip(albumId string, token string, storefront string, userToken string) erro } singerFoldername = strings.TrimSpace(singerFoldername) singerFolder := filepath.Join("AM-DL downloads", forbiddenNames.ReplaceAllString(singerFoldername, "_")) - albumFolder := fmt.Sprintf("%s", meta.Data[0].Attributes.Name) + albumFolder := strings.NewReplacer( + "{ReleaseDate}", meta.Data[0].Attributes.ReleaseDate, + "{ArtistName}", meta.Data[0].Attributes.ArtistName, + "{AlbumName}", meta.Data[0].Attributes.Name, + "{UPC}", meta.Data[0].Attributes.Upc, + "{Copyright}", meta.Data[0].Attributes.Copyright, + "{AlbumId}", albumId, + ).Replace(config.AlbumFolderFormat) if strings.HasSuffix(albumFolder, ".") { albumFolder = strings.ReplaceAll(albumFolder, ".", "") }