Fix child.size and directory.playCount compatibility with Subsonic API. Fixes #304

This commit is contained in:
Deluan 2020-05-19 23:50:27 -04:00
parent c2d1e9df9f
commit 17df63b550
12 changed files with 17 additions and 18 deletions

View file

@ -61,7 +61,7 @@ type DirectoryInfo struct {
Entries Entries
Parent string
Starred time.Time
PlayCount int32
PlayCount int64
UserRating int
AlbumCount int
CoverArt string
@ -138,7 +138,7 @@ func (b *browser) buildArtistDir(a *model.Artist, albums model.Albums) *Director
for i := range albums {
al := albums[i]
dir.Entries[i] = FromAlbum(&al)
dir.PlayCount += int32(al.PlayCount)
dir.PlayCount += al.PlayCount
}
return dir
}
@ -156,7 +156,7 @@ func (b *browser) buildAlbumDir(al *model.Album, tracks model.MediaFiles) *Direc
Year: al.MaxYear,
Genre: al.Genre,
CoverArt: al.CoverArtId,
PlayCount: int32(al.PlayCount),
PlayCount: al.PlayCount,
UserRating: al.Rating,
}

View file

@ -23,7 +23,7 @@ type Entry struct {
Starred time.Time
Track int
Duration int
Size int
Size int64
Suffix string
BitRate int
ContentType string

View file

@ -27,7 +27,7 @@ type Album struct {
UpdatedAt time.Time `json:"updatedAt"`
// Annotations
PlayCount int `json:"playCount" orm:"-"`
PlayCount int64 `json:"playCount" orm:"-"`
PlayDate time.Time `json:"playDate" orm:"-"`
Rating int `json:"rating" orm:"-"`
Starred bool `json:"starred" orm:"-"`

View file

@ -12,7 +12,7 @@ type Artist struct {
OrderArtistName string `json:"orderArtistName"`
// Annotations
PlayCount int `json:"playCount" orm:"-"`
PlayCount int64 `json:"playCount" orm:"-"`
PlayDate time.Time `json:"playDate" orm:"-"`
Rating int `json:"rating" orm:"-"`
Starred bool `json:"starred" orm:"-"`

View file

@ -20,7 +20,7 @@ type MediaFile struct {
DiscNumber int `json:"discNumber"`
DiscSubtitle string `json:"discSubtitle"`
Year int `json:"year"`
Size int `json:"size"`
Size int64 `json:"size"`
Suffix string `json:"suffix"`
Duration float32 `json:"duration"`
BitRate int `json:"bitRate"`
@ -38,7 +38,7 @@ type MediaFile struct {
UpdatedAt time.Time `json:"updatedAt"`
// Annotations
PlayCount int `json:"playCount" orm:"-"`
PlayCount int64 `json:"playCount" orm:"-"`
PlayDate time.Time `json:"playDate" orm:"-"`
Rating int `json:"rating" orm:"-"`
Starred bool `json:"starred" orm:"-"`

View file

@ -101,7 +101,7 @@ var _ = Describe("MediaRepository", func() {
Expect(err).To(BeNil())
Expect(mf.PlayDate.Unix()).To(Equal(playDate.Unix()))
Expect(mf.PlayCount).To(Equal(1))
Expect(mf.PlayCount).To(Equal(int64(1)))
})
It("increments play count on newly starred items", func() {
@ -115,7 +115,7 @@ var _ = Describe("MediaRepository", func() {
Expect(err).To(BeNil())
Expect(mf.PlayDate.Unix()).To(Equal(playDate.Unix()))
Expect(mf.PlayCount).To(Equal(1))
Expect(mf.PlayCount).To(Equal(int64(1)))
})
})
})

View file

@ -49,7 +49,7 @@ func (m *Metadata) BitRate() int { return m.parseInt("bitrate") }
func (m *Metadata) ModificationTime() time.Time { return m.fileInfo.ModTime() }
func (m *Metadata) FilePath() string { return m.filePath }
func (m *Metadata) Suffix() string { return m.suffix }
func (m *Metadata) Size() int { return int(m.fileInfo.Size()) }
func (m *Metadata) Size() int64 { return m.fileInfo.Size() }
func LoadAllAudioFiles(dirPath string) (map[string]os.FileInfo, error) {
dir, err := os.Open(dirPath)

View file

@ -229,7 +229,7 @@ func (c *BrowsingController) buildAlbum(ctx context.Context, d *engine.Directory
dir.CoverArt = d.CoverArt
dir.SongCount = d.SongCount
dir.Duration = d.Duration
dir.PlayCount = int64(d.PlayCount)
dir.PlayCount = d.PlayCount
dir.Year = d.Year
dir.Genre = d.Genre
if !d.Created.IsZero() {

View file

@ -5,7 +5,6 @@ import (
"fmt"
"mime"
"net/http"
"strconv"
"github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/engine"
@ -119,7 +118,7 @@ func ToChild(ctx context.Context, entry engine.Entry) responses.Child {
child.CoverArt = entry.CoverArt
child.Track = entry.Track
child.Duration = entry.Duration
child.Size = strconv.Itoa(entry.Size)
child.Size = entry.Size
child.Suffix = entry.Suffix
child.BitRate = entry.BitRate
child.ContentType = entry.ContentType

View file

@ -1 +1 @@
{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","directory":{"child":[{"id":"1","isDir":true,"title":"title","album":"album","artist":"artist","track":1,"year":1985,"genre":"Rock","coverArt":"1","size":"8421341","contentType":"audio/flac","suffix":"flac","starred":"2016-03-02T20:30:00Z","transcodedContentType":"audio/mpeg","transcodedSuffix":"mp3","duration":146,"bitRate":320,"isVideo":false}],"id":"1","name":"N"}}
{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","directory":{"child":[{"id":"1","isDir":true,"title":"title","album":"album","artist":"artist","track":1,"year":1985,"genre":"Rock","coverArt":"1","size":8421341,"contentType":"audio/flac","suffix":"flac","starred":"2016-03-02T20:30:00Z","transcodedContentType":"audio/mpeg","transcodedSuffix":"mp3","duration":146,"bitRate":320,"isVideo":false}],"id":"1","name":"N"}}

View file

@ -96,7 +96,7 @@ type Child struct {
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
Size string `xml:"size,attr,omitempty" json:"size,omitempty"`
Size int64 `xml:"size,attr,omitempty" json:"size,omitempty"`
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
@ -132,7 +132,7 @@ type Directory struct {
Name string `xml:"name,attr" json:"name"`
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"`
PlayCount int64 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
// ID3

View file

@ -115,7 +115,7 @@ var _ = Describe("Responses", func() {
t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)
child[0] = Child{
Id: "1", IsDir: true, Title: "title", Album: "album", Artist: "artist", Track: 1,
Year: 1985, Genre: "Rock", CoverArt: "1", Size: "8421341", ContentType: "audio/flac",
Year: 1985, Genre: "Rock", CoverArt: "1", Size: 8421341, ContentType: "audio/flac",
Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3",
Duration: 146, BitRate: 320, Starred: &t,
}