fix: incorrect metadata structure
This commit is contained in:
parent
a4c7db8195
commit
be81c22e49
1
go.mod
1
go.mod
|
@ -11,6 +11,7 @@ require github.com/bogem/id3v2/v2 v2.1.4
|
|||
require (
|
||||
github.com/TwiN/go-color v1.4.1
|
||||
github.com/go-flac/flacpicture v0.3.0
|
||||
github.com/go-flac/flacvorbis v0.2.0
|
||||
github.com/go-flac/go-flac v1.0.0
|
||||
)
|
||||
|
||||
|
|
2
go.sum
2
go.sum
|
@ -4,6 +4,8 @@ github.com/bogem/id3v2/v2 v2.1.4 h1:CEwe+lS2p6dd9UZRlPc1zbFNIha2mb2qzT1cCEoNWoI=
|
|||
github.com/bogem/id3v2/v2 v2.1.4/go.mod h1:l+gR8MZ6rc9ryPTPkX77smS5Me/36gxkMgDayZ9G1vY=
|
||||
github.com/go-flac/flacpicture v0.3.0 h1:LkmTxzFLIynwfhHiZsX0s8xcr3/u33MzvV89u+zOT8I=
|
||||
github.com/go-flac/flacpicture v0.3.0/go.mod h1:DPbrzVYQ3fJcvSgLFp9HXIrEQEdfdk/+m0nQCzwodZI=
|
||||
github.com/go-flac/flacvorbis v0.2.0 h1:KH0xjpkNTXFER4cszH4zeJxYcrHbUobz/RticWGOESs=
|
||||
github.com/go-flac/flacvorbis v0.2.0/go.mod h1:uIysHOtuU7OLGoCRG92bvnkg7QEqHx19qKRV6K1pBrI=
|
||||
github.com/go-flac/go-flac v1.0.0 h1:6qI9XOVLcO50xpzm3nXvO31BgDgHhnr/p/rER/K/doY=
|
||||
github.com/go-flac/go-flac v1.0.0/go.mod h1:WnZhcpmq4u1UdZMNn9LYSoASpWOCMOoxXxcWEHSzkW8=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/bogem/id3v2/v2"
|
||||
"github.com/go-flac/flacpicture"
|
||||
"github.com/go-flac/flacvorbis"
|
||||
"github.com/go-flac/go-flac"
|
||||
"github.com/taurusxin/ncmdump-go/utils"
|
||||
"io"
|
||||
|
@ -217,12 +218,36 @@ func (ncm *NeteaseCloudMusic) FixMetadata(fetchAlbumImageFromRemote bool) (bool,
|
|||
pictureMeta := pic.Marshal()
|
||||
audioFile.Meta = append(audioFile.Meta, &pictureMeta)
|
||||
}
|
||||
generalMeta := &flac.MetaDataBlock{
|
||||
Type: flac.VorbisComment,
|
||||
Data: []byte(fmt.Sprintf("title=%s\nartist=%s\nalbum=%s", ncm.mMetadata.mName, ncm.mMetadata.mArtist, ncm.mMetadata.mAlbum)),
|
||||
|
||||
var cmts *flacvorbis.MetaDataBlockVorbisComment
|
||||
var cmtIdx int
|
||||
for idx, meta := range audioFile.Meta {
|
||||
if meta.Type == flac.VorbisComment {
|
||||
cmts, err = flacvorbis.ParseFromMetaDataBlock(*meta)
|
||||
cmtIdx = idx
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
}
|
||||
audioFile.Meta = append(audioFile.Meta, generalMeta)
|
||||
if cmts == nil && cmtIdx > 0 {
|
||||
cmts = flacvorbis.New()
|
||||
}
|
||||
|
||||
_ = cmts.Add(flacvorbis.FIELD_TITLE, ncm.mMetadata.mName)
|
||||
_ = cmts.Add(flacvorbis.FIELD_ARTIST, ncm.mMetadata.mArtist)
|
||||
_ = cmts.Add(flacvorbis.FIELD_ALBUM, ncm.mMetadata.mAlbum)
|
||||
|
||||
cmtsmeta := cmts.Marshal()
|
||||
|
||||
if cmtIdx > 0 {
|
||||
audioFile.Meta[cmtIdx] = &cmtsmeta
|
||||
} else {
|
||||
audioFile.Meta = append(audioFile.Meta, &cmtsmeta)
|
||||
}
|
||||
|
||||
err = audioFile.Save(ncm.mDumpFilePath)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue