mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37: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) {
|
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}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ListenBrainzApiBackend) exportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress, completeProgress bool) {
|
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) {
|
||||||
offset := 0
|
offset := 0
|
||||||
defer close(results)
|
defer close(results)
|
||||||
loves := make(models.LovesList, 0, 2*MaxItemsPerGet)
|
loves := make(models.LovesList, 0, 2*MaxItemsPerGet)
|
||||||
|
@ -201,7 +218,6 @@ out:
|
||||||
for {
|
for {
|
||||||
result, err := b.client.GetFeedback(b.username, 1, offset)
|
result, err := b.client.GetFeedback(b.username, 1, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
progress <- p.Complete()
|
|
||||||
results <- models.LovesResult{Error: err}
|
results <- models.LovesResult{Error: err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -216,7 +232,6 @@ out:
|
||||||
if love.Created.Unix() > oldestTimestamp.Unix() {
|
if love.Created.Unix() > oldestTimestamp.Unix() {
|
||||||
loves = append(loves, love)
|
loves = append(loves, love)
|
||||||
p.Elapsed += 1
|
p.Elapsed += 1
|
||||||
progress <- p
|
|
||||||
} else {
|
} else {
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
|
@ -229,16 +244,16 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(loves)
|
sort.Sort(loves)
|
||||||
if completeProgress {
|
results <- models.LovesResult{
|
||||||
progress <- p.Complete()
|
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) {
|
func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
|
||||||
if len(b.existingMBIDs) == 0 {
|
if len(b.existingMBIDs) == 0 {
|
||||||
existingLovesChan := make(chan models.LovesResult)
|
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
|
// TODO: Store MBIDs directly
|
||||||
b.existingMBIDs = make(map[mbtypes.MBID]bool, MaxItemsPerGet)
|
b.existingMBIDs = make(map[mbtypes.MBID]bool, MaxItemsPerGet)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue