getNowPlaying.view working

This commit is contained in:
Deluan 2016-03-17 10:37:19 -04:00
parent 68c456e188
commit c4b660fce3
6 changed files with 25 additions and 12 deletions

View File

@ -90,8 +90,21 @@ func (c *AlbumListController) GetStarred() {
}
func (c *AlbumListController) GetNowPlaying() {
npInfos, err := c.listGen.GetNowPlaying()
if err != nil {
beego.Error("Error retrieving now playing list:", err)
c.SendError(responses.ERROR_GENERIC, "Internal Error")
}
response := c.NewEmpty()
response.NowPlaying = &responses.NowPlaying{}
//response.NowPlaying.Entry = make([]responses.NowPlayingEntry, 1)
response.NowPlaying.Entry = make([]responses.NowPlayingEntry, len(*npInfos))
for i, entry := range *npInfos {
response.NowPlaying.Entry[i].Child = c.ToChild(entry)
response.NowPlaying.Entry[i].UserName = entry.UserName
response.NowPlaying.Entry[i].MinutesAgo = entry.MinutesAgo
response.NowPlaying.Entry[i].PlayerId = entry.PlayerId
response.NowPlaying.Entry[i].PlayerName = entry.PlayerName
}
c.SendResponse(response)
}

View File

@ -24,8 +24,8 @@ func (c *MediaAnnotationController) Scrobble() {
time := c.ParamTime("time", time.Now())
submission := c.ParamBool("submission", false)
playerName := c.Data["c"].(string)
username := c.Data["u"].(string)
playerName := c.ParamString("c")
username := c.ParamString("u")
if submission {
mf, err := c.scrobbler.Register(id, time)

View File

@ -141,10 +141,10 @@ type Starred struct {
type NowPlayingEntry struct {
Child
UserName string `xml:"username" json:"username,omitempty"`
MinutesAgo int `xml:"minutesAgo" json:"minutesAgo,omitempty"`
PlayerId int `xml:"playerId" json:"playerId,omitempty"`
PlayerName string `xml:"playerName" json:"playerName,omitempty"`
UserName string `xml:"username,attr" json:"username,omitempty"`
MinutesAgo int `xml:"minutesAgo,attr" json:"minutesAgo,omitempty"`
PlayerId int `xml:"playerId,attr" json:"playerId,omitempty"`
PlayerName string `xml:"playerName,attr" json:"playerName,omitempty"`
}
type NowPlaying struct {

View File

@ -32,7 +32,6 @@ func checkParameters(c BaseAPIController) {
logWarn(c, fmt.Sprintf(`Missing required parameter "%s"`, p))
abortRequest(c, responses.ERROR_MISSING_PARAMETER)
}
c.Data[p] = c.GetString(p)
}
}

View File

@ -4,10 +4,8 @@ import (
"math/rand"
"time"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/utils"
"github.com/syndtr/goleveldb/leveldb/errors"
)
// TODO Use Entries instead of Albums
@ -103,11 +101,11 @@ func (g listGenerator) GetNowPlaying() (*Entries, error) {
return nil, err
}
entries[i] = FromMediaFile(mf)
entries[i].UserName = beego.AppConfig.String("user")
entries[i].UserName = np.Username
entries[i].MinutesAgo = int(time.Now().Sub(np.Start).Minutes())
entries[i].PlayerId = np.PlayerId
entries[i].PlayerName = np.PlayerName
}
return &entries, errors.New("Not implemented")
return &entries, nil
}

View File

@ -40,6 +40,9 @@ func (r *nowPlayingRepository) GetAll() (*[]engine.NowPlayingInfo, error) {
if err != nil {
return nil, err
}
if val == nil {
return &[]engine.NowPlayingInfo{}, nil
}
info := &engine.NowPlayingInfo{}
err = json.Unmarshal(val, info)