mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 13:47:05 +02:00
Implemented progressbar for export/import
This commit is contained in:
parent
ab04eb1123
commit
6e330daf06
24 changed files with 590 additions and 239 deletions
|
@ -36,42 +36,34 @@ type JspfBackend struct {
|
|||
title string
|
||||
creator string
|
||||
identifier string
|
||||
tracks []Track
|
||||
}
|
||||
|
||||
func (b JspfBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
func (b *JspfBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
b.filePath = config.GetString("file-path")
|
||||
b.title = config.GetString("title")
|
||||
b.creator = config.GetString("username")
|
||||
b.identifier = config.GetString("identifier")
|
||||
b.tracks = make([]Track, 0)
|
||||
return b
|
||||
}
|
||||
|
||||
func (b JspfBackend) ImportLoves(results chan models.LovesResult, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
importResult := models.ImportResult{
|
||||
LastTimestamp: oldestTimestamp,
|
||||
func (b *JspfBackend) Init() error { return nil }
|
||||
func (b *JspfBackend) Finish() error {
|
||||
err := b.writeJspf(b.tracks)
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *JspfBackend) ImportLoves(export models.LovesResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
|
||||
for _, love := range export.Loves {
|
||||
track := loveToTrack(love)
|
||||
b.tracks = append(b.tracks, track)
|
||||
importResult.ImportCount += 1
|
||||
importResult.UpdateTimestamp(love.Created)
|
||||
}
|
||||
|
||||
tracks := make([]Track, 0, importResult.TotalCount)
|
||||
for result := range results {
|
||||
if result.Error != nil {
|
||||
return importResult, result.Error
|
||||
}
|
||||
|
||||
importResult.TotalCount += len(result.Loves)
|
||||
for _, love := range result.Loves {
|
||||
track := loveToTrack(love)
|
||||
tracks = append(tracks, track)
|
||||
oldestTimestamp = love.Created
|
||||
importResult.ImportCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
err := b.writeJspf(tracks)
|
||||
if err != nil {
|
||||
importResult.UpdateTimestamp(oldestTimestamp)
|
||||
importResult.ImportCount = len(tracks)
|
||||
}
|
||||
return importResult, err
|
||||
progress <- models.Progress{}.FromImportResult(importResult)
|
||||
return importResult, nil
|
||||
}
|
||||
|
||||
func loveToTrack(love models.Love) Track {
|
||||
|
|
|
@ -36,6 +36,6 @@ func TestFromConfig(t *testing.T) {
|
|||
config.Set("title", "My Playlist")
|
||||
config.Set("username", "outsidecontext")
|
||||
config.Set("identifier", "http://example.com/playlist1")
|
||||
backend := scrobblerlog.ScrobblerLogBackend{}.FromConfig(config)
|
||||
assert.IsType(t, scrobblerlog.ScrobblerLogBackend{}, backend)
|
||||
backend := (&scrobblerlog.ScrobblerLogBackend{}).FromConfig(config)
|
||||
assert.IsType(t, &scrobblerlog.ScrobblerLogBackend{}, backend)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue