mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Load playlist track genres
This commit is contained in:
parent
526b6597c8
commit
5e87280750
2 changed files with 25 additions and 5 deletions
|
@ -33,11 +33,10 @@ func (pls Playlist) IsSmartPlaylist() bool {
|
|||
}
|
||||
|
||||
func (pls Playlist) MediaFiles() MediaFiles {
|
||||
mfs := make(MediaFiles, len(pls.Tracks))
|
||||
for i, t := range pls.Tracks {
|
||||
mfs[i] = t.MediaFile
|
||||
if len(pls.Tracks) == 0 {
|
||||
return nil
|
||||
}
|
||||
return mfs
|
||||
return pls.Tracks.MediaFiles()
|
||||
}
|
||||
|
||||
func (pls *Playlist) RemoveTracks(idxToRemove []int) {
|
||||
|
@ -104,6 +103,14 @@ type PlaylistTrack struct {
|
|||
|
||||
type PlaylistTracks []PlaylistTrack
|
||||
|
||||
func (plt PlaylistTracks) MediaFiles() MediaFiles {
|
||||
mfs := make(MediaFiles, len(plt))
|
||||
for i, t := range plt {
|
||||
mfs[i] = t.MediaFile
|
||||
}
|
||||
return mfs
|
||||
}
|
||||
|
||||
type PlaylistTrackRepository interface {
|
||||
ResourceRepository
|
||||
GetAll(options ...QueryOptions) (PlaylistTracks, error)
|
||||
|
|
|
@ -56,7 +56,20 @@ func (r *playlistTrackRepository) Read(id string) (interface{}, error) {
|
|||
}
|
||||
|
||||
func (r *playlistTrackRepository) GetAll(options ...model.QueryOptions) (model.PlaylistTracks, error) {
|
||||
return r.playlistRepo.loadTracks(r.newSelect(options...), r.playlistId)
|
||||
tracks, err := r.playlistRepo.loadTracks(r.newSelect(options...), r.playlistId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mfs := tracks.MediaFiles()
|
||||
err = r.loadMediaFileGenres(&mfs)
|
||||
if err != nil {
|
||||
log.Error(r.ctx, "Error loading genres for playlist", "playlist", r.playlist.Name, "id", r.playlist.ID, err)
|
||||
return nil, err
|
||||
}
|
||||
for i, mf := range mfs {
|
||||
tracks[i].MediaFile.Genres = mf.Genres
|
||||
}
|
||||
return tracks, err
|
||||
}
|
||||
|
||||
func (r *playlistTrackRepository) ReadAll(options ...rest.QueryOptions) (interface{}, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue