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"
"log"
"os"
"strconv"
"strings"
"gitea.elara.ws/Hazel/music-kraken/internal/data"
"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) {
if len(musicObjects) <= 0 {
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 {
fmt.Println("artist: " + a.Name)
results[i] += "#a " + a.Name
} else if a, ok := m.(data.Album); ok {
fmt.Print("release: " + a.Name)
results[i] += "#r " + a.Name
if len(a.Artists) > 0 {
names := make([]string, len(a.Artists))
for i, artist := range a.Artists {
names[i] = artist.Name
for _, artist := range a.Artists {
results[i] += " - " + artist.Name
}
fmt.Println(" by " + strings.Join(names, ", "))
} else {
fmt.Println()
}
} else if a, ok := m.(data.Song); ok {
fmt.Print("track: " + a.Name)
if len(a.Artists) > 0 {
names := make([]string, len(a.Artists))
for i, artist := range a.Artists {
names[i] = artist.Name
}
fmt.Println(" by " + strings.Join(names, ", "))
} else {
fmt.Println()
results[i] += "#s " + a.Name
if a.Album.Name != "" {
results[i] += " - " + a.Album.Name
}
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()
}

View File

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