summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sample/file-hasher-requst.json2
-rw-r--r--src/file-hasher/main.go7
-rw-r--r--src/file-hasher/walker.go24
3 files changed, 19 insertions, 14 deletions
diff --git a/sample/file-hasher-requst.json b/sample/file-hasher-requst.json
index d2a1446..d0b11ba 100644
--- a/sample/file-hasher-requst.json
+++ b/sample/file-hasher-requst.json
@@ -1,8 +1,10 @@
{
"threads": 2,
+ "valid-ext": [ "flac", "ogg", "wav", "mp3", "aac", "mp4", "m4a" ],
"src": {
"dir": [
"../../../../Music/Dead Man's Bones - Dead Man's Bones (2009)",
+ "../../../../Music/Woodkid - The Golden Age",
"../../../../Music/Hozier - Hozier"
],
"m3u": [
diff --git a/src/file-hasher/main.go b/src/file-hasher/main.go
index c7718ee..7100496 100644
--- a/src/file-hasher/main.go
+++ b/src/file-hasher/main.go
@@ -26,6 +26,7 @@ import (
"log"
"os"
"os/signal"
+ "strings"
"syscall"
"time"
)
@@ -37,6 +38,7 @@ type Request struct {
Directories []string `json:"dir"`
M3UPlaylists []string `json:"m3u"`
} `json:"src"`
+ ValidExtensions []string `json:"valid-ext"`
}
func main() {
@@ -47,6 +49,11 @@ func main() {
stdlog.Fatalf("Error decoding request: %v", err)
}
+ validExtensions = req.ValidExtensions
+ for i, ext := range validExtensions {
+ validExtensions[i] = strings.ToLower(ext)
+ }
+
C := make(chan os.Signal, 1)
signal.Notify(C, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM)
diff --git a/src/file-hasher/walker.go b/src/file-hasher/walker.go
index cc543a2..602f974 100644
--- a/src/file-hasher/walker.go
+++ b/src/file-hasher/walker.go
@@ -26,23 +26,19 @@ import (
"strings"
)
+var validExtensions []string
+
func checkFileExt(path string) bool {
- switch strings.ToLower(filepath.Ext(path)) {
- case ".flac":
- return true
- case ".ogg":
- return true
- case ".wav":
- return true
- case ".mp3":
- return true
- case ".aac":
- return true
- case ".mp4":
- return true
- case ".m4a":
+ if len(validExtensions) == 0 {
return true
}
+
+ ext := strings.ToLower(filepath.Ext(path))
+ for _, e := range validExtensions {
+ if ext == "."+e {
+ return true
+ }
+ }
return false
}