mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-01 08:01:15 +03:00
Polishing
This commit is contained in:
parent
12aedc0996
commit
cad65f517c
2
main.go
2
main.go
@ -13,6 +13,6 @@ func main() {
|
|||||||
if beego.BConfig.RunMode == "prod" {
|
if beego.BConfig.RunMode == "prod" {
|
||||||
beego.SetLevel(beego.LevelInformational)
|
beego.SetLevel(beego.LevelInformational)
|
||||||
}
|
}
|
||||||
beego.BConfig.Log.FileLineNum = false
|
//beego.BConfig.Log.FileLineNum = false
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ func (r *checkSumRepository) loadData() {
|
|||||||
for _, p := range pairs {
|
for _, p := range pairs {
|
||||||
r.data[string(p.Field)] = string(p.Value)
|
r.data[string(p.Field)] = string(p.Value)
|
||||||
}
|
}
|
||||||
|
beego.Debug("Loaded", len(r.data), "checksums")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *checkSumRepository) Put(id, sum string) error {
|
func (r *checkSumRepository) Put(id, sum string) error {
|
||||||
|
@ -47,8 +47,7 @@ type plsRelation struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (int, error) {
|
func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (int, error) {
|
||||||
beego.Info("Starting iTunes import from:", path)
|
beego.Info("Checking for updates since", lastModifiedSince.String(), "- Library:", path)
|
||||||
beego.Info("Checking for updates since", lastModifiedSince.String())
|
|
||||||
xml, _ := os.Open(path)
|
xml, _ := os.Open(path)
|
||||||
l, err := itl.ReadFromXML(xml)
|
l, err := itl.ReadFromXML(xml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -183,7 +182,26 @@ func (s *ItunesScanner) lastChangedDate(t *itl.Track) time.Time {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ItunesScanner) hasChanged(t *itl.Track) bool {
|
||||||
|
id := strconv.Itoa(t.TrackID)
|
||||||
|
oldSum, _ := s.checksumRepo.Get(id)
|
||||||
|
newSum := s.newSums[id]
|
||||||
|
return oldSum != newSum
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calc sum of stats fields (whose changes are not reflected in DataModified)
|
||||||
|
func (s *ItunesScanner) calcCheckSum(t *itl.Track) string {
|
||||||
|
id := strconv.Itoa(t.TrackID)
|
||||||
|
data := fmt.Sprint(t.DateModified, t.PlayCount, t.PlayDate, t.ArtworkCount, t.Loved, t.AlbumLoved,
|
||||||
|
t.Rating, t.AlbumRating, t.SkipCount, t.SkipDate)
|
||||||
|
sum := fmt.Sprintf("%x", md5.Sum([]byte(data)))
|
||||||
|
s.newSums[id] = sum
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
||||||
|
s.calcCheckSum(t)
|
||||||
|
|
||||||
mf := &domain.MediaFile{}
|
mf := &domain.MediaFile{}
|
||||||
mf.Id = strconv.Itoa(t.TrackID)
|
mf.Id = strconv.Itoa(t.TrackID)
|
||||||
mf.Album = unescape(t.Album)
|
mf.Album = unescape(t.Album)
|
||||||
@ -262,14 +280,6 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
|
|||||||
return al
|
return al
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ItunesScanner) hasChanged(t *itl.Track) bool {
|
|
||||||
id := strconv.Itoa(t.TrackID)
|
|
||||||
oldSum, _ := s.checksumRepo.Get(id)
|
|
||||||
newSum := calcCheckSum(t)
|
|
||||||
s.newSums[id] = newSum
|
|
||||||
return oldSum != newSum
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ItunesScanner) collectArtists(t *itl.Track) *domain.Artist {
|
func (s *ItunesScanner) collectArtists(t *itl.Track) *domain.Artist {
|
||||||
id := artistId(t)
|
id := artistId(t)
|
||||||
_, found := s.artists[id]
|
_, found := s.artists[id]
|
||||||
@ -340,12 +350,4 @@ func realArtistName(t *itl.Track) string {
|
|||||||
return t.Artist
|
return t.Artist
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calc sum of stats fields (whose changes are not reflected in DataModified)
|
|
||||||
func calcCheckSum(t *itl.Track) string {
|
|
||||||
data := fmt.Sprint(t.DateModified, t.PlayCount, t.PlayDate, t.ArtworkCount, t.Loved, t.AlbumLoved,
|
|
||||||
t.Rating, t.AlbumRating, t.SkipCount, t.SkipDate)
|
|
||||||
return fmt.Sprintf("%x", md5.Sum([]byte(data)))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ Scanner = (*ItunesScanner)(nil)
|
var _ Scanner = (*ItunesScanner)(nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user