🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Implementing coverArt
Deluan1b945831cc68
diff --git a/.gitignore b/.gitignoreindex 7d9408e20..4c8f08beb 100644--- a/.gitignore+++ b/.gitignore@@ -1,9 +1,6 @@-lastupdate.tmp-gosonic-iTunes.xml-iTunesFull.xml-gosonic.index+/gosonic+/iTunes*.xmlstatic/JamstashdevDb-tmp+/tmp.vendor\ No newline at end of filediff --git a/.gopmfile b/.gopmfileindex f4db45418..42239c037 100644--- a/.gopmfile+++ b/.gopmfile@@ -7,6 +7,7 @@ github.com/deluan/itl = commit:35d15a3github.com/siddontang/ledisdb = commit:713b229github.com/smartystreets/goconvey = commit:899ed5agithub.com/karlkfi/inject = commit:fe06da2+github.com/dhowden/tag = commit:a35ac09[res]include = confdiff --git a/.travis.yml b/.travis.ymlindex ac24be1e6..94b35339d 100644--- a/.travis.yml+++ b/.travis.yml@@ -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/tagscript:- go test ./... -vdiff --git a/api/get_music_directory.go b/api/get_music_directory.goindex 085d8728f..9ef226c43 100644--- a/api/get_music_directory.go+++ b/api/get_music_directory.go@@ -57,6 +57,7 @@ func (c *GetMusicDirectoryController) buildArtistDir(a *domain.Artist, albums []dir.Child[i].Year = al.Yeardir.Child[i].Artist = al.Artistdir.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 []ddir.Child[i].Size = mf.Sizedir.Child[i].Suffix = mf.Suffixdir.Child[i].BitRate = mf.BitRate+ if mf.HasCoverArt {+ dir.Child[i].CoverArt = mf.Id+ }}return dir}diff --git a/conf/app.conf b/conf/app.confindex 1739a786d..a447bbe7e 100644--- a/conf/app.conf+++ b/conf/app.conf@@ -8,7 +8,7 @@ apiVersion = 1.0.0ignoredArticles="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.xmluser=deluanpassword=wordpassdbPath = ./devDbdiff --git a/domain/album.go b/domain/album.goindex 556a61279..06958704c 100644--- a/domain/album.go+++ b/domain/album.go@@ -5,6 +5,7 @@ type Album struct {Name stringArtistId string `parent:"artist"`CoverArtPath string // TODO http://stackoverflow.com/questions/13795842/linking-itunes-itc2-files-and-ituneslibrary-xml+ CoverArtId stringArtist stringAlbumArtist stringYear intdiff --git a/domain/mediafile.go b/domain/mediafile.goindex a7416c8c4..a41472f9b 100644--- a/domain/mediafile.go+++ b/domain/mediafile.go@@ -12,6 +12,7 @@ type MediaFile struct {Artist stringAlbumArtist stringAlbumId string `parent:"album"`+ HasCoverArt boolTrackNumber intDiscNumber intYear intdiff --git a/scanner/itunes_scanner.go b/scanner/itunes_scanner.goindex e9a6162d6..64d0d3133 100644--- a/scanner/itunes_scanner.go+++ b/scanner/itunes_scanner.go@@ -39,7 +39,7 @@ func (s *ItunesScanner) LoadFolder(path string) []Track {}mediaFiles[i].BitRate = t.BitRatepath, _ = url.QueryUnescape(t.Location)- path = strings.TrimPrefix(path, "file://")+ path = strings.TrimPrefix(unescape(path), "file://")mediaFiles[i].Path = pathmediaFiles[i].Suffix = strings.TrimPrefix(filepath.Ext(path), ".")mediaFiles[i].CreatedAt = t.DateAddeddiff --git a/scanner/scanner.go b/scanner/scanner.goindex 0f3bd1b1d..883f682ca 100644--- a/scanner/scanner.go+++ b/scanner/scanner.go@@ -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(),}