feat: get from url if missing album pic
This commit is contained in:
parent
b98677266a
commit
d84c082972
|
@ -46,3 +46,7 @@ func NewNeteaseCloudMusicMetadata(meta string) *NeteaseClousMusicMetadata {
|
||||||
|
|
||||||
return metaData
|
return metaData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAlbumPicUrl(meta string) string {
|
||||||
|
return gjson.Get(meta, "albumPic").String()
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue