Checkpoint
This commit is contained in:
54 files changed
+6855
-526
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package mpd
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"go.maze.io/harmon/player"
|
||||
)
|
||||
|
||||
type artRequest struct {
|
||||
Path string
|
||||
Art chan image.Image
|
||||
}
|
||||
|
||||
func (d *Player) AlbumArt(track *player.Track) (image.Image, bool) {
|
||||
if track == nil || track.Path == "" {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if cached, ok := d.artCache.Load(track.Path); ok {
|
||||
return cached.(image.Image), true
|
||||
}
|
||||
|
||||
// Not in cache, request artwork through the art connection.
|
||||
art := make(chan image.Image)
|
||||
d.artRequest <- &artRequest{Path: track.Path, Art: art}
|
||||
|
||||
// Respond with image.
|
||||
if image := <-art; image != nil {
|
||||
return image, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (d *Player) artLoop(conn *clientConn) {
|
||||
for {
|
||||
select {
|
||||
case request := <-d.artRequest:
|
||||
logrus.WithField("path", request.Path).Debug("requesting album art")
|
||||
request.Art <- nil
|
||||
|
||||
case <-d.quit:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-4
@@ -6,6 +6,7 @@ import (
|
||||
"net/textproto"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -34,6 +35,8 @@ type Player struct {
|
||||
addr string
|
||||
password string
|
||||
idleSubsystems []string
|
||||
artCache sync.Map // map of path to image
|
||||
artRequest chan *artRequest
|
||||
commands chan *Command
|
||||
errors chan error
|
||||
quit chan struct{}
|
||||
@@ -94,10 +97,11 @@ func New(addr, password string) (*Player, error) {
|
||||
return nil, err
|
||||
}
|
||||
p := &Player{
|
||||
addr: addr,
|
||||
commands: make(chan *Command, 16),
|
||||
errors: make(chan error, 1),
|
||||
quit: make(chan struct{}, 2),
|
||||
addr: addr,
|
||||
commands: make(chan *Command, 16),
|
||||
artRequest: make(chan *artRequest, 16),
|
||||
errors: make(chan error, 1),
|
||||
quit: make(chan struct{}, 2),
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
@@ -301,6 +305,15 @@ func (p *Player) run(events chan player.Event) {
|
||||
continue
|
||||
}
|
||||
|
||||
art, _, err := newConn(p.addr, p.password, "art", p.name)
|
||||
if err != nil {
|
||||
_ = idle.Close()
|
||||
_ = main.Close()
|
||||
log.WithError(err).Warn("connection failed; retrying")
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
|
||||
p.commands = make(chan *Command)
|
||||
p.errors = make(chan error)
|
||||
p.quit = make(chan struct{}, 2)
|
||||
@@ -308,6 +321,7 @@ func (p *Player) run(events chan player.Event) {
|
||||
events <- player.NewConnectedEvent(p)
|
||||
|
||||
go p.idleLoop(idle)
|
||||
go p.artLoop(art)
|
||||
p.mainLoop(main, events)
|
||||
|
||||
events <- player.NewDisconnectedEvent(p)
|
||||
|
||||
Reference in new issue
Block a user