Music Pipeline Refactor
This commit is contained in:
@@ -121,7 +121,23 @@ type HAKConfig struct {
|
||||
}
|
||||
|
||||
type MusicConfig struct {
|
||||
Prefixes map[string]string `json:"prefixes" yaml:"prefixes"`
|
||||
Prefixes map[string]string `json:"prefixes,omitempty" yaml:"prefixes,omitempty"`
|
||||
Defaults *MusicDefaultsConfig `json:"defaults,omitempty" yaml:"defaults,omitempty"`
|
||||
Datasets map[string]MusicDatasetConfig `json:"datasets,omitempty" yaml:"datasets,omitempty"`
|
||||
}
|
||||
|
||||
type MusicDefaultsConfig struct {
|
||||
StageRoot string `json:"stage_root,omitempty" yaml:"stage_root,omitempty"`
|
||||
CreditsRoot string `json:"credits_root,omitempty" yaml:"credits_root,omitempty"`
|
||||
CreditsOverlay string `json:"credits_overlay,omitempty" yaml:"credits_overlay,omitempty"`
|
||||
MaxStemLength *int `json:"max_stem_length,omitempty" yaml:"max_stem_length,omitempty"`
|
||||
}
|
||||
|
||||
type MusicDatasetConfig struct {
|
||||
Source string `json:"source" yaml:"source"`
|
||||
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
||||
StageRoot string `json:"stage_root,omitempty" yaml:"stage_root,omitempty"`
|
||||
CreditsRoot string `json:"credits_root,omitempty" yaml:"credits_root,omitempty"`
|
||||
}
|
||||
|
||||
type TopDataConfig struct {
|
||||
@@ -871,6 +887,25 @@ func normalizeConfig(cfg *Config) {
|
||||
for i := range cfg.Autogen.Consumers {
|
||||
cfg.Autogen.Consumers[i].Include = normalizeStringSlice(cfg.Autogen.Consumers[i].Include)
|
||||
}
|
||||
normalizeMusicConfig(&cfg.Music)
|
||||
}
|
||||
|
||||
func normalizeMusicConfig(music *MusicConfig) {
|
||||
if len(music.Prefixes) > 0 && len(music.Datasets) == 0 {
|
||||
datasets := make(map[string]MusicDatasetConfig, len(music.Prefixes))
|
||||
for dir, prefix := range music.Prefixes {
|
||||
source := trimConfigSlashes(filepath.ToSlash(strings.TrimSpace(dir)))
|
||||
if source == "" {
|
||||
continue
|
||||
}
|
||||
key := strings.ReplaceAll(source, "/", "_")
|
||||
datasets[key] = MusicDatasetConfig{
|
||||
Source: source,
|
||||
Prefix: strings.TrimSpace(prefix),
|
||||
}
|
||||
}
|
||||
music.Datasets = datasets
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeStringSlice(input []string) []string {
|
||||
@@ -994,6 +1029,20 @@ func validateMusicConfig(cfg MusicConfig) []error {
|
||||
failures = append(failures, fmt.Errorf("music.prefixes[%q] must not be empty", root))
|
||||
}
|
||||
}
|
||||
seenSources := map[string]string{}
|
||||
for id, ds := range cfg.Datasets {
|
||||
if strings.TrimSpace(id) == "" {
|
||||
failures = append(failures, errors.New("music.datasets contains an empty key"))
|
||||
}
|
||||
source := trimConfigSlashes(filepath.ToSlash(strings.TrimSpace(ds.Source)))
|
||||
if source == "" {
|
||||
failures = append(failures, fmt.Errorf("music.datasets[%q].source is required", id))
|
||||
} else if prior, exists := seenSources[source]; exists {
|
||||
failures = append(failures, fmt.Errorf("music.datasets[%q].source %q conflicts with dataset %q", id, ds.Source, prior))
|
||||
} else {
|
||||
seenSources[source] = id
|
||||
}
|
||||
}
|
||||
return failures
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user