diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2022-07-21 21:14:14 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2022-07-21 21:14:14 +0200 |
| commit | 8b4335c18752ce96e452dc232e57695c2fdf6a6d (patch) | |
| tree | e191e079b607126a890a0bf1498a3f8167a8204e /spotify.go | |
| parent | a14ffdfc999abd76c2d9937e778c932a457be08f (diff) | |
| download | WRMS-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.go | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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{} } |
