Preparing for new scanner

This commit is contained in:
Deluan 2020-01-14 21:51:35 -05:00
parent 02d642814b
commit 25686c1742
11 changed files with 31 additions and 28 deletions

6
domain/checksum.go Normal file
View file

@ -0,0 +1,6 @@
package domain
type CheckSumRepository interface {
Get(id string) (string, error)
SetData(newSums map[string]string) error
}

View file

@ -2,8 +2,8 @@ package persistence
import (
"github.com/astaxie/beego/orm"
"github.com/cloudsonic/sonic-server/domain"
"github.com/cloudsonic/sonic-server/log"
"github.com/cloudsonic/sonic-server/scanner"
)
type checkSumRepository struct {
@ -17,7 +17,7 @@ type Checksum struct {
Sum string
}
func NewCheckSumRepository() scanner.CheckSumRepository {
func NewCheckSumRepository() domain.CheckSumRepository {
r := &checkSumRepository{}
return r
}
@ -76,4 +76,4 @@ func (r *checkSumRepository) SetData(newSums map[string]string) error {
return nil
}
var _ scanner.CheckSumRepository = (*checkSumRepository)(nil)
var _ domain.CheckSumRepository = (*checkSumRepository)(nil)

View file

@ -1,13 +1,13 @@
package persistence
import (
"github.com/cloudsonic/sonic-server/scanner"
"github.com/cloudsonic/sonic-server/domain"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ChecksumRepository", func() {
var repo scanner.CheckSumRepository
var repo domain.CheckSumRepository
BeforeEach(func() {
Db().Delete(&Checksum{ID: checkSumId})

View file

@ -1,4 +1,4 @@
package scanner
package scanner_legacy
import (
"fmt"

View file

@ -1,4 +1,4 @@
package scanner
package scanner_legacy
import (
"testing"

View file

@ -1,4 +1,4 @@
package scanner
package scanner_legacy
import (
"crypto/md5"
@ -28,19 +28,14 @@ type ItunesScanner struct {
pplaylists map[string]plsRelation
pmediaFiles map[int]*domain.MediaFile
lastModifiedSince time.Time
checksumRepo CheckSumRepository
checksumRepo domain.CheckSumRepository
newSums map[string]string
}
func NewItunesScanner(checksumRepo CheckSumRepository) *ItunesScanner {
func NewItunesScanner(checksumRepo domain.CheckSumRepository) *ItunesScanner {
return &ItunesScanner{checksumRepo: checksumRepo}
}
type CheckSumRepository interface {
Get(id string) (string, error)
SetData(newSums map[string]string) error
}
type plsRelation struct {
pID string
parentPID string
@ -88,6 +83,8 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
}
}
log.Debug("Finished processing tracks.", "artists", len(s.artists), "albums", len(s.albums), "songs", len(s.mediaFiles))
for albumId, count := range songsPerAlbum {
s.albums[albumId].SongCount = count
}

View file

@ -1,4 +1,4 @@
package scanner
package scanner_legacy
import (
"testing"

View file

@ -1,4 +1,4 @@
package scanner
package scanner_legacy
import "github.com/google/wire"

View file

@ -9,7 +9,7 @@ import (
"github.com/cloudsonic/sonic-server/conf"
"github.com/cloudsonic/sonic-server/log"
"github.com/cloudsonic/sonic-server/scanner"
"github.com/cloudsonic/sonic-server/scanner_legacy"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
@ -18,11 +18,11 @@ import (
const Version = "0.2"
type Server struct {
Importer *scanner.Importer
Importer *scanner_legacy.Importer
router *chi.Mux
}
func New(importer *scanner.Importer) *Server {
func New(importer *scanner_legacy.Importer) *Server {
a := &Server{Importer: importer}
showBanner(Version)
initMimeTypes()

View file

@ -11,7 +11,7 @@ import (
"github.com/cloudsonic/sonic-server/engine"
"github.com/cloudsonic/sonic-server/itunesbridge"
"github.com/cloudsonic/sonic-server/persistence"
"github.com/cloudsonic/sonic-server/scanner"
"github.com/cloudsonic/sonic-server/scanner_legacy"
"github.com/cloudsonic/sonic-server/server"
"github.com/google/wire"
)
@ -21,14 +21,14 @@ import (
func CreateApp(musicFolder string) *server.Server {
provider := createPersistenceProvider()
checkSumRepository := provider.CheckSumRepository
itunesScanner := scanner.NewItunesScanner(checkSumRepository)
itunesScanner := scanner_legacy.NewItunesScanner(checkSumRepository)
mediaFileRepository := provider.MediaFileRepository
albumRepository := provider.AlbumRepository
artistRepository := provider.ArtistRepository
artistIndexRepository := provider.ArtistIndexRepository
playlistRepository := provider.PlaylistRepository
propertyRepository := provider.PropertyRepository
importer := scanner.NewImporter(musicFolder, itunesScanner, mediaFileRepository, albumRepository, artistRepository, artistIndexRepository, playlistRepository, propertyRepository)
importer := scanner_legacy.NewImporter(musicFolder, itunesScanner, mediaFileRepository, albumRepository, artistRepository, artistIndexRepository, playlistRepository, propertyRepository)
serverServer := server.New(importer)
return serverServer
}
@ -84,7 +84,7 @@ func createPersistenceProvider() *Provider {
type Provider struct {
AlbumRepository domain.AlbumRepository
ArtistRepository domain.ArtistRepository
CheckSumRepository scanner.CheckSumRepository
CheckSumRepository domain.CheckSumRepository
ArtistIndexRepository domain.ArtistIndexRepository
MediaFileRepository domain.MediaFileRepository
MediaFolderRepository domain.MediaFolderRepository
@ -93,7 +93,7 @@ type Provider struct {
PropertyRepository domain.PropertyRepository
}
var allProviders = wire.NewSet(itunesbridge.NewItunesControl, engine.Set, scanner.Set, api.NewRouter, wire.FieldsOf(new(*Provider), "AlbumRepository", "ArtistRepository", "CheckSumRepository",
var allProviders = wire.NewSet(itunesbridge.NewItunesControl, engine.Set, scanner_legacy.Set, api.NewRouter, wire.FieldsOf(new(*Provider), "AlbumRepository", "ArtistRepository", "CheckSumRepository",
"ArtistIndexRepository", "MediaFileRepository", "MediaFolderRepository", "NowPlayingRepository",
"PlaylistRepository", "PropertyRepository"), createPersistenceProvider,
)

View file

@ -8,7 +8,7 @@ import (
"github.com/cloudsonic/sonic-server/engine"
"github.com/cloudsonic/sonic-server/itunesbridge"
"github.com/cloudsonic/sonic-server/persistence"
"github.com/cloudsonic/sonic-server/scanner"
"github.com/cloudsonic/sonic-server/scanner_legacy"
"github.com/cloudsonic/sonic-server/server"
"github.com/google/wire"
)
@ -16,7 +16,7 @@ import (
type Provider struct {
AlbumRepository domain.AlbumRepository
ArtistRepository domain.ArtistRepository
CheckSumRepository scanner.CheckSumRepository
CheckSumRepository domain.CheckSumRepository
ArtistIndexRepository domain.ArtistIndexRepository
MediaFileRepository domain.MediaFileRepository
MediaFolderRepository domain.MediaFolderRepository
@ -28,7 +28,7 @@ type Provider struct {
var allProviders = wire.NewSet(
itunesbridge.NewItunesControl,
engine.Set,
scanner.Set,
scanner_legacy.Set,
api.NewRouter,
wire.FieldsOf(new(*Provider), "AlbumRepository", "ArtistRepository", "CheckSumRepository",
"ArtistIndexRepository", "MediaFileRepository", "MediaFolderRepository", "NowPlayingRepository",