Implemented more getAlbumList.view types

This commit is contained in:
Deluan
2016-03-04 17:01:14 -05:00
parent 766fdbc60c
commit 1c9d7721ad
4 changed files with 21 additions and 5 deletions
+4 -2
View File
@@ -18,9 +18,11 @@ type GetAlbumListController struct {
func (c *GetAlbumListController) Prepare() { func (c *GetAlbumListController) Prepare() {
inject.ExtractAssignable(utils.Graph, &c.albumRepo) inject.ExtractAssignable(utils.Graph, &c.albumRepo)
// TODO To implement other types, we need to fix album data at import time
c.types = map[string]domain.QueryOptions{ c.types = map[string]domain.QueryOptions{
"newest": domain.QueryOptions{SortBy: "CreatedAt", Desc: true, Alpha: true}, "newest": domain.QueryOptions{SortBy: "CreatedAt", Desc: true, Alpha: true},
"recent": domain.QueryOptions{SortBy: "PlayDate", Desc: true, Alpha: true},
"frequent": domain.QueryOptions{SortBy: "PlayCount", Desc: true},
"highest": domain.QueryOptions{SortBy: "Rating", Desc: true},
} }
} }
+2
View File
@@ -13,6 +13,8 @@ type Album struct {
Year int Year int
Compilation bool Compilation bool
Starred bool Starred bool
PlayCount int
PlayDate time.Time
Rating int Rating int
Genre string Genre string
CreatedAt time.Time CreatedAt time.Time
+7 -3
View File
@@ -1,8 +1,8 @@
package domain package domain
import ( import (
"time"
"mime" "mime"
"time"
) )
type MediaFile struct { type MediaFile struct {
@@ -23,6 +23,9 @@ type MediaFile struct {
BitRate int BitRate int
Genre string Genre string
Compilation bool Compilation bool
PlayCount int
PlayDate time.Time
Rating int
Starred bool Starred bool
CreatedAt time.Time CreatedAt time.Time
UpdatedAt time.Time UpdatedAt time.Time
@@ -33,10 +36,11 @@ func (mf *MediaFile) ContentType() string {
} }
type MediaFiles []MediaFile type MediaFiles []MediaFile
func (a MediaFiles) Len() int { return len(a) }
func (a MediaFiles) Len() int { return len(a) }
func (a MediaFiles) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a MediaFiles) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a MediaFiles) Less(i, j int) bool { func (a MediaFiles) Less(i, j int) bool {
return (a[i].DiscNumber * 1000 + a[i].TrackNumber) < (a[j].DiscNumber * 1000 + a[j].TrackNumber) return (a[i].DiscNumber*1000 + a[i].TrackNumber) < (a[j].DiscNumber*1000 + a[j].TrackNumber)
} }
type MediaFileRepository interface { type MediaFileRepository interface {
+8
View File
@@ -64,6 +64,9 @@ func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
mf.Genre = unescape(t.Genre) mf.Genre = unescape(t.Genre)
mf.Compilation = t.Compilation mf.Compilation = t.Compilation
mf.Starred = t.Loved mf.Starred = t.Loved
mf.Rating = t.Rating
mf.PlayCount = t.PlayCount
mf.PlayDate = t.PlayDateUTC
mf.Year = t.Year mf.Year = t.Year
mf.TrackNumber = t.TrackNumber mf.TrackNumber = t.TrackNumber
mf.DiscNumber = t.DiscNumber mf.DiscNumber = t.DiscNumber
@@ -103,6 +106,8 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
al.Year = t.Year al.Year = t.Year
al.Compilation = t.Compilation al.Compilation = t.Compilation
al.Starred = t.AlbumLoved al.Starred = t.AlbumLoved
al.Rating = t.AlbumRating
al.PlayCount += t.PlayCount
al.Genre = mf.Genre al.Genre = mf.Genre
al.Artist = mf.Artist al.Artist = mf.Artist
al.AlbumArtist = mf.AlbumArtist al.AlbumArtist = mf.AlbumArtist
@@ -111,6 +116,9 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
al.CoverArtId = mf.Id al.CoverArtId = mf.Id
} }
if al.PlayDate.IsZero() || t.PlayDateUTC.After(al.PlayDate) {
al.PlayDate = t.PlayDateUTC
}
if al.CreatedAt.IsZero() || t.DateAdded.Before(al.CreatedAt) { if al.CreatedAt.IsZero() || t.DateAdded.Before(al.CreatedAt) {
al.CreatedAt = t.DateAdded al.CreatedAt = t.DateAdded
} }