Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:41 +01:00
1 parent b8a493b93d
commit 85a9ec684c
54 files changed
+6855 -526

No files matched your search

+5
View File
@@ -3,6 +3,7 @@ package moode
import (
"bufio"
"fmt"
"image"
"os"
"strconv"
"strings"
@@ -49,6 +50,10 @@ func (Player) Pause() error { return nil }
func (Player) Play() error { return nil }
func (Player) Seek(time.Duration) error { return nil }
func (p *Player) AlbumArt(t *player.Track) (image.Image, bool) {
return p.mpd.AlbumArt(t)
}
func (Player) Status() *player.Status {
s, _ := parseStatus(currentSongFile)
return s
+47
View File
@@ -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
View File
@@ -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)
+5
View File
@@ -25,6 +25,7 @@ type Player interface {
// Status of the player
Status() *Status
// Player controls
Play() error
Pause() error
Next() error
@@ -32,6 +33,10 @@ type Player interface {
Seek(time.Duration) error
}
type AlbumArt interface {
AlbumArt(*Track) (image.Image, bool)
}
// AudioFormat is the audio format.
type AudioFormat struct {
Encoding string
+5
View File
@@ -1,6 +1,7 @@
package volumio
import (
"image"
"time"
"go.maze.io/harmon/config"
@@ -47,3 +48,7 @@ func (p *Player) Seek(d time.Duration) error { return p.mpd.Seek(d) }
func (p *Player) Events() (<-chan player.Event, error) {
return p.mpd.Events()
}
func (p *Player) AlbumArt(t *player.Track) (image.Image, bool) {
return p.mpd.AlbumArt(t)
}