fix offlien scorbbling
This commit is contained in:
@@ -74,11 +74,12 @@ func GetSession(apiKey, secret, token string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Scrobble(apiKey, secret, session string,
|
func Scrobble(apiKey, secret, session string,
|
||||||
track *model.Track, stamp int, submission bool) error {
|
track *model.Track, stampMili int, submission bool) error {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
if submission {
|
if submission {
|
||||||
params.Add("method", "track.Scrobble")
|
params.Add("method", "track.Scrobble")
|
||||||
params.Add("timestamp", strconv.Itoa(stamp))
|
// last.fm wants the timestamp in seconds
|
||||||
|
params.Add("timestamp", strconv.Itoa(stampMili / 1e3))
|
||||||
} else {
|
} else {
|
||||||
params.Add("method", "track.updateNowPlaying")
|
params.Add("method", "track.updateNowPlaying")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,19 +103,16 @@ func (c *Controller) Scrobble(w http.ResponseWriter, r *http.Request) {
|
|||||||
Preload("Album").
|
Preload("Album").
|
||||||
Preload("AlbumArtist").
|
Preload("AlbumArtist").
|
||||||
First(&track, id)
|
First(&track, id)
|
||||||
// get time from args or use now
|
|
||||||
time := getIntParamOr(r, "time", int(time.Now().Unix()))
|
|
||||||
// get submission, where the default is true. we will
|
|
||||||
// check if it's false later
|
|
||||||
submission := getStrParamOr(r, "submission", "true")
|
|
||||||
// scrobble with above info
|
// scrobble with above info
|
||||||
err = lastfm.Scrobble(
|
err = lastfm.Scrobble(
|
||||||
c.GetSetting("lastfm_api_key"),
|
c.GetSetting("lastfm_api_key"),
|
||||||
c.GetSetting("lastfm_secret"),
|
c.GetSetting("lastfm_secret"),
|
||||||
user.LastFMSession,
|
user.LastFMSession,
|
||||||
&track,
|
&track,
|
||||||
time,
|
// clients will provide time in miliseconds, so use that or
|
||||||
submission != "false",
|
// instead convert UnixNano to miliseconds
|
||||||
|
getIntParamOr(r, "time", int(time.Now().UnixNano() / 1e6)),
|
||||||
|
getStrParamOr(r, "submission", "true") != "false",
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
respondError(w, r, 0, fmt.Sprintf("error when submitting: %v", err))
|
respondError(w, r, 0, fmt.Sprintf("error when submitting: %v", err))
|
||||||
|
|||||||
Reference in New Issue
Block a user