feat(qmc): allow retrieve metadata online

This commit is contained in:
Unlock Music Dev
2022-11-25 04:29:59 +08:00
parent f60f0b3d07
commit 112d9ab28e
3 changed files with 83 additions and 5 deletions

View File

@@ -34,8 +34,10 @@ type Decoder struct {
albumMediaID string
// cache
meta common.AudioMeta
cover []byte
meta common.AudioMeta
cover []byte
embeddedCover bool // embeddedCover is true if the cover is embedded in the file
probeBuf *bytes.Buffer // probeBuf is the buffer for sniffing metadata
// provider
logger *zap.Logger
@@ -48,6 +50,8 @@ func (d *Decoder) Read(p []byte) (int, error) {
if n > 0 {
d.cipher.Decrypt(p[:n], d.offset)
d.offset += n
_, _ = d.probeBuf.Write(p[:n]) // bytes.Buffer.Write never return error
}
return n, err
}
@@ -89,6 +93,9 @@ func (d *Decoder) Validate() error {
}
d.audio = io.LimitReader(d.raw, int64(d.audioLen))
// prepare for sniffing metadata
d.probeBuf = bytes.NewBuffer(make([]byte, 0, d.audioLen))
return nil
}