🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Trying to make code more manageable, before a big rewrite
Deluan107321219ab0
diff --git a/scanner/importer.go b/scanner/importer.goindex 95ff39532..2b5504868 100644--- a/scanner/importer.go+++ b/scanner/importer.go@@ -129,22 +129,62 @@ func (i *Importer) lastModifiedSince() time.Time {}func (i *Importer) importLibrary() (err error) {- indexGroups := utils.ParseIndexGroups(beego.AppConfig.String("indexGroups"))- artistIndex := make(map[string]tempIndex)- mfs := make(domain.MediaFiles, len(i.scanner.MediaFiles()))- als := make(domain.Albums, len(i.scanner.Albums()))- ars := make(domain.Artists, len(i.scanner.Artists()))- pls := make(domain.Playlists, len(i.scanner.Playlists()))arc, _ := i.artistRepo.CountAll()alc, _ := i.albumRepo.CountAll()mfc, _ := i.mfRepo.CountAll()plc, _ := i.plsRepo.CountAll()- alu := 0- mfu := 0- //i.search.ClearAll()- //beego.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")+ if deleted, err := i.mfRepo.PurgeInactive(mfs); err != nil {+ beego.Error(err)+ } else {+ i.search.RemoveMediaFile(deleted)+ }+ if deleted, err := i.albumRepo.PurgeInactive(als); err != nil {+ beego.Error(err)+ } else {+ i.search.RemoveAlbum(deleted)+ }+ if deleted, err := i.artistRepo.PurgeInactive(ars); err != nil {+ beego.Error(err)+ } else {+ i.search.RemoveArtist(deleted)+ }+ if _, err := i.plsRepo.PurgeInactive(pls); err != nil {+ beego.Error(err)+ }++ arc2, _ := i.artistRepo.CountAll()+ alc2, _ := i.albumRepo.CountAll()+ mfc2, _ := i.mfRepo.CountAll()+ 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))+ }+ if alu > 0 || mfu > 0 {+ beego.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)+ }++ return err+}++func (i *Importer) importMediaFiles() (domain.MediaFiles, int) {+ mfs := make(domain.MediaFiles, len(i.scanner.MediaFiles()))+ updates := 0j := 0for _, mf := range i.scanner.MediaFiles() {mfs[j] = *mf@@ -166,13 +206,18 @@ func (i *Importer) importLibrary() (err error) {if err := i.search.IndexMediaFile(mf); err != nil {beego.Error("Error indexing artist:", err)}- mfu+++ updates++if !i.lastScan.IsZero() {beego.Debug(fmt.Sprintf(`-- Updated Track: "%s"`, mf.Title))}}+ return mfs, updates+}- j = 0+func (i *Importer) importAlbums() (domain.Albums, int) {+ als := make(domain.Albums, len(i.scanner.Albums()))+ updates := 0+ j := 0for _, al := range i.scanner.Albums() {als[j] = *alj++@@ -193,13 +238,17 @@ func (i *Importer) importLibrary() (err error) {if err := i.search.IndexAlbum(al); err != nil {beego.Error("Error indexing artist:", err)}- alu+++ updates++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))}}+ return als, updates+}- j = 0+func (i *Importer) importArtists() domain.Artists {+ ars := make(domain.Artists, len(i.scanner.Artists()))+ j := 0for _, ar := range i.scanner.Artists() {ars[j] = *arj++@@ -209,10 +258,26 @@ func (i *Importer) importLibrary() (err error) {if err := i.search.IndexArtist(ar); err != nil {beego.Error("Error indexing artist:", err)}+ }+ return ars+}++func (i *Importer) importArtistIndex() {+ indexGroups := utils.ParseIndexGroups(beego.AppConfig.String("indexGroups"))+ artistIndex := make(map[string]tempIndex)++ for _, ar := range i.scanner.Artists() {i.collectIndex(indexGroups, ar, artistIndex)}- j = 0+ if err := i.saveIndex(artistIndex); err != nil {+ beego.Error(err)+ }+}++func (i *Importer) importPlaylists() domain.Playlists {+ pls := make(domain.Playlists, len(i.scanner.Playlists()))+ j := 0for _, pl := range i.scanner.Playlists() {pl.Public = truepl.Owner = beego.AppConfig.String("user")@@ -223,50 +288,7 @@ func (i *Importer) importLibrary() (err error) {beego.Error(err)}}-- if err = i.saveIndex(artistIndex); err != nil {- beego.Error(err)- }-- beego.Debug("Purging old data")- if deleted, err := i.mfRepo.PurgeInactive(mfs); err != nil {- beego.Error(err)- } else {- i.search.RemoveMediaFile(deleted)- }- if deleted, err := i.albumRepo.PurgeInactive(als); err != nil {- beego.Error(err)- } else {- i.search.RemoveAlbum(deleted)- }- if deleted, err := i.artistRepo.PurgeInactive(ars); err != nil {- beego.Error(err)- } else {- i.search.RemoveArtist(deleted)- }- if _, err := i.plsRepo.PurgeInactive(pls); err != nil {- beego.Error(err)- }-- arc2, _ := i.artistRepo.CountAll()- alc2, _ := i.albumRepo.CountAll()- mfc2, _ := i.mfRepo.CountAll()- 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))- }- if alu > 0 || mfu > 0 {- beego.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)- }-- return err+ return pls}func (i *Importer) collectIndex(ig utils.IndexGroups, a *domain.Artist, artistIndex map[string]tempIndex) {