aboutsummaryrefslogtreecommitdiffstats
path: root/apiv1.go
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2017-06-17 12:49:28 -0400
committerThibaut Horel <thibaut.horel@gmail.com>2017-06-17 12:49:28 -0400
commit858de1edf50cc1128f6b621a5413b2975ca446eb (patch)
tree09cec370362844ac9a3fc7c6a128808f632894c7 /apiv1.go
parent060b315f74f437fe36175c4ddb52379d29808d64 (diff)
downloadlastfm-api-858de1edf50cc1128f6b621a5413b2975ca446eb.tar.gz
Clean fecthing of song metadata from Last.fm
Diffstat (limited to 'apiv1.go')
-rw-r--r--apiv1.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/apiv1.go b/apiv1.go
index 1f96819..4cf8941 100644
--- a/apiv1.go
+++ b/apiv1.go
@@ -180,7 +180,7 @@ func (app *App) scrobbleHandler(w http.ResponseWriter, r *http.Request) {
scrobbles, _ := parseScrobbles(r.Form, session)
for i, s := range scrobbles {
- app.GetSong(&s)
+ app.GetScrobbleSong(&s)
scrobbles[i] = s
}
@@ -211,6 +211,19 @@ func parseNowPlaying(values url.Values) (Scrobble, error) {
return scrobble, nil
}
+func (app *App) GetScrobbleSong(s *Scrobble) {
+ song := Song{
+ Artist: s.Artist.Name,
+ Album: s.Album.Name,
+ Name: s.TrackName.Name,
+ TrackNumber: s.TrackNumber,
+ Duration: s.Duration * 1000,
+ Mbid: s.Mbid,
+ }
+ app.GetSong(&song)
+ s.SongId = song.Id
+}
+
func (app *App) nowPlayingHandler(w http.ResponseWriter, r *http.Request) {
session, err := app.GetSession(r.FormValue("s"))
if err != nil {
@@ -221,7 +234,7 @@ func (app *App) nowPlayingHandler(w http.ResponseWriter, r *http.Request) {
s, err := parseNowPlaying(r.Form)
s.SessionKey = session.Key
s.UserId = session.UserId
- app.GetSong(&s)
+ app.GetScrobbleSong(&s)
if err := app.PutNowPlaying(s); err != nil {
log.Println(err)
fmt.Fprintln(w, "Failed Database")