mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-06 04: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)
|
importResult, err := p.Backend.ImportListens(export, result, progress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return importResult, err
|
||||||
}
|
}
|
||||||
return importResult, nil
|
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)
|
importResult, err := p.Backend.ImportLoves(export, result, progress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return importResult, err
|
||||||
}
|
}
|
||||||
return importResult, nil
|
return importResult, nil
|
||||||
}
|
}
|
||||||
|
@ -89,30 +89,30 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
|
||||||
defer close(out)
|
defer close(out)
|
||||||
defer close(progress)
|
defer close(progress)
|
||||||
result := models.ImportResult{}
|
result := models.ImportResult{}
|
||||||
|
p := models.Progress{}
|
||||||
|
|
||||||
err := processor.ImportBackend().StartImport()
|
if err := processor.ImportBackend().StartImport(); err != nil {
|
||||||
if err != nil {
|
|
||||||
out <- handleError(result, err, progress)
|
out <- handleError(result, err, progress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for exportResult := range results {
|
for exportResult := range results {
|
||||||
importResult, err := processor.Import(exportResult, result, out, progress)
|
importResult, err := processor.Import(exportResult, result, out, progress)
|
||||||
if err != nil {
|
|
||||||
out <- handleError(result, err, progress)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
result.Update(importResult)
|
result.Update(importResult)
|
||||||
progress <- models.Progress{}.FromImportResult(result)
|
if err != nil {
|
||||||
|
processor.ImportBackend().FinishImport()
|
||||||
|
out <- handleError(result, err, progress)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
progress <- p.FromImportResult(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = processor.ImportBackend().FinishImport()
|
if err := processor.ImportBackend().FinishImport(); err != nil {
|
||||||
if err != nil {
|
|
||||||
out <- handleError(result, err, progress)
|
out <- handleError(result, err, progress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
progress <- models.Progress{}.FromImportResult(result).Complete()
|
progress <- p.FromImportResult(result).Complete()
|
||||||
out <- result
|
out <- result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,14 +77,11 @@ func (b *JSPFBackend) InitConfig(config *config.ServiceConfig) error {
|
||||||
Title: config.GetString("title"),
|
Title: config.GetString("title"),
|
||||||
Creator: config.GetString("username"),
|
Creator: config.GetString("username"),
|
||||||
Identifier: config.GetString("identifier"),
|
Identifier: config.GetString("identifier"),
|
||||||
|
Date: time.Now(),
|
||||||
Tracks: make([]jspf.Track, 0),
|
Tracks: make([]jspf.Track, 0),
|
||||||
Extension: jspf.ExtensionMap{
|
|
||||||
jspf.MusicBrainzPlaylistExtensionID: jspf.MusicBrainzPlaylistExtension{
|
|
||||||
LastModifiedAt: time.Now(),
|
|
||||||
Public: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.addMusicBrainzPlaylistExtension()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,6 +324,7 @@ func (b *JSPFBackend) readJSPF() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.playlist = playlist.Playlist
|
b.playlist = playlist.Playlist
|
||||||
|
b.addMusicBrainzPlaylistExtension()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,3 +344,13 @@ func (b *JSPFBackend) writeJSPF() error {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return playlist.Write(file)
|
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) {
|
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 {
|
for _, listen := range export.Items {
|
||||||
scrobble := NewScrobble{
|
scrobble := NewScrobble{
|
||||||
Title: listen.TrackName,
|
Title: listen.TrackName,
|
||||||
|
@ -125,7 +126,7 @@ func (b *MalojaApiBackend) ImportListens(export models.ListensResult, importResu
|
||||||
|
|
||||||
importResult.UpdateTimestamp(listen.ListenedAt)
|
importResult.UpdateTimestamp(listen.ListenedAt)
|
||||||
importResult.ImportCount += 1
|
importResult.ImportCount += 1
|
||||||
progress <- models.Progress{}.FromImportResult(importResult)
|
progress <- p.FromImportResult(importResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
return importResult, nil
|
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)
|
resultChan := make(chan models.ImportResult)
|
||||||
go imp.Process(exportChan, resultChan, importProgress)
|
go imp.Process(exportChan, resultChan, importProgress)
|
||||||
result := <-resultChan
|
result := <-resultChan
|
||||||
if timestamp.After(result.LastTimestamp) {
|
|
||||||
result.LastTimestamp = timestamp
|
|
||||||
}
|
|
||||||
progress.Wait()
|
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
|
// Update timestamp
|
||||||
err = c.updateTimestamp(result, 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
|
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
|
// Print errors
|
||||||
if len(result.ImportLog) > 0 {
|
if len(result.ImportLog) > 0 {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue