mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-01 14:17:06 +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
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue