mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 21:57:06 +02:00
Unified code for backend clients and tests
This commit is contained in:
parent
9316838d59
commit
aa01ae1342
11 changed files with 220 additions and 42 deletions
|
@ -50,19 +50,19 @@ func (b MalojaApiBackend) ExportListens(oldestTimestamp time.Time) ([]models.Lis
|
|||
|
||||
out:
|
||||
for {
|
||||
result, err := b.client.GetListens(page, perPage)
|
||||
result, err := b.client.GetScrobbles(page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
count := len(result.Listens)
|
||||
count := len(result.List)
|
||||
if count == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, listen := range result.Listens {
|
||||
if listen.ListenedAt > oldestTimestamp.Unix() {
|
||||
listens = append(listens, ListenFromMaloja(listen))
|
||||
for _, scrobble := range result.List {
|
||||
if scrobble.ListenedAt > oldestTimestamp.Unix() {
|
||||
listens = append(listens, scrobble.ToListen())
|
||||
} else {
|
||||
break out
|
||||
}
|
||||
|
@ -75,11 +75,11 @@ out:
|
|||
return listens, nil
|
||||
}
|
||||
|
||||
func ListenFromMaloja(mlListen Listen) models.Listen {
|
||||
track := mlListen.Track
|
||||
func (s Scrobble) ToListen() models.Listen {
|
||||
track := s.Track
|
||||
listen := models.Listen{
|
||||
ListenedAt: time.Unix(mlListen.ListenedAt, 0),
|
||||
PlaybackDuration: time.Duration(mlListen.Duration * int64(time.Second)),
|
||||
ListenedAt: time.Unix(s.ListenedAt, 0),
|
||||
PlaybackDuration: time.Duration(s.Duration * int64(time.Second)),
|
||||
Track: models.Track{
|
||||
TrackName: track.Title,
|
||||
ReleaseName: track.Album.Title,
|
||||
|
@ -89,7 +89,7 @@ func ListenFromMaloja(mlListen Listen) models.Listen {
|
|||
},
|
||||
}
|
||||
|
||||
client, found := strings.CutPrefix(mlListen.Origin, "client:")
|
||||
client, found := strings.CutPrefix(s.Origin, "client:")
|
||||
if found {
|
||||
listen.AdditionalInfo["media_player"] = client
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue