mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-18 19:19:28 +02:00
ListenBrainz: Skip importing existing loves
This commit is contained in:
parent
6dd67aedcb
commit
9b5a087974
1 changed files with 27 additions and 6 deletions
|
@ -116,6 +116,17 @@ func (b ListenBrainzApiBackend) ImportLoves(loves []models.Love, oldestTimestamp
|
||||||
LastTimestamp: oldestTimestamp,
|
LastTimestamp: oldestTimestamp,
|
||||||
ImportErrors: make([]string, 0),
|
ImportErrors: make([]string, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingLoves, err := b.ExportLoves(time.Unix(0, 0))
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
existingMbids := make(map[string]bool, len(existingLoves))
|
||||||
|
for _, love := range existingLoves {
|
||||||
|
existingMbids[string(love.RecordingMbid)] = true
|
||||||
|
}
|
||||||
|
|
||||||
for _, love := range loves {
|
for _, love := range loves {
|
||||||
if love.Created.Unix() <= oldestTimestamp.Unix() {
|
if love.Created.Unix() <= oldestTimestamp.Unix() {
|
||||||
continue
|
continue
|
||||||
|
@ -123,19 +134,29 @@ func (b ListenBrainzApiBackend) ImportLoves(loves []models.Love, oldestTimestamp
|
||||||
|
|
||||||
// TODO: Support love import without recording MBID
|
// TODO: Support love import without recording MBID
|
||||||
if love.RecordingMbid != "" {
|
if love.RecordingMbid != "" {
|
||||||
resp, err := b.client.SendFeedback(Feedback{
|
ok := false
|
||||||
RecordingMbid: string(love.RecordingMbid),
|
errMsg := ""
|
||||||
Score: 1,
|
if existingMbids[string(love.RecordingMbid)] {
|
||||||
})
|
ok = true
|
||||||
|
} else {
|
||||||
|
resp, err := b.client.SendFeedback(Feedback{
|
||||||
|
RecordingMbid: string(love.RecordingMbid),
|
||||||
|
Score: 1,
|
||||||
|
})
|
||||||
|
ok = err == nil && resp.Status == "ok"
|
||||||
|
if err != nil {
|
||||||
|
errMsg = err.Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err == nil && resp.Status == "ok" {
|
if ok {
|
||||||
result.ImportCount += 1
|
result.ImportCount += 1
|
||||||
if love.Created.Unix() > result.LastTimestamp.Unix() {
|
if love.Created.Unix() > result.LastTimestamp.Unix() {
|
||||||
result.LastTimestamp = love.Created
|
result.LastTimestamp = love.Created
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
msg := fmt.Sprintf("Failed import of \"%s\" by %s: %v",
|
msg := fmt.Sprintf("Failed import of \"%s\" by %s: %v",
|
||||||
love.TrackName, love.ArtistName(), err.Error())
|
love.TrackName, love.ArtistName(), errMsg)
|
||||||
result.ImportErrors = append(result.ImportErrors, msg)
|
result.ImportErrors = append(result.ImportErrors, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue