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
+2
View File
@@ -21,6 +21,8 @@ func (s *ItunesScanner) LoadFolder(path string) []Track {
mediaFiles[i].Album = t.Album
mediaFiles[i].Title = t.Name
mediaFiles[i].Artist = t.Artist
mediaFiles[i].AlbumArtist = t.AlbumArtist
mediaFiles[i].Compilation = t.Compilation
path, _ = url.QueryUnescape(t.Location)
mediaFiles[i].Path = strings.TrimPrefix(path, "file://")
mediaFiles[i].CreatedAt = t.DateAdded
+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
}
+9 -7
View File
@@ -5,11 +5,13 @@ import (
)
type Track struct {
Id string
Path string
Album string
Artist string
Title string
CreatedAt time.Time
UpdatedAt time.Time
Id string
Path string
Title string
Album string
Artist string
AlbumArtist string
Compilation bool
CreatedAt time.Time
UpdatedAt time.Time
}