Updated Date takes Last Played into account

This commit is contained in:
Deluan 2016-03-11 17:09:47 -05:00
parent f4c1dbdd3c
commit 71f1fab575
3 changed files with 18 additions and 6 deletions

View File

@ -1,7 +1,7 @@
GoSonic
=======
[![Build Status](https://travis-ci.org/deluan/gosonic.svg?branch=master)](https://travis-ci.org/deluan/gosonic)
[![Build Status](https://travis-ci.org/deluan/gosonic.svg?branch=master)](https://travis-ci.org/deluan/gosonic) [![Go Report Card](https://goreportcard.com/badge/github.com/deluan/gosonic)](https://goreportcard.com/report/github.com/deluan/gosonic)
__This is still a work in progress, and has no releases available__

View File

@ -107,7 +107,7 @@ func (i *Importer) importLibrary() (err error) {
beego.Error("Error indexing artist:", err)
}
if !i.lastScan.IsZero() {
beego.Debug("Updated Track:", mf.Title)
beego.Debug("-- Updated Track:", mf.Title)
}
}
@ -125,7 +125,7 @@ func (i *Importer) importLibrary() (err error) {
beego.Error("Error indexing artist:", err)
}
if !i.lastScan.IsZero() {
beego.Debug(fmt.Sprintf(`Updated Album:"%s" from "%s"`, al.Name, al.Artist))
beego.Debug(fmt.Sprintf(`-- Updated Album:"%s" from "%s"`, al.Name, al.Artist))
}
}

View File

@ -157,6 +157,17 @@ func (s *ItunesScanner) fullPath(pID string) string {
return fmt.Sprintf("%s > %s", s.fullPath(rel.parentPID), rel.name)
}
func (s *ItunesScanner) changeDate(t *itl.Track) time.Time {
allDates := []time.Time{t.DateModified, t.PlayDateUTC}
c := time.Time{}
for _, d := range allDates {
if c.Before(d) {
c = d
}
}
return c
}
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
mf := &domain.MediaFile{}
mf.Id = strconv.Itoa(t.TrackID)
@ -188,7 +199,7 @@ func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
mf.Suffix = strings.TrimPrefix(filepath.Ext(path), ".")
mf.CreatedAt = t.DateAdded
mf.UpdatedAt = t.DateModified
mf.UpdatedAt = s.changeDate(t)
if mf.UpdatedAt.After(s.lastModifiedSince) {
mf.HasCoverArt = hasCoverArt(path)
@ -229,8 +240,9 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
if al.CreatedAt.IsZero() || t.DateAdded.Before(al.CreatedAt) {
al.CreatedAt = t.DateAdded
}
if al.UpdatedAt.IsZero() || t.DateModified.After(al.UpdatedAt) {
al.UpdatedAt = t.DateModified
trackUpdate := s.changeDate(t)
if al.UpdatedAt.IsZero() || trackUpdate.After(al.UpdatedAt) {
al.UpdatedAt = trackUpdate
}
return al