mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-29 21:27:05 +02:00
ListenBrainz: Fixed loves export
This commit is contained in:
parent
90bf51a00b
commit
7c0774fb8d
1 changed files with 23 additions and 8 deletions
|
@ -188,10 +188,27 @@ func (b *ListenBrainzApiBackend) ImportListens(export models.ListensResult, impo
|
|||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) {
|
||||
b.exportLoves(oldestTimestamp, results, progress, false)
|
||||
defer close(results)
|
||||
exportChan := make(chan models.LovesResult)
|
||||
p := models.Progress{}
|
||||
|
||||
go b.exportLoves(time.Unix(0, 0), exportChan)
|
||||
for existingLoves := range exportChan {
|
||||
if existingLoves.Error != nil {
|
||||
progress <- p.Complete()
|
||||
results <- models.LovesResult{Error: existingLoves.Error}
|
||||
}
|
||||
|
||||
p.Total = int64(existingLoves.Total)
|
||||
p.Elapsed += int64(existingLoves.Items.Len())
|
||||
progress <- p
|
||||
results <- existingLoves
|
||||
}
|
||||
|
||||
progress <- p.Complete()
|
||||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) exportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress, completeProgress bool) {
|
||||
func (b *ListenBrainzApiBackend) exportLoves(oldestTimestamp time.Time, results chan models.LovesResult) {
|
||||
offset := 0
|
||||
defer close(results)
|
||||
loves := make(models.LovesList, 0, 2*MaxItemsPerGet)
|
||||
|
@ -201,7 +218,6 @@ out:
|
|||
for {
|
||||
result, err := b.client.GetFeedback(b.username, 1, offset)
|
||||
if err != nil {
|
||||
progress <- p.Complete()
|
||||
results <- models.LovesResult{Error: err}
|
||||
return
|
||||
}
|
||||
|
@ -216,7 +232,6 @@ out:
|
|||
if love.Created.Unix() > oldestTimestamp.Unix() {
|
||||
loves = append(loves, love)
|
||||
p.Elapsed += 1
|
||||
progress <- p
|
||||
} else {
|
||||
break out
|
||||
}
|
||||
|
@ -229,16 +244,16 @@ out:
|
|||
}
|
||||
|
||||
sort.Sort(loves)
|
||||
if completeProgress {
|
||||
progress <- p.Complete()
|
||||
results <- models.LovesResult{
|
||||
Total: len(loves),
|
||||
Items: loves,
|
||||
}
|
||||
results <- models.LovesResult{Items: loves}
|
||||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
|
||||
if len(b.existingMBIDs) == 0 {
|
||||
existingLovesChan := make(chan models.LovesResult)
|
||||
go b.exportLoves(time.Unix(0, 0), existingLovesChan, progress, false)
|
||||
go b.exportLoves(time.Unix(0, 0), existingLovesChan)
|
||||
|
||||
// TODO: Store MBIDs directly
|
||||
b.existingMBIDs = make(map[mbtypes.MBID]bool, MaxItemsPerGet)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue