Implementing coverArt

This commit is contained in:
Deluan 2016-03-03 10:34:17 -05:00
parent 80880434aa
commit 1b945831cc
9 changed files with 40 additions and 8 deletions

9
.gitignore vendored
View File

@ -1,9 +1,6 @@
lastupdate.tmp
gosonic
iTunes.xml
iTunesFull.xml
gosonic.index
/gosonic
/iTunes*.xml
static/Jamstash
devDb
tmp
/tmp
.vendor

View File

@ -7,6 +7,7 @@ github.com/deluan/itl = commit:35d15a3
github.com/siddontang/ledisdb = commit:713b229
github.com/smartystreets/goconvey = commit:899ed5a
github.com/karlkfi/inject = commit:fe06da2
github.com/dhowden/tag = commit:a35ac09
[res]
include = conf

View File

@ -13,6 +13,7 @@ install:
- go get github.com/siddontang/ledisdb/ledis
- go get github.com/karlkfi/inject
- go get github.com/smartystreets/goconvey
- go get github.com/dhowden/tag
script:
- go test ./... -v

View File

@ -57,6 +57,7 @@ func (c *GetMusicDirectoryController) buildArtistDir(a *domain.Artist, albums []
dir.Child[i].Year = al.Year
dir.Child[i].Artist = al.Artist
dir.Child[i].Genre = al.Genre
dir.Child[i].CoverArt = al.CoverArtId
}
return dir
}
@ -78,6 +79,9 @@ func (c *GetMusicDirectoryController) buildAlbumDir(al *domain.Album, tracks []d
dir.Child[i].Size = mf.Size
dir.Child[i].Suffix = mf.Suffix
dir.Child[i].BitRate = mf.BitRate
if mf.HasCoverArt {
dir.Child[i].CoverArt = mf.Id
}
}
return dir
}

View File

@ -8,7 +8,7 @@ apiVersion = 1.0.0
ignoredArticles="The El La Los Las Le Les Os As O A"
indexGroups=A B C D E F G H I J K L M N O P Q R S T U V W X-Z(XYZ)
musicFolder=./iTunesFull.xml
musicFolder=./iTunes.xml
user=deluan
password=wordpass
dbPath = ./devDb

View File

@ -5,6 +5,7 @@ type Album struct {
Name string
ArtistId string `parent:"artist"`
CoverArtPath string // TODO http://stackoverflow.com/questions/13795842/linking-itunes-itc2-files-and-ituneslibrary-xml
CoverArtId string
Artist string
AlbumArtist string
Year int

View File

@ -12,6 +12,7 @@ type MediaFile struct {
Artist string
AlbumArtist string
AlbumId string `parent:"album"`
HasCoverArt bool
TrackNumber int
DiscNumber int
Year int

View File

@ -39,7 +39,7 @@ func (s *ItunesScanner) LoadFolder(path string) []Track {
}
mediaFiles[i].BitRate = t.BitRate
path, _ = url.QueryUnescape(t.Location)
path = strings.TrimPrefix(path, "file://")
path = strings.TrimPrefix(unescape(path), "file://")
mediaFiles[i].Path = path
mediaFiles[i].Suffix = strings.TrimPrefix(filepath.Ext(path), ".")
mediaFiles[i].CreatedAt = t.DateAdded

View File

@ -9,6 +9,8 @@ import (
"github.com/deluan/gosonic/utils"
"strings"
"time"
"github.com/dhowden/tag"
"os"
)
type Scanner interface {
@ -63,7 +65,27 @@ func importLibrary(files []Track) (err error) {
return err
}
func hasCoverArt(path string) bool {
if _, err := os.Stat(path); err == nil {
f, err := os.Open(path)
if err != nil {
beego.Warn("Error opening file", path, "-", err)
return false
}
defer f.Close()
m, err := tag.ReadFrom(f)
if err != nil {
beego.Warn("Error reading tag from file", path, "-", err)
}
return m.Picture() != nil
}
//beego.Warn("File not found:", path)
return false
}
func parseTrack(t *Track) (*domain.MediaFile, *domain.Album, *domain.Artist) {
hasCover := hasCoverArt(t.Path)
mf := &domain.MediaFile{
Id: t.Id,
Album: t.Album,
@ -75,6 +97,7 @@ func parseTrack(t *Track) (*domain.MediaFile, *domain.Album, *domain.Artist) {
Path: t.Path,
CreatedAt: t.CreatedAt,
UpdatedAt: t.UpdatedAt,
HasCoverArt: hasCover,
TrackNumber: t.TrackNumber,
DiscNumber: t.DiscNumber,
Genre: t.Genre,
@ -95,6 +118,10 @@ func parseTrack(t *Track) (*domain.MediaFile, *domain.Album, *domain.Artist) {
AlbumArtist: t.AlbumArtist,
}
if mf.HasCoverArt {
album.CoverArtId = mf.Id
}
artist := &domain.Artist{
Name: t.RealArtist(),
}