mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-02 19:58:33 +02:00
Compare commits
3 commits
338b2654ef
...
1a9f9bb36c
Author | SHA1 | Date | |
---|---|---|---|
|
1a9f9bb36c | ||
|
45aeeb7087 | ||
|
873a1b88af |
4 changed files with 32 additions and 25 deletions
|
@ -51,7 +51,7 @@ func (p ListensImportProcessor) Import(export models.ListensResult, result model
|
|||
}
|
||||
importResult, err := p.Backend.ImportListens(export, result, progress)
|
||||
if err != nil {
|
||||
return result, err
|
||||
return importResult, err
|
||||
}
|
||||
return importResult, nil
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (p LovesImportProcessor) Import(export models.LovesResult, result models.Im
|
|||
}
|
||||
importResult, err := p.Backend.ImportLoves(export, result, progress)
|
||||
if err != nil {
|
||||
return result, err
|
||||
return importResult, err
|
||||
}
|
||||
return importResult, nil
|
||||
}
|
||||
|
@ -89,30 +89,30 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
|
|||
defer close(out)
|
||||
defer close(progress)
|
||||
result := models.ImportResult{}
|
||||
p := models.Progress{}
|
||||
|
||||
err := processor.ImportBackend().StartImport()
|
||||
if err != nil {
|
||||
if err := processor.ImportBackend().StartImport(); err != nil {
|
||||
out <- handleError(result, err, progress)
|
||||
return
|
||||
}
|
||||
|
||||
for exportResult := range results {
|
||||
importResult, err := processor.Import(exportResult, result, out, progress)
|
||||
result.Update(importResult)
|
||||
if err != nil {
|
||||
processor.ImportBackend().FinishImport()
|
||||
out <- handleError(result, err, progress)
|
||||
return
|
||||
}
|
||||
result.Update(importResult)
|
||||
progress <- models.Progress{}.FromImportResult(result)
|
||||
progress <- p.FromImportResult(result)
|
||||
}
|
||||
|
||||
err = processor.ImportBackend().FinishImport()
|
||||
if err != nil {
|
||||
if err := processor.ImportBackend().FinishImport(); err != nil {
|
||||
out <- handleError(result, err, progress)
|
||||
return
|
||||
}
|
||||
|
||||
progress <- models.Progress{}.FromImportResult(result).Complete()
|
||||
progress <- p.FromImportResult(result).Complete()
|
||||
out <- result
|
||||
}
|
||||
|
||||
|
|
|
@ -77,14 +77,11 @@ func (b *JSPFBackend) InitConfig(config *config.ServiceConfig) error {
|
|||
Title: config.GetString("title"),
|
||||
Creator: config.GetString("username"),
|
||||
Identifier: config.GetString("identifier"),
|
||||
Date: time.Now(),
|
||||
Tracks: make([]jspf.Track, 0),
|
||||
Extension: jspf.ExtensionMap{
|
||||
jspf.MusicBrainzPlaylistExtensionID: jspf.MusicBrainzPlaylistExtension{
|
||||
LastModifiedAt: time.Now(),
|
||||
Public: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
b.addMusicBrainzPlaylistExtension()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -327,6 +324,7 @@ func (b *JSPFBackend) readJSPF() error {
|
|||
return err
|
||||
}
|
||||
b.playlist = playlist.Playlist
|
||||
b.addMusicBrainzPlaylistExtension()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,3 +344,13 @@ func (b *JSPFBackend) writeJSPF() error {
|
|||
defer file.Close()
|
||||
return playlist.Write(file)
|
||||
}
|
||||
|
||||
func (b *JSPFBackend) addMusicBrainzPlaylistExtension() {
|
||||
if b.playlist.Extension == nil {
|
||||
b.playlist.Extension = make(jspf.ExtensionMap, 1)
|
||||
}
|
||||
extension := jspf.MusicBrainzPlaylistExtension{Public: true}
|
||||
b.playlist.Extension.Get(jspf.MusicBrainzPlaylistExtensionID, &extension)
|
||||
extension.LastModifiedAt = time.Now()
|
||||
b.playlist.Extension[jspf.MusicBrainzPlaylistExtensionID] = extension
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@ out:
|
|||
}
|
||||
|
||||
func (b *MalojaApiBackend) ImportListens(export models.ListensResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
|
||||
p := models.Progress{}.FromImportResult(importResult)
|
||||
for _, listen := range export.Items {
|
||||
scrobble := NewScrobble{
|
||||
Title: listen.TrackName,
|
||||
|
@ -125,7 +126,7 @@ func (b *MalojaApiBackend) ImportListens(export models.ListensResult, importResu
|
|||
|
||||
importResult.UpdateTimestamp(listen.ListenedAt)
|
||||
importResult.ImportCount += 1
|
||||
progress <- models.Progress{}.FromImportResult(importResult)
|
||||
progress <- p.FromImportResult(importResult)
|
||||
}
|
||||
|
||||
return importResult, nil
|
||||
|
|
|
@ -121,16 +121,7 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
|
|||
resultChan := make(chan models.ImportResult)
|
||||
go imp.Process(exportChan, resultChan, importProgress)
|
||||
result := <-resultChan
|
||||
if timestamp.After(result.LastTimestamp) {
|
||||
result.LastTimestamp = timestamp
|
||||
}
|
||||
progress.Wait()
|
||||
if result.Error != nil {
|
||||
printTimestamp("Import failed, last reported timestamp was %v (%s)", result.LastTimestamp)
|
||||
return result.Error
|
||||
}
|
||||
fmt.Println(i18n.Tr("Imported %v of %v %s into %v.",
|
||||
result.ImportCount, result.TotalCount, c.entity, c.targetName))
|
||||
|
||||
// Update timestamp
|
||||
err = c.updateTimestamp(result, timestamp)
|
||||
|
@ -138,6 +129,13 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Println(i18n.Tr("Imported %v of %v %s into %v.",
|
||||
result.ImportCount, result.TotalCount, c.entity, c.targetName))
|
||||
if result.Error != nil {
|
||||
printTimestamp("Import failed, last reported timestamp was %v (%s)", result.LastTimestamp)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
// Print errors
|
||||
if len(result.ImportLog) > 0 {
|
||||
fmt.Println()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue