Fixed iTunes location decoding
This commit is contained in:
@@ -24,6 +24,7 @@ disableValidation = true
|
|||||||
enableAdmin = true
|
enableAdmin = true
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
|
enableAdmin = false
|
||||||
disableValidation = false
|
disableValidation = false
|
||||||
httpPort = 8081
|
httpPort = 8081
|
||||||
user = deluan
|
user = deluan
|
||||||
|
|||||||
@@ -193,8 +193,7 @@ func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
|||||||
}
|
}
|
||||||
mf.BitRate = t.BitRate
|
mf.BitRate = t.BitRate
|
||||||
|
|
||||||
path, _ := url.QueryUnescape(t.Location)
|
path := extractPath(t.Location)
|
||||||
path = strings.TrimPrefix(unescape(path), "file://")
|
|
||||||
mf.Path = path
|
mf.Path = path
|
||||||
mf.Suffix = strings.TrimPrefix(filepath.Ext(path), ".")
|
mf.Suffix = strings.TrimPrefix(filepath.Ext(path), ".")
|
||||||
|
|
||||||
@@ -300,6 +299,13 @@ func unescape(str string) string {
|
|||||||
return html.UnescapeString(str)
|
return html.UnescapeString(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func extractPath(loc string) string {
|
||||||
|
path := strings.Replace(loc, "+", "%2B", -1)
|
||||||
|
path, _ = url.QueryUnescape(path)
|
||||||
|
path = html.UnescapeString(path)
|
||||||
|
return strings.TrimPrefix(path, "file://")
|
||||||
|
}
|
||||||
|
|
||||||
func realArtistName(t *itl.Track) string {
|
func realArtistName(t *itl.Track) string {
|
||||||
switch {
|
switch {
|
||||||
case t.Compilation:
|
case t.Compilation:
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package scanner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestExtractLocation(t *testing.T) {
|
||||||
|
|
||||||
|
Convey("Given a path with a plus (+) signal", t, func() {
|
||||||
|
location := "file:///Users/deluan/Music/iTunes%201/iTunes%20Media/Music/Chance/Six%20Through%20Ten/03%20Forgive+Forget.m4a"
|
||||||
|
|
||||||
|
Convey("When I decode it", func() {
|
||||||
|
path := extractPath(location)
|
||||||
|
|
||||||
|
Convey("I get the correct path", func() {
|
||||||
|
So(path, ShouldEqual, "/Users/deluan/Music/iTunes 1/iTunes Media/Music/Chance/Six Through Ten/03 Forgive+Forget.m4a")
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user