mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Experiments with bleve, repositories and parsing itunes
This commit is contained in:
parent
c8b7695b09
commit
9a55fa1c64
8 changed files with 93 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
commentsRouter_*.go
|
||||
lastupdate.tmp
|
||||
gosonic
|
||||
iTunes Music Library.xml
|
|
@ -5,6 +5,7 @@ REST/WEB
|
|||
http://beego.me/
|
||||
|
||||
DB
|
||||
https://github.com/boltdb/bolt
|
||||
https://github.com/HouzuoGuo/tiedot
|
||||
|
||||
SEARCH
|
||||
|
|
|
@ -5,6 +5,8 @@ autorender = false
|
|||
copyrequestbody = true
|
||||
|
||||
apiversion = 1.0.0
|
||||
musicfolder=.
|
||||
|
||||
[dev]
|
||||
enableadmin = true
|
||||
indexpath = ./gosonic.index
|
27
main.go
27
main.go
|
@ -8,6 +8,33 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
//// open a new index
|
||||
//itunes.LoadFolder("iTunes Music Library.xml")
|
||||
//
|
||||
//mapping := bleve.NewIndexMapping()
|
||||
//index, err := bleve.New("example.bleve", mapping)
|
||||
//if (err != nil) {
|
||||
// index, err = bleve.Open("example.bleve")
|
||||
//}
|
||||
//
|
||||
//// index some data
|
||||
//doc := struct {
|
||||
// Id string
|
||||
// Value string
|
||||
//}{
|
||||
// Id: "01",
|
||||
// Value: "deluan cotts quintao",
|
||||
//}
|
||||
//err = index.Index("01", doc)
|
||||
//fmt.Println(err)
|
||||
//
|
||||
//// search for some text
|
||||
//query := bleve.NewMatchQuery("*cotts*")
|
||||
//search := bleve.NewSearchRequest(query)
|
||||
//searchResults, err := index.Search(search)
|
||||
//fmt.Println(err)
|
||||
//fmt.Println(searchResults.Hits)
|
||||
|
||||
if beego.BConfig.RunMode == "dev" {
|
||||
beego.BConfig.WebConfig.DirectoryIndex = true
|
||||
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
||||
|
|
15
models/media_file.go
Normal file
15
models/media_file.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type MediaFile struct {
|
||||
Id string
|
||||
Path string
|
||||
Album string
|
||||
Artist string
|
||||
Title string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
10
repositories/media_file_repository.go
Normal file
10
repositories/media_file_repository.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package repositories
|
||||
|
||||
import "github.com/deluan/gosonic/models"
|
||||
//
|
||||
//func AddMediaFile(m models.MediaFile) string {
|
||||
// m.ID = "user_" + strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||
// UserList[u.Id] = &u
|
||||
// return u.Id
|
||||
//}
|
||||
//
|
29
scanners/itunes/itl_scanner.go
Normal file
29
scanners/itunes/itl_scanner.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package itunes
|
||||
|
||||
import (
|
||||
"github.com/dhowden/itl"
|
||||
"os"
|
||||
"github.com/deluan/gosonic/models"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func LoadFolder(path string) []models.MediaFile {
|
||||
xml, _ := os.Open(path)
|
||||
l,_ := itl.ReadFromXML(xml)
|
||||
|
||||
mediaFiles := make([]models.MediaFile, len(l.Tracks))
|
||||
i := 0
|
||||
for id, track := range l.Tracks {
|
||||
mediaFiles[i].Id = id
|
||||
mediaFiles[i].Album = track.Album
|
||||
mediaFiles[i].Title = track.Name
|
||||
mediaFiles[i].Artist = track.Artist
|
||||
path,_ = url.QueryUnescape(track.Location)
|
||||
mediaFiles[i].Path = strings.TrimPrefix(path, "file://")
|
||||
mediaFiles[i].CreatedAt = track.DateAdded
|
||||
mediaFiles[i].UpdatedAt = track.DateModified
|
||||
i++
|
||||
}
|
||||
return mediaFiles
|
||||
}
|
7
scanners/scanner.go
Normal file
7
scanners/scanner.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package scanners
|
||||
|
||||
import "github.com/deluan/gosonic/models"
|
||||
|
||||
type Scanner interface {
|
||||
LoadFolder(path string) []models.MediaFile
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue