From 6fd5bd58633cbfe064409e5376b4acaec5993f2b Mon Sep 17 00:00:00 2001 From: Emmm Monster <58943012+emmmx@users.noreply.github.com> Date: Thu, 11 Nov 2021 23:27:07 +0800 Subject: [PATCH] fix #18: support upper case extension --- algo/common/dispatch.go | 8 +++++++- algo/common/raw.go | 7 +++++-- cmd/um/main.go | 6 ++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/algo/common/dispatch.go b/algo/common/dispatch.go index 2392152..ff42fdf 100644 --- a/algo/common/dispatch.go +++ b/algo/common/dispatch.go @@ -1,5 +1,10 @@ package common +import ( + "path/filepath" + "strings" +) + type NewDecoderFunc func([]byte) Decoder var decoderRegistry = make(map[string][]NewDecoderFunc) @@ -7,6 +12,7 @@ var decoderRegistry = make(map[string][]NewDecoderFunc) func RegisterDecoder(ext string, dispatchFunc NewDecoderFunc) { decoderRegistry[ext] = append(decoderRegistry[ext], dispatchFunc) } -func GetDecoder(ext string) []NewDecoderFunc { +func GetDecoder(filename string) []NewDecoderFunc { + ext := strings.ToLower(strings.TrimLeft(filepath.Ext(filename), ".")) return decoderRegistry[ext] } diff --git a/algo/common/raw.go b/algo/common/raw.go index f12e783..3bb8e0b 100644 --- a/algo/common/raw.go +++ b/algo/common/raw.go @@ -1,6 +1,9 @@ package common -import "errors" +import ( + "errors" + "strings" +) type RawDecoder struct { file []byte @@ -14,7 +17,7 @@ func NewRawDecoder(file []byte) Decoder { func (d *RawDecoder) Validate() error { for ext, sniffer := range snifferRegistry { if sniffer(d.file) { - d.audioExt = ext + d.audioExt = strings.ToLower(ext) return nil } } diff --git a/cmd/um/main.go b/cmd/um/main.go index 6c168b5..4c59a08 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -76,8 +76,7 @@ func appMain(c *cli.Context) error { if inputStat.IsDir() { return dealDirectory(input, output) } else { - ext := strings.TrimLeft(filepath.Ext(inputStat.Name()), ".") - allDec := common.GetDecoder(ext) + allDec := common.GetDecoder(inputStat.Name()) if len(allDec) == 0 { logging.Log().Fatal("skipping while no suitable decoder") } @@ -94,8 +93,7 @@ func dealDirectory(inputDir string, outputDir string) error { if item.IsDir() { continue } - ext := strings.TrimLeft(filepath.Ext(item.Name()), ".") - allDec := common.GetDecoder(ext) + allDec := common.GetDecoder(item.Name()) if len(allDec) == 0 { logging.Log().Info("skipping while no suitable decoder", zap.String("file", item.Name())) continue