feat: get from url if missing album pic

This commit is contained in:
TaurusXin 2024-09-14 23:18:26 +08:00
parent b98677266a
commit d84c082972
Signed by: taurusxin
GPG Key ID: C334DCA04AC2D2CC
2 changed files with 22 additions and 1 deletions

View File

@ -46,3 +46,7 @@ func NewNeteaseCloudMusicMetadata(meta string) *NeteaseClousMusicMetadata {
return metaData return metaData
} }
func GetAlbumPicUrl(meta string) string {
return gjson.Get(meta, "albumPic").String()
}

View File

@ -8,7 +8,9 @@ import (
"github.com/bogem/id3v2/v2" "github.com/bogem/id3v2/v2"
"github.com/go-flac/flacpicture" "github.com/go-flac/flacpicture"
"github.com/go-flac/go-flac" "github.com/go-flac/go-flac"
"io"
"ncmdump/utils" "ncmdump/utils"
"net/http"
"os" "os"
) )
@ -34,6 +36,7 @@ type NeteaseCloudMusic struct {
mFileStream *os.File mFileStream *os.File
mKeyBox [256]byte mKeyBox [256]byte
mMetadata *NeteaseClousMusicMetadata mMetadata *NeteaseClousMusicMetadata
mAlbumPicUrl string
} }
func (ncm *NeteaseCloudMusic) read(buffer *[]byte, size int) int { func (ncm *NeteaseCloudMusic) read(buffer *[]byte, size int) int {
@ -289,6 +292,9 @@ func NewNeteaseCloudMusic(filePath string) (*NeteaseCloudMusic, error) {
// escape `music:` // escape `music:`
mMetadataString := string(modifyDecryptData[6:]) mMetadataString := string(modifyDecryptData[6:])
// extract the album pic url
ncm.mAlbumPicUrl = GetAlbumPicUrl(mMetadataString)
ncm.mMetadata = NewNeteaseCloudMusicMetadata(mMetadataString) ncm.mMetadata = NewNeteaseCloudMusicMetadata(mMetadataString)
} }
@ -314,7 +320,18 @@ func NewNeteaseCloudMusic(filePath string) (*NeteaseCloudMusic, error) {
if coverFrameDataLen > 0 { if coverFrameDataLen > 0 {
ncm.read(&ncm.mImageData, coverFrameDataLen) ncm.read(&ncm.mImageData, coverFrameDataLen)
} else { } else {
fmt.Printf("[Warning] Missing album: '%s'\n", filePath) // get the album pic from url
resp, err := http.Get(ncm.mAlbumPicUrl)
if err != nil {
}
if resp != nil {
if resp.StatusCode == http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
}
ncm.mImageData = bodyBytes
}
}
} }
ncm.mFileStream.Seek(int64(coverFrameLenInt)-int64(coverFrameDataLen), 1) ncm.mFileStream.Seek(int64(coverFrameLenInt)-int64(coverFrameDataLen), 1)