Replaced Beego logging
This commit is contained in:
+33
-33
@@ -7,10 +7,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/cloudsonic/sonic-server/conf"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/utils"
|
||||
)
|
||||
|
||||
@@ -64,7 +64,7 @@ func (i *Importer) startImport() {
|
||||
go func() {
|
||||
info, err := os.Stat(i.mediaFolder)
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
if i.lastCheck.After(info.ModTime()) {
|
||||
@@ -80,39 +80,39 @@ func (i *Importer) scan() {
|
||||
i.lastScan = i.lastModifiedSince()
|
||||
|
||||
if i.lastScan.IsZero() {
|
||||
beego.Info("Starting first iTunes Library scan. This can take a while...")
|
||||
log.Info("Starting first iTunes Library scan. This can take a while...")
|
||||
}
|
||||
|
||||
total, err := i.scanner.ScanLibrary(i.lastScan, i.mediaFolder)
|
||||
if err != nil {
|
||||
beego.Error("Error importing iTunes Library:", err)
|
||||
log.Error("Error importing iTunes Library", err)
|
||||
return
|
||||
}
|
||||
|
||||
beego.Debug("Found", total, "tracks,",
|
||||
len(i.scanner.MediaFiles()), "songs,",
|
||||
len(i.scanner.Albums()), "albums,",
|
||||
len(i.scanner.Artists()), "artists",
|
||||
len(i.scanner.Playlists()), "playlists")
|
||||
log.Debug("Found", "tracks", total,
|
||||
"songs", len(i.scanner.MediaFiles()),
|
||||
"albums", len(i.scanner.Albums()),
|
||||
"artists", len(i.scanner.Artists()),
|
||||
"playlists", len(i.scanner.Playlists()))
|
||||
|
||||
if err := i.importLibrary(); err != nil {
|
||||
beego.Error("Error persisting data:", err)
|
||||
log.Error("Error persisting data", err)
|
||||
}
|
||||
if i.lastScan.IsZero() {
|
||||
beego.Info("Finished first iTunes Library import")
|
||||
log.Info("Finished first iTunes Library import")
|
||||
} else {
|
||||
beego.Debug("Finished updating tracks from iTunes Library")
|
||||
log.Debug("Finished updating tracks from iTunes Library")
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Importer) lastModifiedSince() time.Time {
|
||||
ms, err := i.propertyRepo.Get(engine.PropLastScan)
|
||||
if err != nil {
|
||||
beego.Warn("Couldn't read LastScan:", err)
|
||||
log.Warn("Couldn't read LastScan", err)
|
||||
return time.Time{}
|
||||
}
|
||||
if ms == "" {
|
||||
beego.Debug("First scan")
|
||||
log.Debug("First scan")
|
||||
return time.Time{}
|
||||
}
|
||||
s, _ := strconv.ParseInt(ms, 10, 64)
|
||||
@@ -125,31 +125,31 @@ func (i *Importer) importLibrary() (err error) {
|
||||
mfc, _ := i.mfRepo.CountAll()
|
||||
plc, _ := i.plsRepo.CountAll()
|
||||
|
||||
beego.Debug("Saving updated data")
|
||||
log.Debug("Saving updated data")
|
||||
mfs, mfu := i.importMediaFiles()
|
||||
als, alu := i.importAlbums()
|
||||
ars := i.importArtists()
|
||||
pls := i.importPlaylists()
|
||||
i.importArtistIndex()
|
||||
|
||||
beego.Debug("Purging old data")
|
||||
log.Debug("Purging old data")
|
||||
if deleted, err := i.mfRepo.PurgeInactive(mfs); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
} else {
|
||||
i.search.RemoveMediaFile(deleted...)
|
||||
}
|
||||
if deleted, err := i.albumRepo.PurgeInactive(als); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
} else {
|
||||
i.search.RemoveAlbum(deleted...)
|
||||
}
|
||||
if deleted, err := i.artistRepo.PurgeInactive(ars); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
} else {
|
||||
i.search.RemoveArtist(deleted...)
|
||||
}
|
||||
if _, err := i.plsRepo.PurgeInactive(pls); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
arc2, _ := i.artistRepo.CountAll()
|
||||
@@ -158,16 +158,16 @@ func (i *Importer) importLibrary() (err error) {
|
||||
plc2, _ := i.plsRepo.CountAll()
|
||||
|
||||
if arc != arc2 || alc != alc2 || mfc != mfc2 || plc != plc2 {
|
||||
beego.Info(fmt.Sprintf("Updated library totals: %d(%+d) artists, %d(%+d) albums, %d(%+d) songs, %d(%+d) playlists", arc2, arc2-arc, alc2, alc2-alc, mfc2, mfc2-mfc, plc2, plc2-plc))
|
||||
log.Info(fmt.Sprintf("Updated library totals: %d(%+d) artists, %d(%+d) albums, %d(%+d) songs, %d(%+d) playlists", arc2, arc2-arc, alc2, alc2-alc, mfc2, mfc2-mfc, plc2, plc2-plc))
|
||||
}
|
||||
if alu > 0 || mfu > 0 {
|
||||
beego.Info(fmt.Sprintf("Updated items: %d album(s), %d song(s)", alu, mfu))
|
||||
log.Info(fmt.Sprintf("Updated items: %d album(s), %d song(s)", alu, mfu))
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
millis := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
i.propertyRepo.Put(engine.PropLastScan, fmt.Sprint(millis))
|
||||
beego.Debug("LastScan timestamp:", millis)
|
||||
log.Debug("LastScan", "timestamp", millis)
|
||||
}
|
||||
|
||||
return err
|
||||
@@ -192,14 +192,14 @@ func (i *Importer) importMediaFiles() (domain.MediaFiles, int) {
|
||||
}
|
||||
}
|
||||
if err := i.mfRepo.Put(mf); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
}
|
||||
if err := i.search.IndexMediaFile(mf); err != nil {
|
||||
beego.Error("Error indexing artist:", err)
|
||||
log.Error("Error indexing artist", err)
|
||||
}
|
||||
updates++
|
||||
if !i.lastScan.IsZero() {
|
||||
beego.Debug(fmt.Sprintf(`-- Updated Track: "%s"`, mf.Title))
|
||||
log.Debug(fmt.Sprintf(`-- Updated Track: "%s"`, mf.Title))
|
||||
}
|
||||
}
|
||||
return mfs, updates
|
||||
@@ -224,14 +224,14 @@ func (i *Importer) importAlbums() (domain.Albums, int) {
|
||||
}
|
||||
}
|
||||
if err := i.albumRepo.Put(al); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
}
|
||||
if err := i.search.IndexAlbum(al); err != nil {
|
||||
beego.Error("Error indexing artist:", err)
|
||||
log.Error("Error indexing artist", err)
|
||||
}
|
||||
updates++
|
||||
if !i.lastScan.IsZero() {
|
||||
beego.Debug(fmt.Sprintf(`-- Updated Album: "%s" from "%s"`, al.Name, al.Artist))
|
||||
log.Debug(fmt.Sprintf(`-- Updated Album: "%s" from "%s"`, al.Name, al.Artist))
|
||||
}
|
||||
}
|
||||
return als, updates
|
||||
@@ -244,10 +244,10 @@ func (i *Importer) importArtists() domain.Artists {
|
||||
ars[j] = *ar
|
||||
j++
|
||||
if err := i.artistRepo.Put(ar); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
}
|
||||
if err := i.search.IndexArtist(ar); err != nil {
|
||||
beego.Error("Error indexing artist:", err)
|
||||
log.Error("Error indexing artist", err)
|
||||
}
|
||||
}
|
||||
return ars
|
||||
@@ -262,7 +262,7 @@ func (i *Importer) importArtistIndex() {
|
||||
}
|
||||
|
||||
if err := i.saveIndex(artistIndex); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ func (i *Importer) importPlaylists() domain.Playlists {
|
||||
pls[j] = *pl
|
||||
j++
|
||||
if err := i.plsRepo.Put(pl); err != nil {
|
||||
beego.Error(err)
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
return pls
|
||||
|
||||
+11
-11
@@ -13,9 +13,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/cloudsonic/sonic-server/conf"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/dhowden/itl"
|
||||
"github.com/dhowden/tag"
|
||||
)
|
||||
@@ -49,13 +49,13 @@ type plsRelation struct {
|
||||
}
|
||||
|
||||
func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (int, error) {
|
||||
beego.Debug("Checking for updates since", lastModifiedSince.String(), "- Library:", path)
|
||||
log.Debug("Checking for updates", "lastModifiedSince", lastModifiedSince, "library", path)
|
||||
xml, _ := os.Open(path)
|
||||
l, err := itl.ReadFromXML(xml)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
beego.Debug("Loaded", len(l.Tracks), "tracks")
|
||||
log.Debug("Loaded tracks", "total", len(l.Tracks))
|
||||
|
||||
s.lastModifiedSince = lastModifiedSince
|
||||
s.mediaFiles = make(map[string]*domain.MediaFile)
|
||||
@@ -85,7 +85,7 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
||||
}
|
||||
i++
|
||||
if i%1000 == 0 {
|
||||
beego.Debug("Processed", i, "tracks.", len(s.artists), "artists,", len(s.albums), "albums", len(s.mediaFiles), "songs")
|
||||
log.Debug(fmt.Sprintf("Processed %d tracks", i), "artists", len(s.artists), "albums", len(s.albums), "songs", len(s.mediaFiles))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
||||
}
|
||||
|
||||
if err := s.checksumRepo.SetData(s.newSums); err != nil {
|
||||
beego.Error("Error saving checksums:", err)
|
||||
log.Error("Error saving checksums", err)
|
||||
} else {
|
||||
beego.Debug("Saved", len(s.newSums), "checksums")
|
||||
log.Debug("Saved checksums", "total", len(s.newSums))
|
||||
}
|
||||
|
||||
ignFolders := conf.Sonic.PlsIgnoreFolders
|
||||
@@ -116,7 +116,7 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
||||
|
||||
s.collectPlaylists(&p, fullPath)
|
||||
}
|
||||
beego.Debug("Processed", len(l.Playlists), "playlists.")
|
||||
log.Debug("Processed playlists", "total", len(l.Playlists))
|
||||
|
||||
return len(l.Tracks), nil
|
||||
}
|
||||
@@ -346,26 +346,26 @@ func artistId(t *itl.Track) string {
|
||||
func hasCoverArt(path string) bool {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
beego.Error("Reading tag for", path, "Panic:", r)
|
||||
log.Error("Panic reading tag", "path", path, "error", r)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
beego.Warn("Error opening file", path, "-", err)
|
||||
log.Warn("Error opening file", "path", path, err)
|
||||
return false
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
m, err := tag.ReadFrom(f)
|
||||
if err != nil {
|
||||
beego.Warn("Error reading tag from file", path, "-", err)
|
||||
log.Warn("Error reading tag from file", "path", path, err)
|
||||
return false
|
||||
}
|
||||
return m.Picture() != nil
|
||||
}
|
||||
//beego.Warn("File not found:", path)
|
||||
//log.Warn("File not found", "path", path)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user