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-15 22:06:23 +01:00
|
|
|
"github.com/deluan/gosonic/domain"
|
2016-03-12 02:49:01 +01:00
|
|
|
"github.com/deluan/gosonic/itunesbridge"
|
|
|
|
"github.com/deluan/gosonic/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MediaAnnotationController struct {
|
|
|
|
BaseAPIController
|
|
|
|
itunes itunesbridge.ItunesControl
|
2016-03-15 22:06:23 +01:00
|
|
|
mfRepo domain.MediaFileRepository
|
2016-03-12 02:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MediaAnnotationController) Prepare() {
|
2016-03-15 22:06:23 +01:00
|
|
|
utils.ResolveDependencies(&c.itunes, &c.mfRepo)
|
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())
|
|
|
|
submission := c.ParamBool("submission", true)
|
|
|
|
|
|
|
|
if submission {
|
2016-03-15 22:06:23 +01:00
|
|
|
mf, err := c.mfRepo.Get(id)
|
|
|
|
if err != nil || mf == nil {
|
|
|
|
beego.Error("Id", id, "not found!")
|
|
|
|
c.SendError(responses.ERROR_DATA_NOT_FOUND, "Id not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
beego.Info(fmt.Sprintf(`Scrobbling (%s) "%s" at %v`, id, mf.Title, time))
|
2016-03-12 02:49:01 +01:00
|
|
|
if err := c.itunes.Scrobble(id, time); err != nil {
|
|
|
|
beego.Error("Error scrobbling:", err)
|
|
|
|
c.SendError(responses.ERROR_GENERIC, "Internal error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response := c.NewEmpty()
|
|
|
|
c.SendResponse(response)
|
|
|
|
}
|