navidrome/engine/common.go

76 lines
1.2 KiB
Go
Raw Normal View History

2016-03-10 00:28:11 +01:00
package engine
import (
"errors"
"time"
2016-03-11 15:10:40 +01:00
"github.com/deluan/gosonic/domain"
2016-03-10 00:28:11 +01:00
)
2016-03-11 15:10:40 +01:00
type Entry struct {
2016-03-10 00:28:11 +01:00
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 Entries []Entry
2016-03-10 00:28:11 +01:00
var (
2016-03-10 17:25:15 +01:00
ErrDataNotFound = errors.New("Data Not Found")
2016-03-10 00:28:11 +01:00
)
2016-03-11 15:10:40 +01:00
func FromAlbum(al *domain.Album) Entry {
c := Entry{}
c.Id = al.Id
c.Title = al.Name
c.IsDir = true
c.Parent = al.ArtistId
c.Album = al.Name
c.Year = al.Year
c.Artist = al.AlbumArtist
c.Genre = al.Genre
c.CoverArt = al.CoverArtId
if al.Starred {
c.Starred = al.UpdatedAt
}
return c
}
func FromMediaFile(mf *domain.MediaFile) Entry {
c := Entry{}
c.Id = mf.Id
c.Title = mf.Title
c.IsDir = false
c.Parent = mf.AlbumId
c.Album = mf.Album
c.Year = mf.Year
c.Artist = mf.Artist
c.Genre = mf.Genre
c.Track = mf.TrackNumber
c.Duration = mf.Duration
c.Size = mf.Size
c.Suffix = mf.Suffix
c.BitRate = mf.BitRate
if mf.Starred {
c.Starred = mf.UpdatedAt
}
if mf.HasCoverArt {
c.CoverArt = mf.Id
}
c.ContentType = mf.ContentType()
return c
}