mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-28 17:32:22 +03:00
Adding song and album counts
This commit is contained in:
parent
167e7a1825
commit
3cc92a32bd
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ type MusicFolders struct {
|
||||
type Artist struct {
|
||||
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 -->
|
||||
|
@ -15,6 +15,7 @@ type Album struct {
|
||||
Starred bool
|
||||
PlayCount int
|
||||
PlayDate time.Time
|
||||
SongCount int
|
||||
Duration int
|
||||
Rating int
|
||||
Genre string
|
||||
|
@ -3,6 +3,7 @@ package domain
|
||||
type Artist struct {
|
||||
Id string
|
||||
Name string
|
||||
AlbumCount int
|
||||
}
|
||||
|
||||
type ArtistRepository interface {
|
||||
|
@ -5,6 +5,7 @@ import "github.com/deluan/gosonic/utils"
|
||||
type ArtistInfo struct {
|
||||
ArtistId string
|
||||
Artist string
|
||||
AlbumCount int
|
||||
}
|
||||
|
||||
type ArtistIndex struct {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user