refactor: change decoder init parameter
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
ad64a0f91d
commit
ea3236e14b
@ -6,7 +6,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type NewDecoderFunc func(rd io.ReadSeeker) Decoder
|
||||
type DecoderParams struct {
|
||||
Reader io.ReadSeeker // required
|
||||
Extension string // required, source extension, eg. ".mp3"
|
||||
|
||||
FilePath string // optional, source file path
|
||||
}
|
||||
type NewDecoderFunc func(p *DecoderParams) Decoder
|
||||
|
||||
type decoderItem struct {
|
||||
noop bool
|
||||
|
@ -14,8 +14,8 @@ type RawDecoder struct {
|
||||
audioExt string
|
||||
}
|
||||
|
||||
func NewRawDecoder(rd io.ReadSeeker) Decoder {
|
||||
return &RawDecoder{rd: rd}
|
||||
func NewRawDecoder(p *DecoderParams) Decoder {
|
||||
return &RawDecoder{rd: p.Reader}
|
||||
}
|
||||
|
||||
func (d *RawDecoder) Validate() error {
|
||||
|
@ -16,8 +16,8 @@ type Decoder struct {
|
||||
header header
|
||||
}
|
||||
|
||||
func NewDecoder(rd io.ReadSeeker) common.Decoder {
|
||||
return &Decoder{rd: rd}
|
||||
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
||||
return &Decoder{rd: p.Reader}
|
||||
}
|
||||
|
||||
// Validate checks if the file is a valid Kugou (.kgm, .vpr, .kgma) file.
|
||||
|
@ -30,8 +30,8 @@ func (d *Decoder) GetAudioExt() string {
|
||||
return "." + d.outputExt
|
||||
}
|
||||
|
||||
func NewDecoder(rd io.ReadSeeker) common.Decoder {
|
||||
return &Decoder{rd: rd}
|
||||
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
||||
return &Decoder{rd: p.Reader}
|
||||
}
|
||||
|
||||
// Validate checks if the file is a valid Kuwo .kw file.
|
||||
|
@ -29,10 +29,8 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func NewDecoder(rd io.ReadSeeker) common.Decoder {
|
||||
return &Decoder{
|
||||
rd: rd,
|
||||
}
|
||||
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
||||
return &Decoder{rd: p.Reader}
|
||||
}
|
||||
|
||||
type Decoder struct {
|
||||
|
@ -38,8 +38,8 @@ func (d *Decoder) Read(p []byte) (int, error) {
|
||||
return n, err
|
||||
}
|
||||
|
||||
func NewDecoder(r io.ReadSeeker) common.Decoder {
|
||||
return &Decoder{raw: r}
|
||||
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
||||
return &Decoder{raw: p.Reader}
|
||||
}
|
||||
|
||||
func (d *Decoder) Validate() error {
|
||||
@ -214,6 +214,8 @@ func init() {
|
||||
|
||||
"mgg", "mgg1", "mggl", //QQ Music New Ogg
|
||||
"mflac", "mflac0", //QQ Music New Flac
|
||||
|
||||
"mflach", // QQ Music Flac (storing key in dedicate MMKV)
|
||||
}
|
||||
for _, ext := range supportedExts {
|
||||
common.RegisterDecoder(ext, false, NewDecoder)
|
||||
|
@ -43,8 +43,8 @@ func (d *Decoder) Read(buf []byte) (int, error) {
|
||||
return d.audio.Read(buf)
|
||||
}
|
||||
|
||||
func NewTmDecoder(rd io.ReadSeeker) common.Decoder {
|
||||
return &Decoder{raw: rd}
|
||||
func NewTmDecoder(p *common.DecoderParams) common.Decoder {
|
||||
return &Decoder{raw: p.Reader}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -37,8 +37,8 @@ func (d *Decoder) GetAudioExt() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func NewDecoder(rd io.ReadSeeker) common.Decoder {
|
||||
return &Decoder{rd: rd}
|
||||
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
||||
return &Decoder{rd: p.Reader}
|
||||
}
|
||||
|
||||
// Validate checks if the file is a valid xiami .xm file.
|
||||
|
@ -16,8 +16,8 @@ type Decoder struct {
|
||||
audio io.Reader
|
||||
}
|
||||
|
||||
func NewDecoder(rd io.ReadSeeker) common.Decoder {
|
||||
return &Decoder{rd: rd}
|
||||
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
||||
return &Decoder{rd: p.Reader}
|
||||
}
|
||||
|
||||
func (d *Decoder) Validate() error {
|
||||
|
@ -163,9 +163,15 @@ func tryDecFile(inputFile string, outputDir string, allDec []common.NewDecoderFu
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
decParams := &common.DecoderParams{
|
||||
Reader: file,
|
||||
Extension: filepath.Ext(inputFile),
|
||||
FilePath: inputFile,
|
||||
}
|
||||
|
||||
var dec common.Decoder
|
||||
for _, decFunc := range allDec {
|
||||
dec = decFunc(file)
|
||||
dec = decFunc(decParams)
|
||||
if err := dec.Validate(); err == nil {
|
||||
break
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user