From 91e23a20dd105a2f4af02fc3d999f0c26bf80838 Mon Sep 17 00:00:00 2001 From: Emmm Monster <58943012+emmmx@users.noreply.github.com> Date: Sat, 26 Dec 2020 16:07:48 +0800 Subject: [PATCH] Register Decoder With Default Output Ext --- algo/common/raw.go | 24 +++++++++++++++--------- algo/ncm/meta.go | 1 + algo/qmc/qmc.go | 34 +++++++++++++++++++++------------- algo/tm/tm.go | 15 +++++++++++---- algo/xm/xm.go | 16 +++++++++++----- 5 files changed, 59 insertions(+), 31 deletions(-) diff --git a/algo/common/raw.go b/algo/common/raw.go index 13af2a5..28d3f06 100644 --- a/algo/common/raw.go +++ b/algo/common/raw.go @@ -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")) } diff --git a/algo/ncm/meta.go b/algo/ncm/meta.go index f4a6400..632d8df 100644 --- a/algo/ncm/meta.go +++ b/algo/ncm/meta.go @@ -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"` diff --git a/algo/qmc/qmc.go b/algo/qmc/qmc.go index bde250f..c4479ae 100644 --- a/algo/qmc/qmc.go +++ b/algo/qmc/qmc.go @@ -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 diff --git a/algo/tm/tm.go b/algo/tm/tm.go index 91ba0c6..907598c 100644 --- a/algo/tm/tm.go +++ b/algo/tm/tm.go @@ -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")) } diff --git a/algo/xm/xm.go b/algo/xm/xm.go index 816a594..2ae7cfc 100644 --- a/algo/xm/xm.go +++ b/algo/xm/xm.go @@ -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")) }