Skip to content

Commit

Permalink
Ignore m3u files when scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 4, 2020
1 parent 1cc03fd commit 17830d6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions scanner/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var _ = Describe("Metadata", func() {
Expect(files).To(HaveKey("tests/fixtures/test.ogg"))
Expect(files).To(HaveKey("tests/fixtures/test.mp3"))
Expect(files).To(HaveKey("tests/fixtures/01 Invisible (RED) Edit Version.mp3"))
Expect(files).ToNot(HaveKey("tests/fixtures/playlist.m3u"))
})
It("returns error if path does not exist", func() {
_, err := LoadAllAudioFiles("./INVALID/PATH")
Expand Down
Empty file added tests/fixtures/playlist.m3u
Empty file.
7 changes: 6 additions & 1 deletion utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import (
"strings"
)

var excludeAudioType = []string{
"audio/x-mpegurl",
}

func IsAudioFile(filePath string) bool {
extension := filepath.Ext(filePath)
return strings.HasPrefix(mime.TypeByExtension(extension), "audio/")
mimeType := mime.TypeByExtension(extension)
return !StringInSlice(mimeType, excludeAudioType) && strings.HasPrefix(mimeType, "audio/")
}

func IsImageFile(filePath string) bool {
Expand Down
8 changes: 8 additions & 0 deletions utils/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ var _ = Describe("Files", func() {
It("returns false for a non-audio file", func() {
Expect(IsAudioFile("test.jpg")).To(BeFalse())
})

It("returns false for m3u files", func() {
Expect(IsAudioFile("test.m3u")).To(BeFalse())
})

It("returns false for pls files", func() {
Expect(IsAudioFile("test.pls")).To(BeFalse())
})
})

Describe("IsImageFile", func() {
Expand Down

0 comments on commit 17830d6

Please sign in to comment.