一些修改

pull/95/head
awalol 9 months ago
parent 2941a9ac76
commit 1c5310ffae

@ -1,18 +1,17 @@
package qmc
import (
"encoding/base64"
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
"git.unlock-music.dev/awalol/go-mmkv"
"github.com/samber/lo"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"golang.org/x/text/unicode/norm"
"unlock-music.dev/mmkv"
)
var streamKeyVault mmkv.Vault
@ -107,11 +106,7 @@ func readKeyFromMMKVCustom(mid string) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("get eKey error: %w", err)
}
n, err := base64.StdEncoding.Decode(eKey, eKey)
if err != nil {
return nil, fmt.Errorf("base64 error: %w", err)
}
return deriveKeyV1(eKey[:n])
return deriveKey(eKey)
}
func getRelativeMMKVDir(file string) (string, error) {

@ -40,8 +40,6 @@ type Decoder struct {
// provider
logger *zap.Logger
footer qqMusicTagMusicEx
}
// Read implements io.Reader, offer the decrypted audio data.
@ -147,12 +145,13 @@ func (d *Decoder) searchKey() (err error) {
case "STag":
return errors.New("qmc: file with 'STag' suffix doesn't contains media key")
case "cex\x00":
audioLen, err := d.footer.Read(d.raw)
footer := qqMusicTagMusicEx{}
audioLen, err := footer.Read(d.raw)
if err != nil {
return err
}
d.audioLen = int(audioLen)
d.decodedKey, err = readKeyFromMMKVCustom(d.footer.mediafile)
d.decodedKey, err = readKeyFromMMKVCustom(footer.mediafile)
if err != nil {
return err
}

@ -43,15 +43,17 @@ func (tag *qqMusicTagMusicEx) Read(raw io.ReadSeeker) (int64, error) {
for i := 0; i < 30; i++ {
u := binary.LittleEndian.Uint16(buf[12+i*2 : 12+(i+1)*2])
if u != 0 {
tag.mid += string(u)
if u == 0 {
break
}
tag.mid += string(u)
}
for i := 0; i < 50; i++ {
u := binary.LittleEndian.Uint16(buf[72+i*2 : 72+(i+1)*2])
if u != 0 {
tag.mediafile += string(u)
if u == 0 {
break
}
tag.mediafile += string(u)
}
tag.unknown_3 = binary.LittleEndian.Uint32(buf[173:177])

@ -50,7 +50,7 @@ func main() {
&cli.StringFlag{Name: "input", Aliases: []string{"i"}, Usage: "path to input file or dir", Required: false},
&cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "path to output dir", Required: false},
&cli.StringFlag{Name: "vault-file", Aliases: []string{"db"}, Usage: "数据库文件位置 (请确保crc文件在同目录下)", Required: false},
&cli.StringFlag{Name: "vault-key", Aliases: []string{"key"}, Usage: "数据库密钥", Required: false},
&cli.StringFlag{Name: "vault-key", Aliases: []string{"key"}, Usage: "数据库密钥 (length 32)", Required: false},
&cli.BoolFlag{Name: "remove-source", Aliases: []string{"rs"}, Usage: "remove source file", Required: false, Value: false},
&cli.BoolFlag{Name: "skip-noop", Aliases: []string{"n"}, Usage: "skip noop decoder", Required: false, Value: true},
&cli.BoolFlag{Name: "update-metadata", Usage: "update metadata & album art from network", Required: false, Value: false},
@ -83,15 +83,6 @@ func printSupportedExtensions() {
}
func appMain(c *cli.Context) (err error) {
vaultPath := c.String("vault-file")
vaultKey := c.String("vault-key")
if vaultPath != "" && vaultKey != "" {
err := qmc.OpenMMKV(vaultPath, vaultKey, logger)
if err != nil {
return err
}
}
if c.Bool("supported-ext") {
printSupportedExtensions()
return nil
@ -140,6 +131,15 @@ func appMain(c *cli.Context) (err error) {
return errors.New("output should be a writable directory")
}
vaultPath := c.String("vault-file")
vaultKey := c.String("vault-key")
if vaultPath != "" && vaultKey != "" {
err := qmc.OpenMMKV(vaultPath, vaultKey, logger)
if err != nil {
return err
}
}
proc := &processor{
outputDir: output,
skipNoopDecoder: c.Bool("skip-noop"),

@ -3,7 +3,6 @@ module unlock-music.dev/cli
go 1.19
require (
git.unlock-music.dev/awalol/go-mmkv v0.1.0
github.com/fsnotify/fsnotify v1.6.0
github.com/go-flac/flacpicture v0.2.0
github.com/go-flac/flacvorbis v0.1.0
@ -14,7 +13,7 @@ require (
golang.org/x/crypto v0.3.0
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
golang.org/x/text v0.5.0
//unlock-music.dev/mmkv v0.0.0-20221204231432-41a75bd29939
unlock-music.dev/mmkv v0.0.0-20240213204546-08c723fb2ed3
)
require (

@ -1,5 +1,3 @@
git.unlock-music.dev/awalol/go-mmkv v0.1.0 h1:Ev4buS12RNOUYd99wtE0P7CUIForghsBt0zRpaCnaSU=
git.unlock-music.dev/awalol/go-mmkv v0.1.0/go.mod h1:aM3nwVQyWkCH424GWxwU5w9JeRLUWNz7HgPxw0lWWOY=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
@ -65,3 +63,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
unlock-music.dev/mmkv v0.0.0-20240213204546-08c723fb2ed3 h1:soJr2wq4gDr+oCz81OCLJX/YjMsx9cwQGAEzvmw2yEs=
unlock-music.dev/mmkv v0.0.0-20240213204546-08c723fb2ed3/go.mod h1:1+Hdsrk8gl1i4/oxOnAhx6y51DAcUfi2CDni6Qhk8Kw=

Loading…
Cancel
Save