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

@ -2,8 +2,10 @@ package common
type RawDecoder struct { type RawDecoder struct {
file []byte file []byte
audioExt string
} }
//goland:noinspection GoUnusedExportedFunction
func NewRawDecoder(file []byte) Decoder { func NewRawDecoder(file []byte) Decoder {
return &RawDecoder{file: file} return &RawDecoder{file: file}
} }
@ -25,17 +27,21 @@ func (d RawDecoder) GetAudioData() []byte {
} }
func (d RawDecoder) GetAudioExt() string { func (d RawDecoder) GetAudioExt() string {
return "" return d.audioExt
} }
func (d RawDecoder) GetMeta() Meta { func (d RawDecoder) GetMeta() Meta {
return nil return nil
} }
func DecoderFuncWithExt(ext string) NewDecoderFunc {
func init() { return func(file []byte) Decoder {
RegisterDecoder("mp3", NewRawDecoder) return &RawDecoder{file: file, audioExt: ext}
RegisterDecoder("flac", NewRawDecoder) }
RegisterDecoder("wav", NewRawDecoder) }
RegisterDecoder("ogg", NewRawDecoder) func init() {
RegisterDecoder("m4a", NewRawDecoder) 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 return m.Format
} }
//goland:noinspection SpellCheckingInspection
type RawMetaDJ struct { type RawMetaDJ struct {
ProgramID int `json:"programId"` ProgramID int `json:"programId"`
ProgramName string `json:"programName"` ProgramName string `json:"programName"`

View File

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

View File

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