|
|
|
@ -1,17 +1,24 @@
|
|
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
|
|
type RawDecoder struct {
|
|
|
|
|
file []byte
|
|
|
|
|
audioExt string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//goland:noinspection GoUnusedExportedFunction
|
|
|
|
|
func NewRawDecoder(file []byte) Decoder {
|
|
|
|
|
return &RawDecoder{file: file}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d RawDecoder) Validate() error {
|
|
|
|
|
return nil
|
|
|
|
|
func (d *RawDecoder) Validate() error {
|
|
|
|
|
for ext, sniffer := range snifferRegistry {
|
|
|
|
|
if sniffer(d.file) {
|
|
|
|
|
d.audioExt = ext
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return errors.New("audio doesn't recognized")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d RawDecoder) Decode() error {
|
|
|
|
@ -27,21 +34,19 @@ func (d RawDecoder) GetAudioData() []byte {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d RawDecoder) GetAudioExt() string {
|
|
|
|
|
return "." + d.audioExt
|
|
|
|
|
return d.audioExt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d RawDecoder) GetMeta() Meta {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
func DecoderFuncWithExt(ext string) NewDecoderFunc {
|
|
|
|
|
return func(file []byte) Decoder {
|
|
|
|
|
return &RawDecoder{file: file, audioExt: ext}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
/*RegisterDecoder("mp3", DecoderFuncWithExt("mp3"))
|
|
|
|
|
RegisterDecoder("flac", DecoderFuncWithExt("flac"))
|
|
|
|
|
RegisterDecoder("wav", DecoderFuncWithExt("wav"))
|
|
|
|
|
RegisterDecoder("ogg", DecoderFuncWithExt("ogg"))
|
|
|
|
|
RegisterDecoder("m4a", DecoderFuncWithExt("m4a"))*/
|
|
|
|
|
RegisterDecoder("mp3", NewRawDecoder)
|
|
|
|
|
RegisterDecoder("flac", NewRawDecoder)
|
|
|
|
|
RegisterDecoder("ogg", NewRawDecoder)
|
|
|
|
|
RegisterDecoder("m4a", NewRawDecoder)
|
|
|
|
|
RegisterDecoder("wav", NewRawDecoder)
|
|
|
|
|
RegisterDecoder("wma", NewRawDecoder)
|
|
|
|
|
RegisterDecoder("aac", NewRawDecoder)
|
|
|
|
|
}
|
|
|
|
|