48 lines
893 B
Go
48 lines
893 B
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) {
|
|
for _, m := range musicObjects {
|
|
if a, ok := m.(data.Artist); ok {
|
|
fmt.Println("artist: " + a.Name)
|
|
} else if a, ok := m.(data.Album); ok {
|
|
fmt.Println("release: " + a.Name)
|
|
} else if a, ok := m.(data.Song); ok {
|
|
fmt.Println("track: " + a.Name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func Shell() {
|
|
plugin.RegisterPlugin(plugin.Musify{})
|
|
|
|
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)
|
|
}
|
|
}
|