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
+16 -1
View File
@@ -1,6 +1,7 @@
package engine
import (
"fmt"
"time"
"github.com/deluan/gosonic/domain"
@@ -81,7 +82,10 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
e.CoverArt = mf.Id
}
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.DiscNumber = mf.DiscNumber
e.Created = mf.CreatedAt
@@ -92,6 +96,17 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
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 {
entries := make(Entries, len(albums))
for i, al := range albums {