Register Decoder With Default Output Ext

This commit is contained in:
Emmm Monster 2020-12-26 16:07:48 +08:00
parent d5031e1935
commit 91e23a20dd
No known key found for this signature in database
GPG Key ID: C98279C83FB50DB9
5 changed files with 59 additions and 31 deletions

View File

@ -1,9 +1,11 @@
package common
type RawDecoder struct {
file []byte
file []byte
audioExt string
}
//goland:noinspection GoUnusedExportedFunction
func NewRawDecoder(file []byte) Decoder {
return &RawDecoder{file: file}
}
@ -25,17 +27,21 @@ func (d RawDecoder) GetAudioData() []byte {
}
func (d RawDecoder) GetAudioExt() string {
return ""
return d.audioExt
}
func (d RawDecoder) GetMeta() Meta {
return nil
}
func init() {
RegisterDecoder("mp3", NewRawDecoder)
RegisterDecoder("flac", NewRawDecoder)
RegisterDecoder("wav", NewRawDecoder)
RegisterDecoder("ogg", NewRawDecoder)
RegisterDecoder("m4a", NewRawDecoder)
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"))
}

View File

@ -53,6 +53,7 @@ func (m RawMetaMusic) GetFormat() string {
return m.Format
}
//goland:noinspection SpellCheckingInspection
type RawMetaDJ struct {
ProgramID int `json:"programId"`
ProgramName string `json:"programName"`

View File

@ -22,6 +22,7 @@ type Decoder struct {
audio []byte
}
//goland:noinspection GoUnusedExportedFunction
func NewDefaultDecoder(data []byte) common.Decoder {
return &Decoder{file: data, mask: getDefaultMask()}
}
@ -95,22 +96,29 @@ func (d Decoder) GetMeta() common.Meta {
return nil
}
func DecoderFuncWithExt(ext string) common.NewDecoderFunc {
return func(file []byte) common.Decoder {
return &Decoder{file: file, audioExt: ext}
}
}
//goland:noinspection SpellCheckingInspection
func init() {
common.RegisterDecoder("qmc3", NewDefaultDecoder) //QQ Music Mp3
common.RegisterDecoder("qmc2", NewDefaultDecoder) //QQ Music Ogg
common.RegisterDecoder("qmc0", NewDefaultDecoder) //QQ Music Mp3
common.RegisterDecoder("qmcflac", NewDefaultDecoder) //QQ Music Flac
common.RegisterDecoder("qmcogg", NewDefaultDecoder) //QQ Music Ogg
common.RegisterDecoder("tkm", NewDefaultDecoder) //QQ Music Accompaniment M4a
common.RegisterDecoder("qmc3", DecoderFuncWithExt("mp3")) //QQ Music Mp3
common.RegisterDecoder("qmc2", DecoderFuncWithExt("ogg")) //QQ Music Ogg
common.RegisterDecoder("qmc0", DecoderFuncWithExt("mp3")) //QQ Music Mp3
common.RegisterDecoder("qmcflac", DecoderFuncWithExt("flac")) //QQ Music Flac
common.RegisterDecoder("qmcogg", DecoderFuncWithExt("ogg")) //QQ Music Ogg
common.RegisterDecoder("tkm", DecoderFuncWithExt("m4a")) //QQ Music Accompaniment M4a
common.RegisterDecoder("bkcmp3", NewDefaultDecoder) //Moo Music Mp3
common.RegisterDecoder("bkcflac", NewDefaultDecoder) //Moo Music Flac
common.RegisterDecoder("bkcmp3", DecoderFuncWithExt("mp3")) //Moo Music Mp3
common.RegisterDecoder("bkcflac", DecoderFuncWithExt("flac")) //Moo Music Flac
common.RegisterDecoder("666c6163", NewDefaultDecoder) //QQ Music Weiyun Flac
common.RegisterDecoder("6d7033", NewDefaultDecoder) //QQ Music Weiyun Mp3
common.RegisterDecoder("6f6767", NewDefaultDecoder) //QQ Music Weiyun Ogg
common.RegisterDecoder("6d3461", NewDefaultDecoder) //QQ Music Weiyun M4a
common.RegisterDecoder("776176", NewDefaultDecoder) //QQ Music Weiyun Wav
common.RegisterDecoder("666c6163", DecoderFuncWithExt("flac")) //QQ Music Weiyun Flac
common.RegisterDecoder("6d7033", DecoderFuncWithExt("mp3")) //QQ Music Weiyun Mp3
common.RegisterDecoder("6f6767", DecoderFuncWithExt("ogg")) //QQ Music Weiyun Ogg
common.RegisterDecoder("6d3461", DecoderFuncWithExt("m4a")) //QQ Music Weiyun M4a
common.RegisterDecoder("776176", DecoderFuncWithExt("wav")) //QQ Music Weiyun Wav
common.RegisterDecoder("mgg", NewMgg256Decoder) //QQ Music Weiyun Wav
common.RegisterDecoder("mflac", NewMflac256Decoder) //QQ Music Weiyun Wav

View File

@ -54,16 +54,23 @@ func (d *Decoder) Decode() error {
return nil
}
//goland:noinspection GoUnusedExportedFunction
func NewDecoder(data []byte) common.Decoder {
return &Decoder{file: data}
}
func DecoderFuncWithExt(ext string) common.NewDecoderFunc {
return func(file []byte) common.Decoder {
return &Decoder{file: file, audioExt: ext}
}
}
func init() {
// QQ Music IOS M4a
common.RegisterDecoder("tm2", NewDecoder)
common.RegisterDecoder("tm6", NewDecoder)
common.RegisterDecoder("tm2", DecoderFuncWithExt("m4a"))
common.RegisterDecoder("tm6", DecoderFuncWithExt("m4a"))
// QQ Music IOS Mp3
common.RegisterDecoder("tm0", common.NewRawDecoder)
common.RegisterDecoder("tm3", common.NewRawDecoder)
common.RegisterDecoder("tm0", common.DecoderFuncWithExt("mp3"))
common.RegisterDecoder("tm3", common.DecoderFuncWithExt("mp3"))
}

View File

@ -84,13 +84,19 @@ func (d *Decoder) Decode() error {
}
return nil
}
func DecoderFuncWithExt(ext string) common.NewDecoderFunc {
return func(file []byte) common.Decoder {
return &Decoder{file: file, outputExt: ext}
}
}
func init() {
// Xiami Wav/M4a/Mp3/Flac
common.RegisterDecoder("xm", NewDecoder)
// Xiami Typed Format
// todo: Init With Type
common.RegisterDecoder("wav", NewDecoder)
common.RegisterDecoder("mp3", NewDecoder)
common.RegisterDecoder("flac", NewDecoder)
common.RegisterDecoder("m4a", NewDecoder)
common.RegisterDecoder("wav", DecoderFuncWithExt("wav"))
common.RegisterDecoder("mp3", DecoderFuncWithExt("mp3"))
common.RegisterDecoder("flac", DecoderFuncWithExt("flac"))
common.RegisterDecoder("m4a", DecoderFuncWithExt("m4a"))
}