1
0
forked from um/cli
cli/algo/common/raw.go

53 lines
952 B
Go
Raw Permalink Normal View History

2020-12-26 07:47:10 +00:00
package common
import "errors"
2020-12-26 07:47:10 +00:00
type RawDecoder struct {
file []byte
audioExt string
2020-12-26 07:47:10 +00:00
}
func NewRawDecoder(file []byte) Decoder {
return &RawDecoder{file: file}
}
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")
2020-12-26 07:47:10 +00:00
}
func (d RawDecoder) Decode() error {
return nil
}
func (d RawDecoder) GetCoverImage() []byte {
return nil
}
func (d RawDecoder) GetAudioData() []byte {
return d.file
}
func (d RawDecoder) GetAudioExt() string {
return d.audioExt
2020-12-26 07:47:10 +00:00
}
func (d RawDecoder) GetMeta() Meta {
return nil
}
2020-12-26 07:47:10 +00:00
func init() {
RegisterDecoder("mp3", NewRawDecoder)
RegisterDecoder("flac", NewRawDecoder)
RegisterDecoder("ogg", NewRawDecoder)
RegisterDecoder("m4a", NewRawDecoder)
RegisterDecoder("wav", NewRawDecoder)
RegisterDecoder("wma", NewRawDecoder)
RegisterDecoder("aac", NewRawDecoder)
2020-12-26 07:47:10 +00:00
}