Adding paths to the responses

This commit is contained in:
Deluan
2016-03-23 20:53:28 -04:00
parent fc8bb34ae3
commit 21460308c9
2 changed files with 42 additions and 29 deletions
+26 -28
View File
@@ -127,36 +127,34 @@ func (c *BaseAPIController) ToChildren(entries engine.Entries) []responses.Child
} }
func (c *BaseAPIController) ToChild(entry engine.Entry) responses.Child { func (c *BaseAPIController) ToChild(entry engine.Entry) responses.Child {
n := responses.Child{} child := responses.Child{}
n.Id = entry.Id child.Id = entry.Id
n.Title = entry.Title child.Title = entry.Title
n.IsDir = entry.IsDir child.IsDir = entry.IsDir
n.Parent = entry.Parent child.Parent = entry.Parent
n.Album = entry.Album child.Album = entry.Album
n.Year = entry.Year child.Year = entry.Year
n.Artist = entry.Artist child.Artist = entry.Artist
n.Genre = entry.Genre child.Genre = entry.Genre
n.CoverArt = entry.CoverArt child.CoverArt = entry.CoverArt
n.Track = entry.Track child.Track = entry.Track
n.Duration = entry.Duration child.Duration = entry.Duration
n.Size = entry.Size child.Size = entry.Size
n.Suffix = entry.Suffix child.Suffix = entry.Suffix
n.BitRate = entry.BitRate child.BitRate = entry.BitRate
n.ContentType = entry.ContentType child.ContentType = entry.ContentType
if !entry.Starred.IsZero() { if !entry.Starred.IsZero() {
n.Starred = &entry.Starred child.Starred = &entry.Starred
} }
//TODO Disabled for now, as DSub was using it for offline browsing. Will re-enable it when browsing by ID3 is working child.Path = entry.Path
//n.Path = entry.Path child.PlayCount = entry.PlayCount
child.DiscNumber = entry.DiscNumber
n.PlayCount = entry.PlayCount
n.DiscNumber = entry.DiscNumber
if !entry.Created.IsZero() { if !entry.Created.IsZero() {
n.Created = &entry.Created child.Created = &entry.Created
} }
n.AlbumId = entry.AlbumId child.AlbumId = entry.AlbumId
n.ArtistId = entry.ArtistId child.ArtistId = entry.ArtistId
n.Type = entry.Type child.Type = entry.Type
n.UserRating = entry.UserRating child.UserRating = entry.UserRating
return n return child
} }
+16 -1
View File
@@ -1,6 +1,7 @@
package engine package engine
import ( import (
"fmt"
"time" "time"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
@@ -81,7 +82,10 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
e.CoverArt = mf.Id e.CoverArt = mf.Id
} }
e.ContentType = mf.ContentType() e.ContentType = mf.ContentType()
e.Path = mf.Path // Creates a "pseudo" path, to avoid sending absolute paths to the client
if mf.Path != "" {
e.Path = fmt.Sprintf("%s/%s/%s.%s", realArtistName(mf), mf.Album, mf.Title, mf.Suffix)
}
e.PlayCount = int32(mf.PlayCount) e.PlayCount = int32(mf.PlayCount)
e.DiscNumber = mf.DiscNumber e.DiscNumber = mf.DiscNumber
e.Created = mf.CreatedAt e.Created = mf.CreatedAt
@@ -92,6 +96,17 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
return e return e
} }
func realArtistName(mf *domain.MediaFile) string {
switch {
case mf.Compilation:
return "Various Artists"
case mf.AlbumArtist != "":
return mf.AlbumArtist
}
return mf.Artist
}
func FromAlbums(albums domain.Albums) Entries { func FromAlbums(albums domain.Albums) Entries {
entries := make(Entries, len(albums)) entries := make(Entries, len(albums))
for i, al := range albums { for i, al := range albums {