Playlists working

This commit is contained in:
Deluan
2016-03-09 18:28:11 -05:00
parent 4bb4fc0cb8
commit 2214e4bd4f
8 changed files with 179 additions and 41 deletions
-23
View File
@@ -12,10 +12,6 @@ import (
"github.com/deluan/gosonic/utils"
)
var (
DataNotFound = errors.New("Data Not Found")
)
type Browser interface {
MediaFolders() (*domain.MediaFolders, error)
Indexes(ifModifiedSince time.Time) (*domain.ArtistIndexes, time.Time, error)
@@ -57,25 +53,6 @@ func (b browser) Indexes(ifModifiedSince time.Time) (*domain.ArtistIndexes, time
return &domain.ArtistIndexes{}, lastModified, nil
}
type Child struct {
Id string
Title string
IsDir bool
Parent string
Album string
Year int
Artist string
Genre string
CoverArt string
Starred time.Time
Track int
Duration int
Size string
Suffix string
BitRate int
ContentType string
}
type DirectoryInfo struct {
Id string
Name string
+29
View File
@@ -0,0 +1,29 @@
package engine
import (
"errors"
"time"
)
type Child struct {
Id string
Title string
IsDir bool
Parent string
Album string
Year int
Artist string
Genre string
CoverArt string
Starred time.Time
Track int
Duration int
Size string
Suffix string
BitRate int
ContentType string
}
var (
DataNotFound = errors.New("Data Not Found")
)
+57 -5
View File
@@ -6,16 +6,68 @@ import (
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
}
func NewPlaylists(pr domain.PlaylistRepository) Playlists {
return playlists{pr}
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 []Child
}
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, DataNotFound
}
pinfo := &PlaylistInfo{Id: pl.Id, Name: pl.Name}
pinfo.Entries = make([]Child, 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].Id = mf.Id
pinfo.Entries[i].Title = mf.Title
pinfo.Entries[i].IsDir = false
pinfo.Entries[i].Parent = mf.AlbumId
pinfo.Entries[i].Album = mf.Album
pinfo.Entries[i].Year = mf.Year
pinfo.Entries[i].Artist = mf.Artist
pinfo.Entries[i].Genre = mf.Genre
//pinfo.Entries[i].Track = mf.TrackNumber
pinfo.Entries[i].Duration = mf.Duration
pinfo.Entries[i].Size = mf.Size
pinfo.Entries[i].Suffix = mf.Suffix
pinfo.Entries[i].BitRate = mf.BitRate
if mf.Starred {
pinfo.Entries[i].Starred = mf.UpdatedAt
}
if mf.HasCoverArt {
pinfo.Entries[i].CoverArt = mf.Id
}
pinfo.Entries[i].ContentType = mf.ContentType()
}
return pinfo, nil
}