Skip to content

Commit

Permalink
ignore songs with last played times far in the future; fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
nishanths committed May 11, 2019
1 parent 4fc7d5e commit 27833a2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions appengine/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,11 @@ func scrobbleHandler(w http.ResponseWriter, r *http.Request) {
return
}

now := time.Now()

// Convert to Songs.
songs := make([]Song, len(mis))
for i, m := range mis {
var songs []Song
for _, m := range mis {
sal := m.SortAlbumTitle
if sal == "" {
sal = m.AlbumTitle
Expand All @@ -382,7 +384,15 @@ func scrobbleHandler(w http.ResponseWriter, r *http.Request) {
if st == "" {
st = m.Title
}
songs[i] = Song{

// There is a bug (somewhere) that leads to some songs having last
// played times far into the future, for instance, in the year 2040.
// So ignore such songs.
if time.Unix(int64(m.LastPlayed), 0).Sub(now) > 365*24*time.Hour {
continue
}

songs = append(songs, Song{
AlbumTitle: m.AlbumTitle,
ArtistName: m.ArtistName,
Title: m.Title,
Expand All @@ -396,10 +406,9 @@ func scrobbleHandler(w http.ResponseWriter, r *http.Request) {
PlayCount: int(m.PlayCount),
ArtworkHash: m.ArtworkHash,
Loved: m.Loved,
}
})
}

now := time.Now()
newParentIdent := songparentident(now, uuid.New())
newParentKey := songParentKey(ns, newParentIdent)

Expand Down

0 comments on commit 27833a2

Please sign in to comment.