feat(qmc): add support for .mflach #46

Merged
um-dev merged 9 commits from qmc/mflach into master 2022-12-05 02:03:42 +00:00
10 changed files with 32 additions and 20 deletions
Showing only changes of commit ea3236e14b - Show all commits

View File

@ -6,7 +6,13 @@ import (
"strings" "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 { type decoderItem struct {
noop bool noop bool

View File

@ -14,8 +14,8 @@ type RawDecoder struct {
audioExt string audioExt string
} }
func NewRawDecoder(rd io.ReadSeeker) Decoder { func NewRawDecoder(p *DecoderParams) Decoder {
return &RawDecoder{rd: rd} return &RawDecoder{rd: p.Reader}
} }
func (d *RawDecoder) Validate() error { func (d *RawDecoder) Validate() error {

View File

@ -16,8 +16,8 @@ type Decoder struct {
header header header header
} }
func NewDecoder(rd io.ReadSeeker) common.Decoder { func NewDecoder(p *common.DecoderParams) common.Decoder {
return &Decoder{rd: rd} return &Decoder{rd: p.Reader}
} }
// Validate checks if the file is a valid Kugou (.kgm, .vpr, .kgma) file. // Validate checks if the file is a valid Kugou (.kgm, .vpr, .kgma) file.

View File

@ -30,8 +30,8 @@ func (d *Decoder) GetAudioExt() string {
return "." + d.outputExt return "." + d.outputExt
} }
func NewDecoder(rd io.ReadSeeker) common.Decoder { func NewDecoder(p *common.DecoderParams) common.Decoder {
return &Decoder{rd: rd} return &Decoder{rd: p.Reader}
} }
// Validate checks if the file is a valid Kuwo .kw file. // Validate checks if the file is a valid Kuwo .kw file.

View File

@ -29,10 +29,8 @@ var (
} }
) )
func NewDecoder(rd io.ReadSeeker) common.Decoder { func NewDecoder(p *common.DecoderParams) common.Decoder {
return &Decoder{ return &Decoder{rd: p.Reader}
rd: rd,
}
} }
type Decoder struct { type Decoder struct {

View File

@ -38,8 +38,8 @@ func (d *Decoder) Read(p []byte) (int, error) {
return n, err return n, err
} }
func NewDecoder(r io.ReadSeeker) common.Decoder { func NewDecoder(p *common.DecoderParams) common.Decoder {
return &Decoder{raw: r} return &Decoder{raw: p.Reader}
} }
func (d *Decoder) Validate() error { func (d *Decoder) Validate() error {
@ -214,6 +214,8 @@ func init() {
"mgg", "mgg1", "mggl", //QQ Music New Ogg "mgg", "mgg1", "mggl", //QQ Music New Ogg
"mflac", "mflac0", //QQ Music New Flac "mflac", "mflac0", //QQ Music New Flac
"mflach", // QQ Music Flac (storing key in dedicate MMKV)
} }
for _, ext := range supportedExts { for _, ext := range supportedExts {
common.RegisterDecoder(ext, false, NewDecoder) common.RegisterDecoder(ext, false, NewDecoder)

View File

@ -43,8 +43,8 @@ func (d *Decoder) Read(buf []byte) (int, error) {
return d.audio.Read(buf) return d.audio.Read(buf)
} }
func NewTmDecoder(rd io.ReadSeeker) common.Decoder { func NewTmDecoder(p *common.DecoderParams) common.Decoder {
return &Decoder{raw: rd} return &Decoder{raw: p.Reader}
} }
func init() { func init() {

View File

@ -37,8 +37,8 @@ func (d *Decoder) GetAudioExt() string {
return "" return ""
} }
func NewDecoder(rd io.ReadSeeker) common.Decoder { func NewDecoder(p *common.DecoderParams) common.Decoder {
return &Decoder{rd: rd} return &Decoder{rd: p.Reader}
} }
// Validate checks if the file is a valid xiami .xm file. // Validate checks if the file is a valid xiami .xm file.

View File

@ -16,8 +16,8 @@ type Decoder struct {
audio io.Reader audio io.Reader
} }
func NewDecoder(rd io.ReadSeeker) common.Decoder { func NewDecoder(p *common.DecoderParams) common.Decoder {
return &Decoder{rd: rd} return &Decoder{rd: p.Reader}
} }
func (d *Decoder) Validate() error { func (d *Decoder) Validate() error {

View File

@ -163,9 +163,15 @@ func tryDecFile(inputFile string, outputDir string, allDec []common.NewDecoderFu
} }
defer file.Close() defer file.Close()
decParams := &common.DecoderParams{
Reader: file,
Extension: filepath.Ext(inputFile),
FilePath: inputFile,
}
var dec common.Decoder var dec common.Decoder
for _, decFunc := range allDec { for _, decFunc := range allDec {
dec = decFunc(file) dec = decFunc(decParams)
if err := dec.Validate(); err == nil { if err := dec.Validate(); err == nil {
break break
} else { } else {