fix #18: support upper case extension

pull/23/head
Emmm Monster 3 years ago
parent 0a13671df2
commit 6fd5bd5863
No known key found for this signature in database
GPG Key ID: C98279C83FB50DB9

@ -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]
}

@ -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
}
}

@ -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

Loading…
Cancel
Save