Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vvatanabe/spotify-playing-stream
spotify-playing-stream is a GO library for polling the currently-playing API on Spotify.
https://github.com/vvatanabe/spotify-playing-stream
Last synced: 24 days ago
JSON representation
spotify-playing-stream is a GO library for polling the currently-playing API on Spotify.
- Host: GitHub
- URL: https://github.com/vvatanabe/spotify-playing-stream
- Owner: vvatanabe
- License: mit
- Created: 2020-08-07T11:10:44.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-07T20:11:50.000Z (about 4 years ago)
- Last Synced: 2024-05-21T12:38:03.475Z (6 months ago)
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spotify-playing-stream
spotify-playing-stream is a GO library for polling the currently-playing API on Spotify.
## Requires
Go 1.14+
## Depends
github.com/zmb3/spotify
## Usage
```go
import "github.com/vvatanabe/spotify-playing-stream/stream"
```## Example
```go
package mainimport (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time""github.com/vvatanabe/spotify-playing-stream/stream"
"github.com/zmb3/spotify"
)func main() {
// should create a spotify client with auth
client := spotify.NewClient(http.DefaultClient)s := stream.Stream{
Conn: &client,
Handler: stream.HandlerFunc(func(playing *spotify.CurrentlyPlaying) {
externalURL := playing.Item.ExternalURLs["spotify"]
trackName := playing.Item.Name
artistName := playing.Item.Artists[0].Name
metadata := fmt.Sprintf("%s/%s", trackName, artistName)
log.Println("NOW PLAYING",
fmt.Sprintf("%s %s", metadata, externalURL))
}),
Interval: time.Second, // Minimum 1 Sec
LoggerFunc: log.Println,
}go func() {
log.Println("start to subscribe spotify playing stream")
err := s.Subscribe()
if err != nil {
log.Println(err)
}
}()sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt, syscall.SIGTERM)<-sigint
log.Println("received a signal of graceful shutdown")
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
err := s.Shutdown(ctx)
if err != nil {
log.Println("failed to graceful shutdown", err)
return
}
log.Println("completed graceful shutdown")
}
```## Acknowledgments
Inspired by [net/http](https://golang.org/pkg/net/http/)
## Bugs and Feedback
For bugs, questions and discussions please use the Github Issues.
## License
[MIT License](http://www.opensource.org/licenses/mit-license.php)
## Author
[vvatanabe](https://github.com/vvatanabe)