Scrobble working!!! I mean, iTunes scrobble, not Last.FM (for now)

This commit is contained in:
Deluan
2016-03-11 20:49:01 -05:00
parent 329297dab8
commit d23f5ca635
8 changed files with 147 additions and 8 deletions
+10 -1
View File
@@ -29,8 +29,11 @@ func (c *BaseAPIController) ParamString(param string) string {
return c.Input().Get(param)
}
func (c *BaseAPIController) ParamTime(param string) time.Time {
func (c *BaseAPIController) ParamTime(param string, def time.Time) time.Time {
var value int64
if c.Input().Get(param) == "" {
return def
}
c.Ctx.Input.Bind(&value, param)
return utils.ToTime(value)
}
@@ -41,6 +44,12 @@ func (c *BaseAPIController) ParamInt(param string, def int) int {
return value
}
func (c *BaseAPIController) ParamBool(param string, def bool) bool {
value := def
c.Ctx.Input.Bind(&value, param)
return value
}
func (c *BaseAPIController) SendError(errorCode int, message ...interface{}) {
response := responses.Subsonic{Version: beego.AppConfig.String("apiVersion"), Status: "fail"}
var msg string
+3 -1
View File
@@ -3,6 +3,8 @@ package api
import (
"fmt"
"time"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/engine"
@@ -32,7 +34,7 @@ func (c *BrowsingController) GetMediaFolders() {
// TODO: Shortcuts amd validate musicFolder parameter
func (c *BrowsingController) GetIndexes() {
ifModifiedSince := c.ParamTime("ifModifiedSince")
ifModifiedSince := c.ParamTime("ifModifiedSince", time.Time{})
indexes, lastModified, err := c.browser.Indexes(ifModifiedSince)
if err != nil {
+36
View File
@@ -0,0 +1,36 @@
package api
import (
"time"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/itunesbridge"
"github.com/deluan/gosonic/utils"
)
type MediaAnnotationController struct {
BaseAPIController
itunes itunesbridge.ItunesControl
}
func (c *MediaAnnotationController) Prepare() {
utils.ResolveDependencies(&c.itunes)
}
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 {
beego.Debug("Scrobbling", id, "at", 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)
}
+1
View File
@@ -11,5 +11,6 @@ func (c *UsersController) GetUser() {
r.User.Username = c.RequiredParamString("username", "Required string parameter 'username' is not present")
r.User.StreamRole = true
r.User.DownloadRole = true
r.User.ScrobblingEnabled = true
c.SendResponse(r)
}