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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.TotalCount += len(exportResult.Listens)
|
if exportResult.Total > 0 {
|
||||||
|
result.TotalCount = exportResult.Total
|
||||||
|
} else {
|
||||||
|
result.TotalCount += len(exportResult.Listens)
|
||||||
|
}
|
||||||
importResult, err := importer.ImportListens(exportResult, result, progress)
|
importResult, err := importer.ImportListens(exportResult, result, progress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(importResult, err, out, progress)
|
handleError(importResult, err, out, progress)
|
||||||
|
@ -74,7 +78,11 @@ func ProcessLovesImports(importer models.LovesImport, results chan models.LovesR
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.TotalCount += len(exportResult.Loves)
|
if exportResult.Total > 0 {
|
||||||
|
result.TotalCount = exportResult.Total
|
||||||
|
} else {
|
||||||
|
result.TotalCount += len(exportResult.Loves)
|
||||||
|
}
|
||||||
importResult, err := importer.ImportLoves(exportResult, result, progress)
|
importResult, err := importer.ImportLoves(exportResult, result, progress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(importResult, err, out, progress)
|
handleError(importResult, err, out, progress)
|
||||||
|
|
|
@ -139,6 +139,7 @@ func (b *SpotifyApiBackend) ExportLoves(oldestTimestamp time.Time, results chan
|
||||||
defer close(progress)
|
defer close(progress)
|
||||||
|
|
||||||
p := models.Progress{Total: int64(perPage)}
|
p := models.Progress{Total: int64(perPage)}
|
||||||
|
var totalCount int
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
|
@ -153,6 +154,7 @@ out:
|
||||||
// and continue.
|
// and continue.
|
||||||
if offset >= result.Total {
|
if offset >= result.Total {
|
||||||
p.Total = int64(result.Total)
|
p.Total = int64(result.Total)
|
||||||
|
totalCount = result.Total
|
||||||
offset = result.Total - perPage
|
offset = result.Total - perPage
|
||||||
if offset < 0 {
|
if offset < 0 {
|
||||||
offset = 0
|
offset = 0
|
||||||
|
@ -169,15 +171,16 @@ out:
|
||||||
for _, track := range result.Items {
|
for _, track := range result.Items {
|
||||||
love := track.ToLove()
|
love := track.ToLove()
|
||||||
if love.Created.Unix() > oldestTimestamp.Unix() {
|
if love.Created.Unix() > oldestTimestamp.Unix() {
|
||||||
p.Elapsed += 1
|
|
||||||
loves = append(loves, love)
|
loves = append(loves, love)
|
||||||
} else {
|
} else {
|
||||||
|
totalCount -= 1
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(loves)
|
sort.Sort(loves)
|
||||||
results <- models.LovesResult{Loves: loves}
|
results <- models.LovesResult{Loves: loves, Total: totalCount}
|
||||||
|
p.Elapsed += int64(count)
|
||||||
progress <- p
|
progress <- p
|
||||||
|
|
||||||
if offset <= 0 {
|
if offset <= 0 {
|
||||||
|
|
|
@ -106,12 +106,14 @@ func (l LovesList) Swap(i, j int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListensResult struct {
|
type ListensResult struct {
|
||||||
|
Total int
|
||||||
Listens ListensList
|
Listens ListensList
|
||||||
OldestTimestamp time.Time
|
OldestTimestamp time.Time
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
type LovesResult struct {
|
type LovesResult struct {
|
||||||
|
Total int
|
||||||
Loves LovesList
|
Loves LovesList
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue