add explicit-choice,clean-choice,apple-master-choice

This commit is contained in:
zhaarey
2024-06-04 18:21:01 +08:00
parent 4a6ec9ef43
commit 06a78c9009
4 changed files with 167 additions and 8 deletions

55
main.go
View File

@ -46,6 +46,10 @@ type Config struct {
AlacSaveFolder string `yaml:"alac-save-folder"`
AtmosSaveFolder string `yaml:"atmos-save-folder"`
AlbumFolderFormat string `yaml:"album-folder-format"`
SongFileFormat string `yaml:"song-file-format"`
ExplicitChoice string `yaml:"explicit-choice"`
CleanChoice string `yaml:"clean-choice"`
AppleMasterChoice string `yaml:"apple-master-choice"`
ForceApi bool `yaml:"force-api"`
Check string `yaml:"check"`
GetM3u8FromDevice bool `yaml:"get-m3u8-from-device"`
@ -1172,6 +1176,21 @@ func rip(albumId string, token string, storefront string, userToken string) erro
"{Copyright}", meta.Data[0].Attributes.Copyright,
"{AlbumId}", albumId,
).Replace(config.AlbumFolderFormat)
if meta.Data[0].Attributes.IsMasteredForItunes{
if config.AppleMasterChoice != ""{
albumFolder = fmt.Sprintf("%s %s", albumFolder,config.AppleMasterChoice)
}
}
if meta.Data[0].Attributes.ContentRating=="explicit"{
if config.ExplicitChoice != ""{
albumFolder = fmt.Sprintf("%s %s", albumFolder,config.ExplicitChoice)
}
}
if meta.Data[0].Attributes.ContentRating=="clean"{
if config.CleanChoice != ""{
albumFolder = fmt.Sprintf("%s %s", albumFolder,config.CleanChoice)
}
}
if strings.HasSuffix(albumFolder, ".") {
albumFolder = strings.ReplaceAll(albumFolder, ".", "")
}
@ -1198,8 +1217,30 @@ func rip(albumId string, token string, storefront string, userToken string) erro
fmt.Println("Unavailable in ALAC.")
continue
}
filename := fmt.Sprintf("%02d. %s.m4a", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
lrcFilename := fmt.Sprintf("%02d. %s.lrc", trackNum, forbiddenNames.ReplaceAllString(track.Attributes.Name, "_"))
songName := strings.NewReplacer(
"{SongNumer}", fmt.Sprintf("%02d", trackNum),
"{SongName}", track.Attributes.Name,
"{DiscNumber}", fmt.Sprintf("%0d", track.Attributes.DiscNumber),
"{TrackNumber}", fmt.Sprintf("%0d", track.Attributes.TrackNumber),
).Replace(config.SongFileFormat)
if track.Attributes.IsAppleDigitalMaster{
if config.AppleMasterChoice != ""{
songName = fmt.Sprintf("%s %s", songName,config.AppleMasterChoice)
}
}
if track.Attributes.ContentRating=="explicit"{
if config.ExplicitChoice != ""{
songName = fmt.Sprintf("%s %s", songName,config.ExplicitChoice)
}
}
if track.Attributes.ContentRating=="clean"{
if config.CleanChoice != ""{
songName = fmt.Sprintf("%s %s", songName,config.CleanChoice)
}
}
fmt.Println(songName)
filename := fmt.Sprintf("%s.m4a", forbiddenNames.ReplaceAllString(songName, "_"))
lrcFilename := fmt.Sprintf("%s.lrc", forbiddenNames.ReplaceAllString(songName, "_"))
trackPath := filepath.Join(sanAlbumFolder, filename)
var lrc string = ""
if userToken != "your-media-user-token" && (config.EmbedLrc || config.SaveLrcFile) {
@ -1778,6 +1819,8 @@ type SongAttributes struct {
EnhancedHls string `json:"enhancedHls"`
} `json:"extendedAssetUrls"`
IsMasteredForItunes bool `json:"isMasteredForItunes"`
IsAppleDigitalMaster bool `json:"isAppleDigitalMaster"`
ContentRating string `json:"contentRating"`
ReleaseDate string `json:"releaseDate"`
Name string `json:"name"`
Isrc string `json:"isrc"`
@ -1793,6 +1836,8 @@ type AlbumAttributes struct {
GenreNames []string `json:"genreNames"`
TrackCount int `json:"trackCount"`
IsMasteredForItunes bool `json:"isMasteredForItunes"`
IsAppleDigitalMaster bool `json:"isAppleDigitalMaster"`
ContentRating string `json:"contentRating"`
ReleaseDate string `json:"releaseDate"`
Name string `json:"name"`
RecordLabel string `json:"recordLabel"`
@ -1967,6 +2012,8 @@ type AutoGenerated struct {
GenreNames []string `json:"genreNames"`
TrackCount int `json:"trackCount"`
IsMasteredForItunes bool `json:"isMasteredForItunes"`
IsAppleDigitalMaster bool `json:"isAppleDigitalMaster"`
ContentRating string `json:"contentRating"`
ReleaseDate string `json:"releaseDate"`
Name string `json:"name"`
RecordLabel string `json:"recordLabel"`
@ -2022,6 +2069,8 @@ type AutoGenerated struct {
GenreNames []string `json:"genreNames"`
HasTimeSyncedLyrics bool `json:"hasTimeSyncedLyrics"`
IsMasteredForItunes bool `json:"isMasteredForItunes"`
IsAppleDigitalMaster bool `json:"isAppleDigitalMaster"`
ContentRating string `json:"contentRating"`
DurationInMillis int `json:"durationInMillis"`
ReleaseDate string `json:"releaseDate"`
Name string `json:"name"`
@ -2083,6 +2132,8 @@ type AutoGeneratedTrack struct {
GenreNames []string `json:"genreNames"`
HasTimeSyncedLyrics bool `json:"hasTimeSyncedLyrics"`
IsMasteredForItunes bool `json:"isMasteredForItunes"`
IsAppleDigitalMaster bool `json:"isAppleDigitalMaster"`
ContentRating string `json:"contentRating"`
DurationInMillis int `json:"durationInMillis"`
ReleaseDate string `json:"releaseDate"`
Name string `json:"name"`