2021-03-28 08:52:34 +00:00
|
|
|
package goscrobble
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
2021-04-11 05:26:48 +00:00
|
|
|
"fmt"
|
2021-03-28 08:52:34 +00:00
|
|
|
"log"
|
2021-04-03 01:16:13 +00:00
|
|
|
"strings"
|
2021-03-28 08:52:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Track struct {
|
2021-08-12 08:52:47 +00:00
|
|
|
UUID string `json:"uuid"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Length int `json:"length"`
|
|
|
|
Desc string `json:"desc"`
|
|
|
|
Img string `json:"img"`
|
|
|
|
MusicBrainzID string `json:"mbid"`
|
|
|
|
SpotifyID string `json:"spotify_id"`
|
|
|
|
Artists []Artist `json:"artists"` // Optional Artist
|
|
|
|
Albums []Album `json:"albums"` // Optional Albums
|
2021-03-28 08:52:34 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 07:00:13 +00:00
|
|
|
type TopTrack struct {
|
|
|
|
UUID string `json:"uuid"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Img string `json:"img"`
|
|
|
|
Plays int `json:"plays"`
|
|
|
|
}
|
2022-01-05 21:20:30 +00:00
|
|
|
|
2021-04-08 07:00:13 +00:00
|
|
|
type TopTracks struct {
|
|
|
|
Tracks map[int]TopTrack `json:"tracks"`
|
|
|
|
}
|
|
|
|
|
2021-03-28 08:52:34 +00:00
|
|
|
// insertTrack - This will return if it exists or create it based on MBID > Name
|
2021-04-02 09:24:00 +00:00
|
|
|
func insertTrack(name string, legnth int, mbid string, spotifyId string, album string, artists []string, tx *sql.Tx) (Track, error) {
|
2021-03-28 08:52:34 +00:00
|
|
|
track := Track{}
|
|
|
|
|
2021-04-02 09:24:00 +00:00
|
|
|
// Try locate our track
|
2021-03-28 08:52:34 +00:00
|
|
|
if mbid != "" {
|
2021-04-04 09:54:53 +00:00
|
|
|
track = getTrackByCol("mbid", mbid, tx)
|
2021-04-02 09:24:00 +00:00
|
|
|
} else if spotifyId != "" {
|
2021-04-04 09:54:53 +00:00
|
|
|
track = getTrackByCol("spotify_id", spotifyId, tx)
|
2021-04-02 09:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If it didn't match above, lookup by name
|
2021-04-04 09:54:53 +00:00
|
|
|
if track.UUID == "" {
|
|
|
|
track = getTrackWithArtists(name, artists, album, tx)
|
2021-04-02 09:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we can't find it. Lets add it!
|
2021-04-04 09:54:53 +00:00
|
|
|
if track.UUID == "" {
|
|
|
|
err := insertNewTrack(&track, name, legnth, mbid, spotifyId, tx)
|
|
|
|
|
2021-04-02 09:24:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return track, errors.New("Failed to insert track")
|
|
|
|
}
|
2021-03-28 08:52:34 +00:00
|
|
|
|
2021-04-04 09:54:53 +00:00
|
|
|
if track.UUID == "" {
|
|
|
|
return track, errors.New("Unable to fetch track!")
|
2021-04-02 09:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = track.linkTrack(album, artists, tx)
|
|
|
|
if err != nil {
|
|
|
|
return track, errors.New("Unable to link tracks!")
|
2021-03-28 08:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-04 09:54:53 +00:00
|
|
|
// Updates these values if we match earlier!
|
2021-04-03 08:29:31 +00:00
|
|
|
if track.MusicBrainzID != mbid {
|
|
|
|
track.MusicBrainzID = mbid
|
|
|
|
track.updateTrack("mbid", mbid, tx)
|
|
|
|
}
|
|
|
|
|
|
|
|
if track.SpotifyID != spotifyId {
|
|
|
|
track.SpotifyID = spotifyId
|
|
|
|
track.updateTrack("spotify_id", spotifyId, tx)
|
|
|
|
}
|
|
|
|
|
2021-03-28 08:52:34 +00:00
|
|
|
return track, nil
|
|
|
|
}
|
|
|
|
|
2021-04-04 09:54:53 +00:00
|
|
|
func getTrackByCol(col string, val string, tx *sql.Tx) Track {
|
2021-03-28 08:52:34 +00:00
|
|
|
var track Track
|
|
|
|
err := tx.QueryRow(
|
2021-04-04 09:54:53 +00:00
|
|
|
"SELECT BIN_TO_UUID(`uuid`, true), `name`, IFNULL(`desc`,''), IFNULL(`img`,''), `mbid` FROM `tracks` WHERE `"+col+"` = ? LIMIT 1",
|
|
|
|
val).Scan(&track.UUID, &track.Name, &track.Desc, &track.Img, &track.MusicBrainzID)
|
2021-03-28 08:52:34 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != sql.ErrNoRows {
|
|
|
|
log.Printf("Error fetching tracks: %+v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return track
|
|
|
|
}
|
|
|
|
|
2021-04-04 09:54:53 +00:00
|
|
|
func getTrackWithArtists(name string, artists []string, album string, tx *sql.Tx) Track {
|
2021-04-03 01:16:13 +00:00
|
|
|
var track Track
|
|
|
|
artistString := strings.Join(artists, "','")
|
|
|
|
err := tx.QueryRow(
|
2021-04-04 09:54:53 +00:00
|
|
|
"SELECT BIN_TO_UUID(`uuid`, true), `name`, IFNULL(`desc`,''), IFNULL(`img`,''), `mbid` FROM `tracks` "+
|
2021-04-03 01:16:13 +00:00
|
|
|
"LEFT JOIN `track_artist` ON `tracks`.`uuid` = `track_artist`.`track` "+
|
2021-04-03 08:29:31 +00:00
|
|
|
"LEFT JOIN `track_album` ON `tracks`.`uuid` = `track_album`.`track` "+
|
|
|
|
"WHERE `name` = ? AND BIN_TO_UUID(`track_artist`.`artist`, true) IN ('"+artistString+"') "+
|
|
|
|
"AND BIN_TO_UUID(`track_album`.`album`,true) = ? LIMIT 1",
|
2021-04-04 09:54:53 +00:00
|
|
|
name, album).Scan(&track.UUID, &track.Name, &track.Desc, &track.Img, &track.MusicBrainzID)
|
2021-04-03 01:16:13 +00:00
|
|
|
if err != nil {
|
|
|
|
if err != sql.ErrNoRows {
|
|
|
|
log.Printf("Error fetching tracks: %+v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return track
|
|
|
|
}
|
|
|
|
|
2022-02-25 23:16:45 +00:00
|
|
|
// getAllTracksForAlbum - return all album tracks!
|
|
|
|
func getAllTracksForAlbum(uuid string) (TopTracks, error) {
|
|
|
|
var topTracks TopTracks
|
|
|
|
|
|
|
|
rows, err := db.Query("SELECT BIN_TO_UUID(`tracks`.`uuid`, true), `tracks`.`name` "+
|
|
|
|
"FROM `albums` "+
|
|
|
|
"JOIN `track_album` ON `track_album`.`album` = `albums`.`uuid` "+
|
|
|
|
"JOIN `tracks` ON `tracks`.`uuid` = `track_album`.`track` "+
|
|
|
|
"WHERE albums.uuid = UUID_TO_BIN(?, true)", uuid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch top tracks: %+v", err)
|
|
|
|
return topTracks, errors.New("Failed to fetch top tracks")
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
i := 1
|
|
|
|
tempTracks := make(map[int]TopTrack)
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var track TopTrack
|
|
|
|
err := rows.Scan(&track.UUID, &track.Name)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch track: %+v", err)
|
|
|
|
return topTracks, errors.New("Failed to fetch track")
|
|
|
|
}
|
|
|
|
|
|
|
|
tempTracks[i] = track
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
|
|
|
topTracks.Tracks = tempTracks
|
|
|
|
|
|
|
|
return topTracks, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// getAllTracksForArtist - return all album tracks!
|
|
|
|
func getAllTracksForArtist(uuid string) (TopTracks, error) {
|
|
|
|
var topTracks TopTracks
|
|
|
|
|
|
|
|
rows, err := db.Query("SELECT BIN_TO_UUID(`tracks`.`uuid`, true), `tracks`.`name` "+
|
|
|
|
"FROM `artists` "+
|
|
|
|
"JOIN `track_artist` ON `track_artist`.`artist` = `artists`.`uuid` "+
|
|
|
|
"JOIN `tracks` ON `tracks`.`uuid` = `track_artist`.`track` "+
|
|
|
|
"WHERE artists.uuid = UUID_TO_BIN(?,true)", uuid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch top tracks: %+v", err)
|
|
|
|
return topTracks, errors.New("Failed to fetch top tracks")
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
i := 1
|
|
|
|
tempTracks := make(map[int]TopTrack)
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var track TopTrack
|
|
|
|
err := rows.Scan(&track.UUID, &track.Name)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch track: %+v", err)
|
|
|
|
return topTracks, errors.New("Failed to fetch track")
|
|
|
|
}
|
|
|
|
|
|
|
|
tempTracks[i] = track
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
|
|
|
topTracks.Tracks = tempTracks
|
|
|
|
|
|
|
|
return topTracks, nil
|
|
|
|
}
|
|
|
|
|
2021-04-04 09:54:53 +00:00
|
|
|
func insertNewTrack(track *Track, name string, length int, mbid string, spotifyId string, tx *sql.Tx) error {
|
|
|
|
track.UUID = newUUID()
|
|
|
|
track.Name = name
|
|
|
|
track.Length = length
|
|
|
|
track.MusicBrainzID = mbid
|
|
|
|
track.SpotifyID = spotifyId
|
|
|
|
|
2021-04-02 09:24:00 +00:00
|
|
|
_, err := tx.Exec("INSERT INTO `tracks` (`uuid`, `name`, `length`, `mbid`, `spotify_id`) "+
|
2021-04-04 09:54:53 +00:00
|
|
|
"VALUES (UUID_TO_BIN(?, true),?,?,?,?)", track.UUID, track.Name, track.Length, track.MusicBrainzID, track.SpotifyID)
|
2021-03-28 08:52:34 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (track *Track) linkTrack(album string, artists []string, tx *sql.Tx) error {
|
|
|
|
err := track.linkTrackToAlbum(album, tx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = track.linkTrackToArtists(artists, tx)
|
2021-04-04 09:54:53 +00:00
|
|
|
|
2021-03-28 08:52:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-04 09:54:53 +00:00
|
|
|
|
2021-03-28 08:52:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-04 09:54:53 +00:00
|
|
|
func (track *Track) linkTrackToAlbum(albumUuid string, tx *sql.Tx) error {
|
2021-03-28 08:52:34 +00:00
|
|
|
_, err := tx.Exec("INSERT INTO `track_album` (`track`, `album`) "+
|
2021-04-04 09:54:53 +00:00
|
|
|
"VALUES (UUID_TO_BIN(?, true), UUID_TO_BIN(?, true))", track.UUID, albumUuid)
|
2021-03-28 08:52:34 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-04 09:54:53 +00:00
|
|
|
func (track *Track) linkTrackToArtists(artists []string, tx *sql.Tx) error {
|
2021-03-28 08:52:34 +00:00
|
|
|
var err error
|
|
|
|
for _, artist := range artists {
|
|
|
|
_, err = tx.Exec("INSERT INTO `track_artist` (`track`, `artist`) "+
|
2021-04-04 09:54:53 +00:00
|
|
|
"VALUES (UUID_TO_BIN(?, true),UUID_TO_BIN(?, true))", track.UUID, artist)
|
2021-03-28 08:52:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-04-02 09:24:00 +00:00
|
|
|
|
2021-04-03 08:29:31 +00:00
|
|
|
func (track *Track) updateTrack(col string, val string, tx *sql.Tx) error {
|
2021-04-04 09:54:53 +00:00
|
|
|
_, err := tx.Exec("UPDATE `tracks` SET `"+col+"` = ? WHERE `uuid` = UUID_TO_BIN(?,true)", val, track.UUID)
|
2021-04-02 09:24:00 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
2021-04-04 09:54:53 +00:00
|
|
|
|
|
|
|
func getTrackByUUID(uuid string) (Track, error) {
|
|
|
|
var track Track
|
2021-04-11 08:10:52 +00:00
|
|
|
err := db.QueryRow("SELECT BIN_TO_UUID(`tracks`.`uuid`, true), `tracks`.`name`, IFNULL(`albums`.`desc`,''), IFNULL(BIN_TO_UUID(`albums`.`uuid`, true),''), `tracks`.`length`, `tracks`.`mbid`, `tracks`.`spotify_id` "+
|
2021-04-11 05:26:48 +00:00
|
|
|
"FROM `tracks` "+
|
|
|
|
"LEFT JOIN track_album ON track_album.track = tracks.uuid "+
|
|
|
|
"LEFT JOIN albums ON track_album.album = albums.uuid "+
|
|
|
|
"WHERE `tracks`.`uuid` = UUID_TO_BIN(?, true)",
|
2021-04-04 09:54:53 +00:00
|
|
|
uuid).Scan(&track.UUID, &track.Name, &track.Desc, &track.Img, &track.Length, &track.MusicBrainzID, &track.SpotifyID)
|
|
|
|
|
|
|
|
if err != nil {
|
2021-04-11 05:26:48 +00:00
|
|
|
fmt.Println(err)
|
2021-04-04 09:54:53 +00:00
|
|
|
return track, errors.New("Invalid UUID")
|
|
|
|
}
|
|
|
|
|
|
|
|
return track, nil
|
|
|
|
}
|
2021-04-08 07:00:13 +00:00
|
|
|
|
2022-01-05 22:30:15 +00:00
|
|
|
func getTopTracks(userUuid string, dayRange string) (TopTracks, error) {
|
2021-04-08 07:00:13 +00:00
|
|
|
var topTracks TopTracks
|
|
|
|
|
2022-01-05 22:30:15 +00:00
|
|
|
dateClause := ""
|
|
|
|
if dayRange != "" {
|
|
|
|
dateClause = " AND DATE(created_at) > SUBDATE(CURRENT_DATE, " + dayRange + ") "
|
|
|
|
}
|
|
|
|
|
2022-01-08 22:24:36 +00:00
|
|
|
whereClause := ""
|
|
|
|
if userUuid != "0" {
|
|
|
|
whereClause = "WHERE `scrobbles`.`user` = UUID_TO_BIN('" + userUuid + "', true) "
|
|
|
|
}
|
|
|
|
|
|
|
|
rows, err := db.Query("SELECT BIN_TO_UUID(`tracks`.`uuid`, true), `tracks`.`name`, IFNULL(BIN_TO_UUID(`albums`.`uuid`, true),''), count(*) " +
|
|
|
|
"FROM `scrobbles` " +
|
|
|
|
"JOIN `tracks` ON `tracks`.`uuid` = `scrobbles`.`track` " +
|
|
|
|
"JOIN track_album ON track_album.track = tracks.uuid " +
|
|
|
|
"JOIN albums ON track_album.album = albums.uuid " +
|
|
|
|
whereClause +
|
|
|
|
dateClause +
|
|
|
|
"GROUP BY `scrobbles`.`track` " +
|
|
|
|
"ORDER BY count(*) DESC " +
|
|
|
|
"LIMIT 14")
|
2022-01-05 22:30:15 +00:00
|
|
|
|
2021-04-08 07:00:13 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch top tracks: %+v", err)
|
|
|
|
return topTracks, errors.New("Failed to fetch top tracks")
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
i := 1
|
|
|
|
tempTracks := make(map[int]TopTrack)
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var track TopTrack
|
|
|
|
err := rows.Scan(&track.UUID, &track.Name, &track.Img, &track.Plays)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch track: %+v", err)
|
|
|
|
return topTracks, errors.New("Failed to fetch track")
|
|
|
|
}
|
|
|
|
|
|
|
|
tempTracks[i] = track
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
|
|
|
topTracks.Tracks = tempTracks
|
|
|
|
|
|
|
|
return topTracks, nil
|
|
|
|
}
|
2021-08-12 08:52:47 +00:00
|
|
|
|
|
|
|
func (track *Track) loadExtraTrackInfo() error {
|
|
|
|
err := track.getArtistsForTrack()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = track.getAlbumsForTrack()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (track *Track) getArtistsForTrack() error {
|
|
|
|
artists := []Artist{}
|
|
|
|
|
|
|
|
rows, err := db.Query("SELECT BIN_TO_UUID(`track_artist`.`artist`, true) "+
|
|
|
|
"FROM `track_artist` "+
|
|
|
|
"WHERE `track_artist`.`track` = UUID_TO_BIN(?, true)",
|
|
|
|
track.UUID)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch artists for track: %+v", err)
|
|
|
|
return errors.New("Failed to fetch top tracks")
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var artistUUID string
|
|
|
|
err := rows.Scan(&artistUUID)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch track_artist: %+v", err)
|
|
|
|
return errors.New("Failed to fetch track")
|
|
|
|
}
|
|
|
|
|
|
|
|
artist, err := getArtistByUUID(artistUUID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
artists = append(artists, artist)
|
|
|
|
}
|
|
|
|
|
|
|
|
track.Artists = artists
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (track *Track) getAlbumsForTrack() error {
|
|
|
|
albums := []Album{}
|
|
|
|
|
|
|
|
rows, err := db.Query("SELECT BIN_TO_UUID(`track_album`.`album`, true) "+
|
|
|
|
"FROM `track_album` "+
|
|
|
|
"WHERE `track_album`.`track` = UUID_TO_BIN(?, true)",
|
|
|
|
track.UUID)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch album for track: %+v", err)
|
|
|
|
return errors.New("Failed to fetch top tracks")
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var albumUUID string
|
|
|
|
err := rows.Scan(&albumUUID)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch track_album: %+v", err)
|
|
|
|
return errors.New("Failed to fetch track")
|
|
|
|
}
|
|
|
|
|
|
|
|
album, err := getAlbumByUUID(albumUUID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
albums = append(albums, album)
|
|
|
|
}
|
|
|
|
|
|
|
|
track.Albums = albums
|
|
|
|
return nil
|
|
|
|
}
|
2021-08-13 09:37:53 +00:00
|
|
|
|
|
|
|
// getTopUsersForTrackUUID - Returns list of top users for a track
|
2022-01-05 21:20:30 +00:00
|
|
|
func getTopUsersForTrackUUID(trackUUID string, limit int, page int) (TopUserResponse, error) {
|
|
|
|
response := TopUserResponse{}
|
2021-08-13 09:37:53 +00:00
|
|
|
var count int
|
|
|
|
|
|
|
|
total, err := getDbCount(
|
2022-01-05 21:20:30 +00:00
|
|
|
"SELECT COUNT(*) FROM `scrobbles` WHERE `track` = UUID_TO_BIN(?, true)", trackUUID)
|
2021-08-13 09:37:53 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch scrobble count: %+v", err)
|
|
|
|
return response, errors.New("Failed to fetch combined scrobbles")
|
|
|
|
}
|
|
|
|
|
|
|
|
rows, err := db.Query(
|
|
|
|
"SELECT BIN_TO_UUID(`scrobbles`.`user`, true), `users`.`username`, COUNT(*) "+
|
|
|
|
"FROM `scrobbles` "+
|
|
|
|
"JOIN `users` ON `scrobbles`.`user` = `users`.`uuid` "+
|
|
|
|
"WHERE `track` = UUID_TO_BIN(?, true) "+
|
|
|
|
"GROUP BY `scrobbles`.`user` "+
|
|
|
|
"ORDER BY COUNT(*) DESC LIMIT ?",
|
|
|
|
trackUUID, limit)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch scrobbles: %+v", err)
|
|
|
|
return response, errors.New("Failed to fetch combined scrobbles")
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
2022-01-05 21:20:30 +00:00
|
|
|
item := TopUserResponseItem{}
|
2021-08-13 09:37:53 +00:00
|
|
|
err := rows.Scan(&item.UserUUID, &item.UserName, &item.Count)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch scrobbles: %+v", err)
|
|
|
|
return response, errors.New("Failed to fetch combined scrobbles")
|
|
|
|
}
|
|
|
|
count++
|
|
|
|
response.Items = append(response.Items, item)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = rows.Err()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch scrobbles: %+v", err)
|
|
|
|
return response, errors.New("Failed to fetch scrobbles")
|
|
|
|
}
|
|
|
|
|
|
|
|
response.Meta.Count = count
|
|
|
|
response.Meta.Total = total
|
|
|
|
response.Meta.Page = page
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
}
|