2020-12-26 07:47:10 +00:00
|
|
|
package common
|
|
|
|
|
2021-11-11 15:27:07 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
)
|
2021-05-23 11:59:29 +00:00
|
|
|
|
2020-12-26 07:47:10 +00:00
|
|
|
type RawDecoder struct {
|
2020-12-26 08:07:48 +00:00
|
|
|
file []byte
|
|
|
|
audioExt string
|
2020-12-26 07:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewRawDecoder(file []byte) Decoder {
|
|
|
|
return &RawDecoder{file: file}
|
|
|
|
}
|
|
|
|
|
2021-05-23 11:59:29 +00:00
|
|
|
func (d *RawDecoder) Validate() error {
|
|
|
|
for ext, sniffer := range snifferRegistry {
|
|
|
|
if sniffer(d.file) {
|
2021-11-11 15:27:07 +00:00
|
|
|
d.audioExt = strings.ToLower(ext)
|
2021-05-23 11:59:29 +00:00
|
|
|
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 {
|
2021-05-23 11:59:29 +00:00
|
|
|
return d.audioExt
|
2020-12-26 07:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d RawDecoder) GetMeta() Meta {
|
|
|
|
return nil
|
|
|
|
}
|
2021-05-23 11:59:29 +00:00
|
|
|
|
2020-12-26 07:47:10 +00:00
|
|
|
func init() {
|
2021-11-11 15:43:20 +00:00
|
|
|
RegisterDecoder("mp3", true, NewRawDecoder)
|
|
|
|
RegisterDecoder("flac", true, NewRawDecoder)
|
|
|
|
RegisterDecoder("ogg", true, NewRawDecoder)
|
|
|
|
RegisterDecoder("m4a", true, NewRawDecoder)
|
|
|
|
RegisterDecoder("wav", true, NewRawDecoder)
|
|
|
|
RegisterDecoder("wma", true, NewRawDecoder)
|
|
|
|
RegisterDecoder("aac", true, NewRawDecoder)
|
2020-12-26 07:47:10 +00:00
|
|
|
}
|