Skip to content

🎧 Your Personal Streaming Service

Implementing coverArt

Deluan1b945831cc68
diff --git a/.gitignore b/.gitignore
index 7d9408e20..4c8f08beb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,6 @@
-lastupdate.tmp
-gosonic
-iTunes.xml
-iTunesFull.xml
-gosonic.index
+/gosonic
+/iTunes*.xml
static/Jamstash
devDb
-tmp
+/tmp
.vendor
\ No newline at end of file
diff --git a/.gopmfile b/.gopmfile
index f4db45418..42239c037 100644
--- a/.gopmfile
+++ b/.gopmfile
@@ -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
diff --git a/.travis.yml b/.travis.yml
index 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/tag
script:
- go test ./... -v
diff --git a/api/get_music_directory.go b/api/get_music_directory.go
index 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.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
}
diff --git a/conf/app.conf b/conf/app.conf
index 1739a786d..a447bbe7e 100644
--- a/conf/app.conf
+++ b/conf/app.conf
@@ -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
diff --git a/domain/album.go b/domain/album.go
index 556a61279..06958704c 100644
--- a/domain/album.go
+++ b/domain/album.go
@@ -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
diff --git a/domain/mediafile.go b/domain/mediafile.go
index a7416c8c4..a41472f9b 100644
--- a/domain/mediafile.go
+++ b/domain/mediafile.go
@@ -12,6 +12,7 @@ type MediaFile struct {
Artist string
AlbumArtist string
AlbumId string `parent:"album"`
+ HasCoverArt bool
TrackNumber int
DiscNumber int
Year int
diff --git a/scanner/itunes_scanner.go b/scanner/itunes_scanner.go
index 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.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
diff --git a/scanner/scanner.go b/scanner/scanner.go
index 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(),
}