mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-14 11:17:19 +03:00
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package engine
|
|
|
|
import (
|
|
"github.com/deluan/gosonic/domain"
|
|
)
|
|
|
|
type Playlists interface {
|
|
GetAll() (*domain.Playlists, error)
|
|
Get(id string) (*PlaylistInfo, error)
|
|
}
|
|
|
|
func NewPlaylists(pr domain.PlaylistRepository, mr domain.MediaFileRepository) Playlists {
|
|
return playlists{pr, mr}
|
|
}
|
|
|
|
type playlists struct {
|
|
plsRepo domain.PlaylistRepository
|
|
mfileRepo domain.MediaFileRepository
|
|
}
|
|
|
|
func (p playlists) GetAll() (*domain.Playlists, error) {
|
|
return p.plsRepo.GetAll(domain.QueryOptions{})
|
|
}
|
|
|
|
type PlaylistInfo struct {
|
|
Id string
|
|
Name string
|
|
Entries Entries
|
|
}
|
|
|
|
func (p playlists) Get(id string) (*PlaylistInfo, error) {
|
|
pl, err := p.plsRepo.Get(id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if pl == nil {
|
|
return nil, ErrDataNotFound
|
|
}
|
|
|
|
pinfo := &PlaylistInfo{Id: pl.Id, Name: pl.Name}
|
|
pinfo.Entries = make(Entries, len(pl.Tracks))
|
|
|
|
// TODO Optimize: Get all tracks at once
|
|
for i, mfId := range pl.Tracks {
|
|
mf, err := p.mfileRepo.Get(mfId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
pinfo.Entries[i] = FromMediaFile(mf)
|
|
pinfo.Entries[i].Track = 0
|
|
}
|
|
|
|
return pinfo, nil
|
|
}
|