remove jukebox's dependency on ctrlsubsonic
This commit is contained in:
@@ -10,11 +10,11 @@ import (
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
"go.senan.xyz/gonic/server/db"
|
||||
"go.senan.xyz/gonic/server/scanner"
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/params"
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/spec"
|
||||
"go.senan.xyz/gonic/server/db"
|
||||
"go.senan.xyz/gonic/server/lastfm"
|
||||
"go.senan.xyz/gonic/server/scanner"
|
||||
)
|
||||
|
||||
func lowerUDecOrHash(in string) string {
|
||||
@@ -329,6 +329,23 @@ func (c *Controller) ServeJukebox(r *http.Request) *spec.Response {
|
||||
}
|
||||
return tracks
|
||||
}
|
||||
getStatus := func() spec.JukeboxStatus {
|
||||
status := c.Jukebox.GetStatus()
|
||||
return spec.JukeboxStatus{
|
||||
CurrentIndex: status.CurrentIndex,
|
||||
Playing: status.Playing,
|
||||
Gain: status.Gain,
|
||||
Position: status.Position,
|
||||
}
|
||||
}
|
||||
getStatusTracks := func() []*spec.TrackChild {
|
||||
tracks := c.Jukebox.GetTracks()
|
||||
ret := make([]*spec.TrackChild, len(tracks))
|
||||
for i, track := range tracks {
|
||||
ret[i] = spec.NewTrackByTags(track, track.Album)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
switch act := params.Get("action"); act {
|
||||
case "set":
|
||||
c.Jukebox.SetTracks(getTracks())
|
||||
@@ -354,11 +371,16 @@ func (c *Controller) ServeJukebox(r *http.Request) *spec.Response {
|
||||
c.Jukebox.Skip(index)
|
||||
case "get":
|
||||
sub := spec.NewResponse()
|
||||
sub.JukeboxPlaylist = c.Jukebox.GetTracks()
|
||||
sub.JukeboxPlaylist = &spec.JukeboxPlaylist{
|
||||
JukeboxStatus: getStatus(),
|
||||
List: getStatusTracks(),
|
||||
}
|
||||
return sub
|
||||
}
|
||||
// all actions except get are expected to return a status
|
||||
sub := spec.NewResponse()
|
||||
sub.JukeboxStatus = c.Jukebox.Status()
|
||||
sub.JukeboxPlaylist = &spec.JukeboxPlaylist{
|
||||
JukeboxStatus: getStatus(),
|
||||
}
|
||||
return sub
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ import (
|
||||
"github.com/faiface/beep/speaker"
|
||||
|
||||
"go.senan.xyz/gonic/server/db"
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/spec"
|
||||
)
|
||||
|
||||
type strmInfo struct {
|
||||
ctrlStrmr beep.Ctrl
|
||||
strm beep.StreamSeekCloser
|
||||
format beep.Format
|
||||
type Status struct {
|
||||
CurrentIndex int
|
||||
Playing bool
|
||||
Gain float64
|
||||
Position int
|
||||
}
|
||||
|
||||
type Jukebox struct {
|
||||
@@ -39,6 +39,12 @@ type Jukebox struct {
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
type strmInfo struct {
|
||||
ctrlStrmr beep.Ctrl
|
||||
strm beep.StreamSeekCloser
|
||||
format beep.Format
|
||||
}
|
||||
|
||||
type updateType string
|
||||
|
||||
const (
|
||||
@@ -227,13 +233,13 @@ func (j *Jukebox) Start() {
|
||||
j.updates <- update{action: start}
|
||||
}
|
||||
|
||||
func (j *Jukebox) Status() *spec.JukeboxStatus {
|
||||
func (j *Jukebox) GetStatus() Status {
|
||||
position := 0
|
||||
if j.info != nil {
|
||||
length := j.info.format.SampleRate.D(j.info.strm.Position())
|
||||
position = int(length.Round(time.Millisecond).Seconds())
|
||||
}
|
||||
return &spec.JukeboxStatus{
|
||||
return Status{
|
||||
CurrentIndex: j.index,
|
||||
Playing: j.playing,
|
||||
Gain: 0.9,
|
||||
@@ -241,21 +247,8 @@ func (j *Jukebox) Status() *spec.JukeboxStatus {
|
||||
}
|
||||
}
|
||||
|
||||
func (j *Jukebox) GetTracks() *spec.JukeboxPlaylist {
|
||||
func (j *Jukebox) GetTracks() []*db.Track {
|
||||
j.Lock()
|
||||
defer j.Unlock()
|
||||
jb := &spec.JukeboxPlaylist{}
|
||||
jb.List = make([]*spec.TrackChild, len(j.playlist))
|
||||
for i, track := range j.playlist {
|
||||
jb.List[i] = spec.NewTrackByTags(track, track.Album)
|
||||
}
|
||||
jb.CurrentIndex = j.index
|
||||
jb.Playing = j.playing
|
||||
jb.Gain = 0.9
|
||||
jb.Position = 0
|
||||
if j.info != nil {
|
||||
length := j.info.format.SampleRate.D(j.info.strm.Position())
|
||||
jb.Position = int(length.Round(time.Millisecond).Seconds())
|
||||
}
|
||||
return jb
|
||||
return j.playlist
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user