72 lines
1.2 KiB
Go
72 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
|
"gitea.elara.ws/Hazel/music-kraken/internal/plugin"
|
|
)
|
|
|
|
func printResults(musicObjects []data.MusicObject) {
|
|
if len(musicObjects) <= 0 {
|
|
return
|
|
}
|
|
|
|
for _, m := range musicObjects {
|
|
if a, ok := m.(data.Artist); ok {
|
|
fmt.Print("#a " + a.Name)
|
|
|
|
} else if a, ok := m.(data.Album); ok {
|
|
fmt.Print("#r " + a.Name)
|
|
|
|
for _, artist := range a.Artists {
|
|
fmt.Print(" - " + artist.Name)
|
|
}
|
|
} else if a, ok := m.(data.Song); ok {
|
|
fmt.Print("#s " + a.Name)
|
|
|
|
if a.Album.Name != "" {
|
|
fmt.Print(" - " + a.Album.Name)
|
|
}
|
|
|
|
for _, artist := range a.Artists {
|
|
fmt.Print(" - " + artist.Name)
|
|
}
|
|
}
|
|
|
|
fmt.Println()
|
|
}
|
|
|
|
fmt.Println()
|
|
}
|
|
|
|
func Shell() {
|
|
plugin.RegisterPlugin(&plugin.Musify{})
|
|
|
|
fmt.Println("== MusicKraken Shell ==")
|
|
fmt.Println()
|
|
|
|
for {
|
|
fmt.Print("> ")
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
line, err := reader.ReadString('\n')
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return
|
|
}
|
|
|
|
searchResults, err := plugin.Search(line, plugin.SearchConfig{IgnoreErrors: false})
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
fmt.Println()
|
|
}
|
|
|
|
fmt.Println()
|
|
printResults(searchResults)
|
|
}
|
|
}
|