Adding song and album counts

This commit is contained in:
Deluan 2016-03-27 20:13:00 -04:00
parent 167e7a1825
commit 3cc92a32bd
9 changed files with 32 additions and 7 deletions

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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"`
/*
<xs:attribute name="starred" type="xs:dateTime" use="optional"/> <!-- Added in 1.10.1 -->
<xs:attribute name="userRating" type="sub:UserRating" use="optional"/> <!-- Added in 1.13.0 -->
@ -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"`
/*
<xs:attribute name="isVideo" type="xs:boolean" use="optional"/> <!-- Added in 1.4.1 -->
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.6.0 -->

View File

@ -15,6 +15,7 @@ type Album struct {
Starred bool
PlayCount int
PlayDate time.Time
SongCount int
Duration int
Rating int
Genre string

View File

@ -1,8 +1,9 @@
package domain
type Artist struct {
Id string
Name string
Id string
Name string
AlbumCount int
}
type ArtistRepository interface {

View File

@ -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 {

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {