mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
42 lines
No EOL
895 B
Go
42 lines
No EOL
895 B
Go
package scanner
|
|
|
|
import (
|
|
"github.com/astaxie/beego"
|
|
"github.com/deluan/gosonic/repositories"
|
|
"github.com/deluan/gosonic/models"
|
|
)
|
|
|
|
type Scanner interface {
|
|
LoadFolder(path string) []Track
|
|
}
|
|
|
|
func StartImport() {
|
|
go doImport(beego.AppConfig.String("musicFolder"), &ItunesScanner{})
|
|
}
|
|
|
|
func doImport(mediaFolder string, scanner Scanner) {
|
|
beego.Info("Starting iTunes import from:", mediaFolder)
|
|
files := scanner.LoadFolder(mediaFolder)
|
|
updateDatastore(files)
|
|
beego.Info("Finished importing", len(files), "files")
|
|
}
|
|
|
|
func updateDatastore(files []Track) {
|
|
mfRepo := repositories.NewMediaFileRepository()
|
|
for _, t := range files {
|
|
m := &models.MediaFile{
|
|
Id: t.Id,
|
|
Album: t.Album,
|
|
Artist: t.Artist,
|
|
Title: t.Title,
|
|
Path: t.Path,
|
|
CreatedAt: t.CreatedAt,
|
|
UpdatedAt: t.UpdatedAt,
|
|
}
|
|
err := mfRepo.Add(m)
|
|
if err != nil {
|
|
beego.Error(err)
|
|
}
|
|
}
|
|
mfRepo.Dump()
|
|
} |