quintodrome/engine/playlists.go

83 lines
1.7 KiB
Go
Raw Normal View History

package engine
import (
2020-01-08 16:45:07 -09:00
"context"
2016-03-24 08:06:39 -08:00
2020-01-14 18:22:34 -09:00
"github.com/cloudsonic/sonic-server/model"
)
type Playlists interface {
2020-01-14 18:22:34 -09:00
GetAll() (model.Playlists, error)
2016-03-09 14:28:11 -09:00
Get(id string) (*PlaylistInfo, error)
2020-01-08 16:45:07 -09:00
Create(ctx context.Context, name string, ids []string) error
Delete(ctx context.Context, playlistId string) error
2016-03-24 09:28:20 -08:00
Update(playlistId string, name *string, idsToAdd []string, idxToRemove []int) error
}
func NewPlaylists(ds model.DataStore) Playlists {
return &playlists{ds}
}
2016-03-09 14:28:11 -09:00
type playlists struct {
ds model.DataStore
}
2020-01-14 18:22:34 -09:00
func (p *playlists) GetAll() (model.Playlists, error) {
return p.ds.Playlist().GetAll(model.QueryOptions{})
}
2016-03-09 14:28:11 -09:00
type PlaylistInfo struct {
2016-03-21 08:26:55 -08:00
Id string
Name string
Entries Entries
SongCount int
Duration int
Public bool
Owner string
2016-03-24 09:28:20 -08:00
Comment string
2016-03-09 14:28:11 -09:00
}
2020-01-08 16:45:07 -09:00
func (p *playlists) Create(ctx context.Context, name string, ids []string) error {
// TODO
2016-03-24 08:06:39 -08:00
return nil
}
2020-01-08 16:45:07 -09:00
func (p *playlists) Delete(ctx context.Context, playlistId string) error {
// TODO
2016-03-24 09:28:20 -08:00
return nil
}
func (p *playlists) Update(playlistId string, name *string, idsToAdd []string, idxToRemove []int) error {
// TODO
2016-03-24 08:17:35 -08:00
return nil
}
2016-03-21 19:11:57 -08:00
func (p *playlists) Get(id string) (*PlaylistInfo, error) {
pl, err := p.ds.Playlist().Get(id)
2016-03-09 14:28:11 -09:00
if err != nil {
return nil, err
}
2016-03-21 08:26:55 -08:00
pinfo := &PlaylistInfo{
Id: pl.ID,
2016-03-21 08:26:55 -08:00
Name: pl.Name,
SongCount: len(pl.Tracks), // TODO Use model.Playlist
2016-03-21 08:26:55 -08:00
Duration: pl.Duration,
Public: pl.Public,
Owner: pl.Owner,
2016-03-24 09:28:20 -08:00
Comment: pl.Comment,
2016-03-21 08:26:55 -08:00
}
2016-03-14 07:42:33 -08:00
pinfo.Entries = make(Entries, len(pl.Tracks))
2016-03-09 14:28:11 -09:00
// TODO Optimize: Get all tracks at once
for i, mfId := range pl.Tracks {
mf, err := p.ds.MediaFile().Get(mfId)
2016-03-09 14:28:11 -09:00
if err != nil {
return nil, err
}
2016-03-11 05:10:40 -09:00
pinfo.Entries[i] = FromMediaFile(mf)
2016-03-09 14:28:11 -09:00
}
return pinfo, nil
}