navidrome/api/media_annotation.go

46 lines
1.1 KiB
Go
Raw Normal View History

package api
import (
2016-03-15 22:06:23 +01:00
"fmt"
"time"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
2016-03-15 22:06:23 +01:00
"github.com/deluan/gosonic/domain"
"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
}
func (c *MediaAnnotationController) Prepare() {
2016-03-15 22:06:23 +01:00
utils.ResolveDependencies(&c.itunes, &c.mfRepo)
}
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))
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)
}