2016-03-12 02:49:01 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2016-03-15 22:06:23 +01:00
|
|
|
"fmt"
|
2016-03-12 02:49:01 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/astaxie/beego"
|
|
|
|
"github.com/deluan/gosonic/api/responses"
|
2016-03-16 22:48:44 +01:00
|
|
|
"github.com/deluan/gosonic/engine"
|
2016-03-12 02:49:01 +01:00
|
|
|
"github.com/deluan/gosonic/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MediaAnnotationController struct {
|
|
|
|
BaseAPIController
|
2016-03-16 22:48:44 +01:00
|
|
|
scrobbler engine.Scrobbler
|
2016-03-12 02:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MediaAnnotationController) Prepare() {
|
2016-03-16 22:48:44 +01:00
|
|
|
utils.ResolveDependencies(&c.scrobbler)
|
2016-03-12 02:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MediaAnnotationController) Scrobble() {
|
|
|
|
id := c.RequiredParamString("id", "Required id parameter is missing")
|
|
|
|
time := c.ParamTime("time", time.Now())
|
2016-03-16 22:48:44 +01:00
|
|
|
submission := c.ParamBool("submission", false)
|
2016-03-17 14:34:32 +01:00
|
|
|
|
|
|
|
playerName := c.Data["c"].(string)
|
|
|
|
username := c.Data["u"].(string)
|
|
|
|
|
2016-03-12 02:49:01 +01:00
|
|
|
if submission {
|
2016-03-17 01:45:08 +01:00
|
|
|
mf, err := c.scrobbler.Register(id, time)
|
2016-03-16 22:48:44 +01:00
|
|
|
if err != nil {
|
2016-03-12 02:49:01 +01:00
|
|
|
beego.Error("Error scrobbling:", err)
|
|
|
|
c.SendError(responses.ERROR_GENERIC, "Internal error")
|
|
|
|
}
|
2016-03-16 22:48:44 +01:00
|
|
|
beego.Info(fmt.Sprintf(`Scrobbled (%s) "%s" at %v`, id, mf.Title, time))
|
2016-03-17 02:04:41 +01:00
|
|
|
} else {
|
2016-03-17 14:34:32 +01:00
|
|
|
mf, err := c.scrobbler.NowPlaying(id, username, playerName)
|
2016-03-17 02:04:41 +01:00
|
|
|
if err != nil {
|
|
|
|
beego.Error("Error setting", id, "as current song:", err)
|
|
|
|
c.SendError(responses.ERROR_GENERIC, "Internal error")
|
|
|
|
}
|
|
|
|
beego.Info(fmt.Sprintf(`Current Song (%s) "%s" at %v`, id, mf.Title, time))
|
2016-03-12 02:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
response := c.NewEmpty()
|
|
|
|
c.SendResponse(response)
|
|
|
|
}
|