More experimenting with tiedot
This commit is contained in:
+25
-1
@@ -4,6 +4,9 @@ import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/deluan/gosonic/repositories"
|
||||
"github.com/deluan/gosonic/models"
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type Scanner interface {
|
||||
@@ -23,12 +26,15 @@ func doImport(mediaFolder string, scanner Scanner) {
|
||||
|
||||
func updateDatastore(files []Track) {
|
||||
mfRepo := repositories.NewMediaFileRepository()
|
||||
var artistIndex = make(map[string]map[string]string)
|
||||
for _, t := range files {
|
||||
m := &models.MediaFile{
|
||||
Id: t.Id,
|
||||
Album: t.Album,
|
||||
Artist: t.Artist,
|
||||
AlbumArtist: t.AlbumArtist,
|
||||
Title: t.Title,
|
||||
Compilation: t.Compilation,
|
||||
Path: t.Path,
|
||||
CreatedAt: t.CreatedAt,
|
||||
UpdatedAt: t.UpdatedAt,
|
||||
@@ -37,6 +43,24 @@ func updateDatastore(files []Track) {
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
}
|
||||
collectIndex(m, artistIndex)
|
||||
}
|
||||
mfRepo.Dump()
|
||||
//mfRepo.Dump()
|
||||
j,_ := json.MarshalIndent(artistIndex, "", " ")
|
||||
fmt.Println(string(j))
|
||||
}
|
||||
|
||||
func collectIndex(m *models.MediaFile, artistIndex map[string]map[string]string) {
|
||||
name := m.RealArtist()
|
||||
indexName := strings.ToLower(models.NoArticle(name))
|
||||
if indexName == "" {
|
||||
return
|
||||
}
|
||||
initial := strings.ToUpper(indexName[0:1])
|
||||
artists := artistIndex[initial]
|
||||
if artists == nil {
|
||||
artists = make(map[string]string)
|
||||
artistIndex[initial] = artists
|
||||
}
|
||||
artists[indexName] = name
|
||||
}
|
||||
Reference in New Issue
Block a user