mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-16 10:09:28 +02:00
Improved progress report for Spotify loves
This commit is contained in:
parent
0e3061e837
commit
4a9f26d9db
3 changed files with 17 additions and 4 deletions
|
@ -36,7 +36,11 @@ func ProcessListensImports(importer models.ListensImport, results chan models.Li
|
|||
return
|
||||
}
|
||||
|
||||
if exportResult.Total > 0 {
|
||||
result.TotalCount = exportResult.Total
|
||||
} else {
|
||||
result.TotalCount += len(exportResult.Listens)
|
||||
}
|
||||
importResult, err := importer.ImportListens(exportResult, result, progress)
|
||||
if err != nil {
|
||||
handleError(importResult, err, out, progress)
|
||||
|
@ -74,7 +78,11 @@ func ProcessLovesImports(importer models.LovesImport, results chan models.LovesR
|
|||
return
|
||||
}
|
||||
|
||||
if exportResult.Total > 0 {
|
||||
result.TotalCount = exportResult.Total
|
||||
} else {
|
||||
result.TotalCount += len(exportResult.Loves)
|
||||
}
|
||||
importResult, err := importer.ImportLoves(exportResult, result, progress)
|
||||
if err != nil {
|
||||
handleError(importResult, err, out, progress)
|
||||
|
|
|
@ -139,6 +139,7 @@ func (b *SpotifyApiBackend) ExportLoves(oldestTimestamp time.Time, results chan
|
|||
defer close(progress)
|
||||
|
||||
p := models.Progress{Total: int64(perPage)}
|
||||
var totalCount int
|
||||
|
||||
out:
|
||||
for {
|
||||
|
@ -153,6 +154,7 @@ out:
|
|||
// and continue.
|
||||
if offset >= result.Total {
|
||||
p.Total = int64(result.Total)
|
||||
totalCount = result.Total
|
||||
offset = result.Total - perPage
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
|
@ -169,15 +171,16 @@ out:
|
|||
for _, track := range result.Items {
|
||||
love := track.ToLove()
|
||||
if love.Created.Unix() > oldestTimestamp.Unix() {
|
||||
p.Elapsed += 1
|
||||
loves = append(loves, love)
|
||||
} else {
|
||||
totalCount -= 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(loves)
|
||||
results <- models.LovesResult{Loves: loves}
|
||||
results <- models.LovesResult{Loves: loves, Total: totalCount}
|
||||
p.Elapsed += int64(count)
|
||||
progress <- p
|
||||
|
||||
if offset <= 0 {
|
||||
|
|
|
@ -106,12 +106,14 @@ func (l LovesList) Swap(i, j int) {
|
|||
}
|
||||
|
||||
type ListensResult struct {
|
||||
Total int
|
||||
Listens ListensList
|
||||
OldestTimestamp time.Time
|
||||
Error error
|
||||
}
|
||||
|
||||
type LovesResult struct {
|
||||
Total int
|
||||
Loves LovesList
|
||||
Error error
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue