Compare commits

..

3 Commits

Author SHA1 Message Date
Hazel Noack
3dd03491ca pretty shell 2025-10-08 13:19:30 +02:00
Hazel Noack
043f5e9b55 improved printing results 2025-10-08 13:06:39 +02:00
Hazel Noack
c5a74c5f97 tried improving shell 2025-10-08 12:38:56 +02:00
2 changed files with 44 additions and 22 deletions

View File

@@ -5,48 +5,57 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"strconv"
"strings" "strings"
"gitea.elara.ws/Hazel/music-kraken/internal/data" "gitea.elara.ws/Hazel/music-kraken/internal/data"
"gitea.elara.ws/Hazel/music-kraken/internal/plugin" "gitea.elara.ws/Hazel/music-kraken/internal/plugin"
) )
func zeroPad(num int, length int) string {
str := strconv.Itoa(num)
if len(str) >= length {
return str
}
return strings.Repeat("0", length-len(str)) + str
}
func printResults(musicObjects []data.MusicObject) { func printResults(musicObjects []data.MusicObject) {
if len(musicObjects) <= 0 { if len(musicObjects) <= 0 {
return return
} }
for _, m := range musicObjects { results := make([]string, len(musicObjects))
for i, m := range musicObjects {
results[i] = zeroPad(i, 2) + ": "
if a, ok := m.(data.Artist); ok { if a, ok := m.(data.Artist); ok {
fmt.Println("artist: " + a.Name) results[i] += "#a " + a.Name
} else if a, ok := m.(data.Album); ok { } else if a, ok := m.(data.Album); ok {
fmt.Print("release: " + a.Name) results[i] += "#r " + a.Name
if len(a.Artists) > 0 { for _, artist := range a.Artists {
names := make([]string, len(a.Artists)) results[i] += " - " + artist.Name
for i, artist := range a.Artists {
names[i] = artist.Name
}
fmt.Println(" by " + strings.Join(names, ", "))
} else {
fmt.Println()
} }
} else if a, ok := m.(data.Song); ok { } else if a, ok := m.(data.Song); ok {
fmt.Print("track: " + a.Name) results[i] += "#s " + a.Name
if len(a.Artists) > 0 {
names := make([]string, len(a.Artists)) if a.Album.Name != "" {
for i, artist := range a.Artists { results[i] += " - " + a.Album.Name
names[i] = artist.Name
}
fmt.Println(" by " + strings.Join(names, ", "))
} else {
fmt.Println()
} }
for _, artist := range a.Artists {
results[i] += " - " + artist.Name
}
}
for _, source := range m.GetSources() {
results[i] += "\n\t- " + source.Url
} }
} }
fmt.Println(strings.Join(results, "\n"))
fmt.Println() fmt.Println()
} }

View File

@@ -7,6 +7,7 @@ import (
) )
type MusicObject interface { type MusicObject interface {
GetSources() []Source
Compile() MusicObject Compile() MusicObject
GetIndices() []string GetIndices() []string
Merge(other MusicObject) MusicObject Merge(other MusicObject) MusicObject
@@ -70,6 +71,10 @@ type Song struct {
Sources []Source Sources []Source
} }
func (m Song) GetSources() []Source {
return m.Sources
}
func (m Song) GetIndices() []string { func (m Song) GetIndices() []string {
res := sourceIndices(m.Sources) res := sourceIndices(m.Sources)
if m.UnifiedName != "" { if m.UnifiedName != "" {
@@ -122,6 +127,10 @@ type Album struct {
Sources []Source Sources []Source
} }
func (m Album) GetSources() []Source {
return m.Sources
}
func (m Album) GetIndices() []string { func (m Album) GetIndices() []string {
res := sourceIndices(m.Sources) res := sourceIndices(m.Sources)
if m.UnifiedName != "" { if m.UnifiedName != "" {
@@ -174,6 +183,10 @@ type Artist struct {
Sources []Source Sources []Source
} }
func (m Artist) GetSources() []Source {
return m.Sources
}
func (m Artist) Merge(other MusicObject) MusicObject { func (m Artist) Merge(other MusicObject) MusicObject {
otherArtist, ok := other.(Artist) otherArtist, ok := other.(Artist)
if !ok { if !ok {