feat: allow for custom music folder path alias

closes #259
This commit is contained in:
sentriz
2022-11-21 20:17:55 +00:00
parent 92a73b2d61
commit 7e097c9bdf
6 changed files with 81 additions and 32 deletions

61
paths/paths.go Normal file
View File

@@ -0,0 +1,61 @@
package paths
import (
"fmt"
"path/filepath"
"strings"
)
const sep = "->"
type MusicPaths []MusicPath
func (mps MusicPaths) String() string {
var strs []string
for _, path := range mps {
strs = append(strs, path.String())
}
return strings.Join(strs, ", ")
}
func (mps *MusicPaths) Set(value string) error {
alias, path, ok := strings.Cut(value, sep)
if !ok {
*mps = append(*mps, MusicPath{
Path: filepath.Clean(strings.TrimSpace(value)),
})
return nil
}
*mps = append(*mps, MusicPath{
Alias: strings.TrimSpace(alias),
Path: filepath.Clean(strings.TrimSpace(path)),
})
return nil
}
func (mps MusicPaths) Paths() []string {
var paths []string
for _, mp := range mps {
paths = append(paths, mp.Path)
}
return paths
}
type MusicPath struct {
Alias string
Path string
}
func (mp MusicPath) String() string {
if mp.Alias == "" {
return mp.Path
}
return fmt.Sprintf("%s %s %s", mp.Alias, sep, mp.Path)
}
func (mp MusicPath) DisplayAlias() string {
if mp.Alias == "" {
return filepath.Base(mp.Path)
}
return mp.Alias
}