summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2016-11-22 22:41:59 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2016-11-22 22:41:59 -0500
commitfbb328b6c33470f8aec74fcb5e6e7d0388067c1e (patch)
tree6e33586135c23841e6760effc3b54835e7c2bb4c
parent47ae04e16e467d4fc2114c89e24efdb14223c8f4 (diff)
downloadlastfm-api-fbb328b6c33470f8aec74fcb5e6e7d0388067c1e.tar.gz
better marshalling
-rw-r--r--data.go8
-rw-r--r--main.go6
-rw-r--r--modern.go27
3 files changed, 27 insertions, 14 deletions
diff --git a/data.go b/data.go
index bced353..a844630 100644
--- a/data.go
+++ b/data.go
@@ -10,10 +10,10 @@ import (
)
type Scrobble struct {
- Artist string
- AlbumArtist string
- TrackName string
- Album string
+ Artist Correctable `xml:"artist" json:"artist"`
+ AlbumArtist Correctable `xml:"albumArtist" json:"albumArtist"`
+ TrackName Correctable `xml:"track" json:"albumArtist"`
+ Album Correctable `xml:"album" json:album"`
TrackNumber int
Duration int
Time int
diff --git a/main.go b/main.go
index 8675de1..0ad8e89 100644
--- a/main.go
+++ b/main.go
@@ -67,14 +67,14 @@ func parseValues(values url.Values) map[int]url.Values {
func parsePart(values url.Values) (Scrobble, error) {
var scrobble Scrobble
- scrobble.TrackName = values.Get("t")
- scrobble.Artist = values.Get("a")
+ scrobble.TrackName = NewCorrectable(values.Get("t"))
+ scrobble.Artist = NewCorrectable(values.Get("a"))
time, err := strconv.Atoi(values.Get("i"))
if err != nil {
return scrobble, errors.New("Could not parse timestamp")
}
scrobble.Time = time
- scrobble.Album = values.Get("b")
+ scrobble.Album = NewCorrectable(values.Get("b"))
scrobble.Mbid = values.Get("m")
tn, err := strconv.Atoi(values.Get("n"))
if err != nil {
diff --git a/modern.go b/modern.go
index 4a95f32..8a384c3 100644
--- a/modern.go
+++ b/modern.go
@@ -25,18 +25,31 @@ type Token struct {
string
}
+type Attrs struct {
+ Accepted int `xml:"accepted,attr" json:"accepted"`
+ Ignored int `xml:"ignored,attr" json:"ignored"`
+}
+
type Scrobbles struct {
- XMLName xml.Name `xml:"scrobbles"`
- Scrobbles []Scrobble
+ XMLName xml.Name `xml:"scrobbles" json:scrobbles"`
+ Scrobbles []Scrobble `xml:"scrobble" json:scrobble`
+ Attrs `json:"@attr"`
}
-type Scrobble struct {
- Track Track `xml:"track"`
+type Correctable struct {
+ Corrected int `xml:"corrected,attr" json:"corrected"`
+ Name string `xml:",chardata" json:"#text"`
+}
+
+func NewCorrectable(name string) Correctable {
+ return Correctable{
+ Corrected: 0,
+ Name: name,
+ }
}
-type Track struct {
- Corrected int `xml:"corrected,attr"`
- Name string `xml:",chardata"`
+func (field *Correctable) String() string {
+ return field.Name
}
func (n Name) getName() string {