diff --git a/api/base_api_controller.go b/api/base_api_controller.go
index fca710d55..07d8fc1e9 100644
--- a/api/base_api_controller.go
+++ b/api/base_api_controller.go
@@ -172,5 +172,6 @@ func (c *BaseAPIController) ToChild(entry engine.Entry) responses.Child {
child.ArtistId = entry.ArtistId
child.Type = entry.Type
child.UserRating = entry.UserRating
+ child.SongCount = entry.SongCount
return child
}
diff --git a/api/browsing.go b/api/browsing.go
index 8aea376eb..f38ecac5f 100644
--- a/api/browsing.go
+++ b/api/browsing.go
@@ -53,6 +53,7 @@ func (c *BrowsingController) GetIndexes() {
for j, a := range idx.Artists {
res.Index[i].Artists[j].Id = a.ArtistId
res.Index[i].Artists[j].Name = a.Artist
+ res.Index[i].Artists[j].AlbumCount = a.AlbumCount
}
}
diff --git a/api/responses/responses.go b/api/responses/responses.go
index fa7b31c44..da90f056a 100644
--- a/api/responses/responses.go
+++ b/api/responses/responses.go
@@ -47,8 +47,9 @@ type MusicFolders struct {
}
type Artist struct {
- Id string `xml:"id,attr" json:"id"`
- Name string `xml:"name,attr" json:"name"`
+ Id string `xml:"id,attr" json:"id"`
+ Name string `xml:"name,attr" json:"name"`
+ AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
/*
@@ -94,6 +95,7 @@ type Child struct {
ArtistId string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
+ SongCount int `xml:"songCount,attr,omitempty" json:"songCount,omitempty"`
/*
diff --git a/domain/album.go b/domain/album.go
index 10500babd..9bc70e8f4 100644
--- a/domain/album.go
+++ b/domain/album.go
@@ -15,6 +15,7 @@ type Album struct {
Starred bool
PlayCount int
PlayDate time.Time
+ SongCount int
Duration int
Rating int
Genre string
diff --git a/domain/artist.go b/domain/artist.go
index 90ebc9dd9..a2aeebcb3 100644
--- a/domain/artist.go
+++ b/domain/artist.go
@@ -1,8 +1,9 @@
package domain
type Artist struct {
- Id string
- Name string
+ Id string
+ Name string
+ AlbumCount int
}
type ArtistRepository interface {
diff --git a/domain/index.go b/domain/index.go
index 21e525f91..48c840517 100644
--- a/domain/index.go
+++ b/domain/index.go
@@ -3,8 +3,9 @@ package domain
import "github.com/deluan/gosonic/utils"
type ArtistInfo struct {
- ArtistId string
- Artist string
+ ArtistId string
+ Artist string
+ AlbumCount int
}
type ArtistIndex struct {
diff --git a/engine/common.go b/engine/common.go
index 3c747e5bf..733657263 100644
--- a/engine/common.go
+++ b/engine/common.go
@@ -32,6 +32,7 @@ type Entry struct {
ArtistId string
Type string
UserRating int
+ SongCount int
UserName string
MinutesAgo int
@@ -59,6 +60,7 @@ func FromAlbum(al *domain.Album) Entry {
e.ArtistId = al.ArtistId
e.UserRating = al.Rating
e.Duration = al.Duration
+ e.SongCount = al.SongCount
return e
}
diff --git a/scanner/importer.go b/scanner/importer.go
index 30cb604bb..ffdab435a 100644
--- a/scanner/importer.go
+++ b/scanner/importer.go
@@ -303,7 +303,7 @@ func (i *Importer) collectIndex(ig utils.IndexGroups, a *domain.Artist, artistIn
artists = make(tempIndex)
artistIndex[group] = artists
}
- artists[indexName] = domain.ArtistInfo{ArtistId: a.Id, Artist: a.Name}
+ artists[indexName] = domain.ArtistInfo{ArtistId: a.Id, Artist: a.Name, AlbumCount: a.AlbumCount}
}
func (i *Importer) findGroup(ig utils.IndexGroups, name string) string {
diff --git a/scanner/itunes_scanner.go b/scanner/itunes_scanner.go
index 3e2a12e94..d92ff6644 100644
--- a/scanner/itunes_scanner.go
+++ b/scanner/itunes_scanner.go
@@ -64,6 +64,8 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
s.pplaylists = make(map[string]plsRelation)
s.pmediaFiles = make(map[int]*domain.MediaFile)
s.newSums = make(map[string]string)
+ songsPerAlbum := make(map[string]int)
+ albumsPerArtist := make(map[string]map[string]bool)
i := 0
for _, t := range l.Tracks {
@@ -73,6 +75,12 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
ar := s.collectArtists(&t)
mf := s.collectMediaFiles(&t)
s.collectAlbums(&t, mf, ar)
+
+ songsPerAlbum[mf.AlbumId]++
+ if albumsPerArtist[mf.ArtistId] == nil {
+ albumsPerArtist[mf.ArtistId] = make(map[string]bool)
+ }
+ albumsPerArtist[mf.ArtistId][mf.AlbumId] = true
}
i++
if i%1000 == 0 {
@@ -80,6 +88,14 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
}
}
+ for albumId, count := range songsPerAlbum {
+ s.albums[albumId].SongCount = count
+ }
+
+ for artistId, albums := range albumsPerArtist {
+ s.artists[artistId].AlbumCount = len(albums)
+ }
+
if err := s.checksumRepo.SetData(s.newSums); err != nil {
beego.Error("Error saving checksums:", err)
} else {