mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-01 19:47:37 +03:00
fix(server): send artist mbids when scrobbling to ListenBrainz
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
f6eee65955
commit
20297c2aea
4 changed files with 26 additions and 22 deletions
|
@ -124,7 +124,7 @@ func (p *playTracker) Submit(ctx context.Context, submissions []Submission) erro
|
|||
success := 0
|
||||
|
||||
for _, s := range submissions {
|
||||
mf, err := p.ds.MediaFile(ctx).Get(s.TrackID)
|
||||
mf, err := p.ds.MediaFile(ctx).GetWithParticipants(s.TrackID)
|
||||
if err != nil {
|
||||
log.Error(ctx, "Cannot find track for scrobbling", "id", s.TrackID, "user", username, err)
|
||||
continue
|
||||
|
|
|
@ -150,27 +150,6 @@ func (r *mediaFileRepository) GetWithParticipants(id string) (*model.MediaFile,
|
|||
return m, err
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) getParticipants(m *model.MediaFile) (model.Participants, error) {
|
||||
ar := NewArtistRepository(r.ctx, r.db)
|
||||
ids := m.Participants.AllIDs()
|
||||
artists, err := ar.GetAll(model.QueryOptions{Filters: Eq{"id": ids}})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting participants: %w", err)
|
||||
}
|
||||
artistMap := slice.ToMap(artists, func(a model.Artist) (string, model.Artist) {
|
||||
return a.ID, a
|
||||
})
|
||||
p := m.Participants
|
||||
for role, artistList := range p {
|
||||
for idx, artist := range artistList {
|
||||
if a, ok := artistMap[artist.ID]; ok {
|
||||
p[role][idx].Artist = a
|
||||
}
|
||||
}
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) GetAll(options ...model.QueryOptions) (model.MediaFiles, error) {
|
||||
sq := r.selectMediaFile(options...)
|
||||
var res dbMediaFiles
|
||||
|
|
|
@ -82,6 +82,10 @@ func (r *scrobbleBufferRepository) Next(service string, userId string) (*model.S
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.ScrobbleEntry.Participants, err = r.getParticipants(&res.ScrobbleEntry.MediaFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.ScrobbleEntry, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -64,3 +64,24 @@ func (r sqlRepository) updateParticipants(itemID string, participants model.Part
|
|||
_, err = r.executeSQL(sqi)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *sqlRepository) getParticipants(m *model.MediaFile) (model.Participants, error) {
|
||||
ar := NewArtistRepository(r.ctx, r.db)
|
||||
ids := m.Participants.AllIDs()
|
||||
artists, err := ar.GetAll(model.QueryOptions{Filters: Eq{"id": ids}})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting participants: %w", err)
|
||||
}
|
||||
artistMap := slice.ToMap(artists, func(a model.Artist) (string, model.Artist) {
|
||||
return a.ID, a
|
||||
})
|
||||
p := m.Participants
|
||||
for role, artistList := range p {
|
||||
for idx, artist := range artistList {
|
||||
if a, ok := artistMap[artist.ID]; ok {
|
||||
p[role][idx].Artist = a
|
||||
}
|
||||
}
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue