aboutsummaryrefslogtreecommitdiff
path: root/spotify.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2022-07-21 21:14:14 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2022-07-21 21:14:14 +0200
commit8b4335c18752ce96e452dc232e57695c2fdf6a6d (patch)
treee191e079b607126a890a0bf1498a3f8167a8204e /spotify.go
parenta14ffdfc999abd76c2d9937e778c932a457be08f (diff)
downloadWRMS-8b4335c18752ce96e452dc232e57695c2fdf6a6d.tar.gz
WRMS-8b4335c18752ce96e452dc232e57695c2fdf6a6d.zip
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
Diffstat (limited to 'spotify.go')
-rw-r--r--spotify.go24
1 files changed, 24 insertions, 0 deletions
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{}
}