More experimenting with tiedot

This commit is contained in:
Deluan
2016-02-27 03:35:01 -05:00
parent 4f9054b738
commit ecc0df9e7c
14 changed files with 175 additions and 35 deletions
+25 -1
View File
@@ -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
}