From 8b4335c18752ce96e452dc232e57695c2fdf6a6d Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 21 Jul 2022 21:14:14 +0200 Subject: intermediate commit * add dummy backend * enable spotify searching * JS: use let instead of var * improve logging * support adding new songs from search * rename Song.Id to Song.Uri --- spotify.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'spotify.go') diff --git a/spotify.go b/spotify.go index a813254..a4d8080 100644 --- a/spotify.go +++ b/spotify.go @@ -9,6 +9,7 @@ package main import ( "errors" + "fmt" "os" // "github.com/librespot-org/librespot-golang/Spotify" @@ -64,6 +65,29 @@ func (spotify *SpotifyBackend) Pause() { } func (spotify *SpotifyBackend) Search(keyword string) []Song { + session := spotify.session + resp, err := session.Mercury().Search(keyword, 12, session.Country(), session.Username()) + + if err != nil { + fmt.Println("Failed to search:", err) + return []Song{} + } + + res := resp.Results + + fmt.Println("Search results for ", keyword) + fmt.Println("=============================") + + if res.Error != nil { + fmt.Println("Search result error:", res.Error) + } + + fmt.Printf("\nTracks: %d (total %d)\n", len(res.Tracks.Hits), res.Tracks.Total) + + for _, track := range res.Tracks.Hits { + fmt.Printf(" => %v (%s)\n", track, track.Uri) + } + return []Song{} } -- cgit v1.2.3