mirror of
https://git.um-react.app/um/cli.git
synced 2025-11-28 11:43:02 +00:00
Compare commits
79 Commits
v0.2.0-bet
...
v0.2.12
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61fba401c7 | ||
|
|
a968be6063 | ||
|
|
000ef4ac13 | ||
|
|
05e5783336 | ||
|
|
006bad8c48 | ||
|
|
380ed78b6b | ||
|
|
208aceb1b5 | ||
|
|
28ca8cef60 | ||
|
|
2b0bd2985e | ||
|
|
72ace9fc62 | ||
|
|
074e4f874f | ||
|
|
2bfb5ffddf | ||
|
|
2c9de7c56c | ||
|
|
b374c11c86 | ||
|
|
6493b2c5fc | ||
|
|
f753b9c67d | ||
|
|
8829a3b3ba | ||
|
|
b2ef27761f | ||
|
|
7f7cb66fe5 | ||
|
|
77729cf653 | ||
|
|
b317b89ae9 | ||
|
|
89b629304e | ||
|
|
c0c3bda9ce | ||
|
|
fa8f7a1565 | ||
|
|
d4d5e5ddf4 | ||
|
|
57c1aa3e54 | ||
|
|
b0998d8c8a | ||
|
|
f819726f3e | ||
|
|
fbad7ec450 | ||
|
|
19bc6c466e | ||
|
|
b9e2a38f82 | ||
|
|
673ea8491f | ||
|
|
0d071a82be | ||
|
|
b8e6196248 | ||
|
|
1323fb9e1a | ||
|
|
36df203bdd | ||
|
|
2afc232eb1 | ||
|
|
2abdd47c9c | ||
|
|
8b59bc026d | ||
|
|
91855f8f5b | ||
|
|
7edd326b95 | ||
|
|
0b3ad0d97c | ||
|
|
c87204c78a | ||
|
|
3630fc0c78 | ||
|
|
b3f7cd33df | ||
|
|
c6fa777db1 | ||
|
|
cab705a130 | ||
|
|
f258e3e8f2 | ||
|
|
59f3759d48 | ||
|
|
db547002f9 | ||
|
|
05a1affa03 | ||
|
|
68e0c06246 | ||
|
|
e010d1b308 | ||
|
|
9b4e3b87ef | ||
|
|
1ccc507f61 | ||
|
|
119a8cf380 | ||
|
|
6179bcf0c7 | ||
|
|
c9ed772ce0 | ||
|
|
9c0acb794e | ||
|
|
bda32bc53e | ||
|
|
3f6566f7a9 | ||
|
|
1c5310ffae | ||
|
|
2941a9ac76 | ||
|
|
1835f9852a | ||
|
|
4f4d8db3d5 | ||
|
|
877f37f01e | ||
|
|
7b12f61a97 | ||
|
|
f6bc911125 | ||
|
|
9ddbd5f702 | ||
|
|
d480c9a2f8 | ||
|
|
907fe4143b | ||
|
|
4ad9a721f0 | ||
|
|
1bbc707dcc | ||
|
|
dfbb807e41 | ||
|
|
a928611a8d | ||
|
|
2754c14fa6 | ||
|
|
8858ff37ad | ||
|
|
d0d9836990 | ||
|
|
1a508fc2b6 |
@@ -8,7 +8,10 @@ local CreateRelease() = {
|
|||||||
settings: {
|
settings: {
|
||||||
api_key: { from_secret: 'GITEA_API_KEY' },
|
api_key: { from_secret: 'GITEA_API_KEY' },
|
||||||
base_url: 'https://git.unlock-music.dev',
|
base_url: 'https://git.unlock-music.dev',
|
||||||
files: 'dist/*',
|
files: [
|
||||||
|
'um-*.tar.gz',
|
||||||
|
'um-*.zip',
|
||||||
|
],
|
||||||
checksum: 'sha256',
|
checksum: 'sha256',
|
||||||
draft: true,
|
draft: true,
|
||||||
title: '${DRONE_TAG}',
|
title: '${DRONE_TAG}',
|
||||||
@@ -17,29 +20,41 @@ local CreateRelease() = {
|
|||||||
|
|
||||||
|
|
||||||
local StepGoBuild(GOOS, GOARCH) = {
|
local StepGoBuild(GOOS, GOARCH) = {
|
||||||
local filepath = 'dist/um-%s-%s.tar.gz' % [GOOS, GOARCH],
|
local windows = GOOS == 'windows',
|
||||||
|
local archiveExt = if windows then 'zip' else 'tar.gz',
|
||||||
|
local filepath = 'dist/um-%s-%s-%s.%s' % [GOOS, GOARCH, '$(git describe --tags --always)', archiveExt],
|
||||||
|
|
||||||
|
local archive = if windows then [
|
||||||
|
// Ensure zip is installed
|
||||||
|
'command -v zip >/dev/null || (apt update && apt install -y zip)',
|
||||||
|
'zip -9 -j -r "%s" $DIST_DIR' % filepath,
|
||||||
|
] else [
|
||||||
|
'tar -c -C $DIST_DIR um | gzip -9 > "%s"' % filepath,
|
||||||
|
],
|
||||||
|
|
||||||
name: 'go build %s/%s' % [GOOS, GOARCH],
|
name: 'go build %s/%s' % [GOOS, GOARCH],
|
||||||
image: 'golang:1.19',
|
image: 'golang:1.23',
|
||||||
environment: {
|
environment: {
|
||||||
GOOS: GOOS,
|
GOOS: GOOS,
|
||||||
GOARCH: GOARCH,
|
GOARCH: GOARCH,
|
||||||
|
GOPROXY: 'https://goproxy.io,direct',
|
||||||
},
|
},
|
||||||
commands: [
|
commands: [
|
||||||
'DIST_DIR=$(mktemp -d)',
|
'DIST_DIR=$(mktemp -d)',
|
||||||
'go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um',
|
'go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um',
|
||||||
'mkdir -p dist',
|
'mkdir -p dist',
|
||||||
'tar cz -f %s -C $DIST_DIR .' % filepath,
|
] + archive,
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
local StepUploadArtifact(GOOS, GOARCH) = {
|
local StepUploadArtifact(GOOS, GOARCH) = {
|
||||||
local filename = 'um-%s-%s.tar.gz' % [GOOS, GOARCH],
|
local windows = GOOS == 'windows',
|
||||||
|
local archiveExt = if windows then 'zip' else 'tar.gz',
|
||||||
|
local filename = 'um-%s-%s-%s.%s' % [GOOS, GOARCH, '$(git describe --tags --always)', archiveExt],
|
||||||
local filepath = 'dist/%s' % filename,
|
local filepath = 'dist/%s' % filename,
|
||||||
local pkgname = '${DRONE_REPO_NAME}-build',
|
local pkgname = '${DRONE_REPO_NAME}-build',
|
||||||
|
|
||||||
name: 'upload artifact',
|
name: 'upload artifact',
|
||||||
image: 'golang:1.19', // reuse golang:1.19 for curl
|
image: 'golang:1.23', // reuse golang:1.19 for curl
|
||||||
environment: {
|
environment: {
|
||||||
DRONE_GITEA_SERVER: 'https://git.unlock-music.dev',
|
DRONE_GITEA_SERVER: 'https://git.unlock-music.dev',
|
||||||
GITEA_API_KEY: { from_secret: 'GITEA_API_KEY' },
|
GITEA_API_KEY: { from_secret: 'GITEA_API_KEY' },
|
||||||
@@ -68,7 +83,10 @@ local PipelineBuild(GOOS, GOARCH, RUN_TEST) = {
|
|||||||
(
|
(
|
||||||
if RUN_TEST then [{
|
if RUN_TEST then [{
|
||||||
name: 'go test',
|
name: 'go test',
|
||||||
image: 'golang:1.19',
|
image: 'golang:1.23',
|
||||||
|
environment: {
|
||||||
|
GOPROXY: 'https://goproxy.io,direct',
|
||||||
|
},
|
||||||
commands: ['go test -v ./...'],
|
commands: ['go test -v ./...'],
|
||||||
}] else []
|
}] else []
|
||||||
)
|
)
|
||||||
@@ -94,16 +112,27 @@ local PipelineRelease() = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'go test',
|
name: 'go test',
|
||||||
image: 'golang:1.19',
|
image: 'golang:1.23',
|
||||||
|
environment: {
|
||||||
|
GOPROXY: 'https://goproxy.io,direct',
|
||||||
|
},
|
||||||
commands: ['go test -v ./...'],
|
commands: ['go test -v ./...'],
|
||||||
},
|
},
|
||||||
StepGoBuild('linux', 'amd64'),
|
StepGoBuild('linux', 'amd64'),
|
||||||
StepGoBuild('linux', 'arm64'),
|
StepGoBuild('linux', 'arm64'),
|
||||||
StepGoBuild('linux', '386'),
|
StepGoBuild('linux', '386'),
|
||||||
StepGoBuild('windows', 'amd64'),
|
StepGoBuild('windows', 'amd64'),
|
||||||
|
StepGoBuild('windows', 'arm64'),
|
||||||
StepGoBuild('windows', '386'),
|
StepGoBuild('windows', '386'),
|
||||||
StepGoBuild('darwin', 'amd64'),
|
StepGoBuild('darwin', 'amd64'),
|
||||||
StepGoBuild('darwin', 'arm64'),
|
StepGoBuild('darwin', 'arm64'),
|
||||||
|
{
|
||||||
|
name: 'prepare root',
|
||||||
|
image: 'golang:1.23',
|
||||||
|
commands: [
|
||||||
|
'mv dist/*.tar.gz dist/*.zip ./',
|
||||||
|
],
|
||||||
|
},
|
||||||
CreateRelease(),
|
CreateRelease(),
|
||||||
],
|
],
|
||||||
trigger: {
|
trigger: {
|
||||||
|
|||||||
115
.drone.yml
115
.drone.yml
@@ -8,29 +8,34 @@ steps:
|
|||||||
name: fetch tags
|
name: fetch tags
|
||||||
- commands:
|
- commands:
|
||||||
- go test -v ./...
|
- go test -v ./...
|
||||||
image: golang:1.19
|
environment:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go test
|
name: go test
|
||||||
- commands:
|
- commands:
|
||||||
- DIST_DIR=$(mktemp -d)
|
- DIST_DIR=$(mktemp -d)
|
||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-linux-amd64.tar.gz -C $DIST_DIR .
|
- tar -c -C $DIST_DIR um | gzip -9 > "dist/um-linux-amd64-$(git describe --tags
|
||||||
|
--always).tar.gz"
|
||||||
environment:
|
environment:
|
||||||
GOARCH: amd64
|
GOARCH: amd64
|
||||||
GOOS: linux
|
GOOS: linux
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build linux/amd64
|
name: go build linux/amd64
|
||||||
- commands:
|
- commands:
|
||||||
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-linux-amd64.tar.gz"
|
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-linux-amd64-$(git
|
||||||
"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-linux-amd64.tar.gz"
|
describe --tags --always).tar.gz" "$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-linux-amd64-$(git
|
||||||
- sha256sum dist/um-linux-amd64.tar.gz
|
describe --tags --always).tar.gz"
|
||||||
|
- sha256sum dist/um-linux-amd64-$(git describe --tags --always).tar.gz
|
||||||
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
|
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
|
||||||
environment:
|
environment:
|
||||||
DRONE_GITEA_SERVER: https://git.unlock-music.dev
|
DRONE_GITEA_SERVER: https://git.unlock-music.dev
|
||||||
GITEA_API_KEY:
|
GITEA_API_KEY:
|
||||||
from_secret: GITEA_API_KEY
|
from_secret: GITEA_API_KEY
|
||||||
image: golang:1.19
|
image: golang:1.23
|
||||||
name: upload artifact
|
name: upload artifact
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
@@ -50,22 +55,25 @@ steps:
|
|||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-windows-amd64.tar.gz -C $DIST_DIR .
|
- command -v zip >/dev/null || (apt update && apt install -y zip)
|
||||||
|
- zip -9 -j -r "dist/um-windows-amd64-$(git describe --tags --always).zip" $DIST_DIR
|
||||||
environment:
|
environment:
|
||||||
GOARCH: amd64
|
GOARCH: amd64
|
||||||
GOOS: windows
|
GOOS: windows
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build windows/amd64
|
name: go build windows/amd64
|
||||||
- commands:
|
- commands:
|
||||||
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-windows-amd64.tar.gz"
|
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-windows-amd64-$(git
|
||||||
"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-windows-amd64.tar.gz"
|
describe --tags --always).zip" "$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-windows-amd64-$(git
|
||||||
- sha256sum dist/um-windows-amd64.tar.gz
|
describe --tags --always).zip"
|
||||||
|
- sha256sum dist/um-windows-amd64-$(git describe --tags --always).zip
|
||||||
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
|
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
|
||||||
environment:
|
environment:
|
||||||
DRONE_GITEA_SERVER: https://git.unlock-music.dev
|
DRONE_GITEA_SERVER: https://git.unlock-music.dev
|
||||||
GITEA_API_KEY:
|
GITEA_API_KEY:
|
||||||
from_secret: GITEA_API_KEY
|
from_secret: GITEA_API_KEY
|
||||||
image: golang:1.19
|
image: golang:1.23
|
||||||
name: upload artifact
|
name: upload artifact
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
@@ -85,22 +93,25 @@ steps:
|
|||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-darwin-amd64.tar.gz -C $DIST_DIR .
|
- tar -c -C $DIST_DIR um | gzip -9 > "dist/um-darwin-amd64-$(git describe --tags
|
||||||
|
--always).tar.gz"
|
||||||
environment:
|
environment:
|
||||||
GOARCH: amd64
|
GOARCH: amd64
|
||||||
GOOS: darwin
|
GOOS: darwin
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build darwin/amd64
|
name: go build darwin/amd64
|
||||||
- commands:
|
- commands:
|
||||||
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-darwin-amd64.tar.gz"
|
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-darwin-amd64-$(git
|
||||||
"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-darwin-amd64.tar.gz"
|
describe --tags --always).tar.gz" "$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-darwin-amd64-$(git
|
||||||
- sha256sum dist/um-darwin-amd64.tar.gz
|
describe --tags --always).tar.gz"
|
||||||
|
- sha256sum dist/um-darwin-amd64-$(git describe --tags --always).tar.gz
|
||||||
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
|
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
|
||||||
environment:
|
environment:
|
||||||
DRONE_GITEA_SERVER: https://git.unlock-music.dev
|
DRONE_GITEA_SERVER: https://git.unlock-music.dev
|
||||||
GITEA_API_KEY:
|
GITEA_API_KEY:
|
||||||
from_secret: GITEA_API_KEY
|
from_secret: GITEA_API_KEY
|
||||||
image: golang:1.19
|
image: golang:1.23
|
||||||
name: upload artifact
|
name: upload artifact
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
@@ -117,85 +128,117 @@ steps:
|
|||||||
name: fetch tags
|
name: fetch tags
|
||||||
- commands:
|
- commands:
|
||||||
- go test -v ./...
|
- go test -v ./...
|
||||||
image: golang:1.19
|
environment:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go test
|
name: go test
|
||||||
- commands:
|
- commands:
|
||||||
- DIST_DIR=$(mktemp -d)
|
- DIST_DIR=$(mktemp -d)
|
||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-linux-amd64.tar.gz -C $DIST_DIR .
|
- tar -c -C $DIST_DIR um | gzip -9 > "dist/um-linux-amd64-$(git describe --tags
|
||||||
|
--always).tar.gz"
|
||||||
environment:
|
environment:
|
||||||
GOARCH: amd64
|
GOARCH: amd64
|
||||||
GOOS: linux
|
GOOS: linux
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build linux/amd64
|
name: go build linux/amd64
|
||||||
- commands:
|
- commands:
|
||||||
- DIST_DIR=$(mktemp -d)
|
- DIST_DIR=$(mktemp -d)
|
||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-linux-arm64.tar.gz -C $DIST_DIR .
|
- tar -c -C $DIST_DIR um | gzip -9 > "dist/um-linux-arm64-$(git describe --tags
|
||||||
|
--always).tar.gz"
|
||||||
environment:
|
environment:
|
||||||
GOARCH: arm64
|
GOARCH: arm64
|
||||||
GOOS: linux
|
GOOS: linux
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build linux/arm64
|
name: go build linux/arm64
|
||||||
- commands:
|
- commands:
|
||||||
- DIST_DIR=$(mktemp -d)
|
- DIST_DIR=$(mktemp -d)
|
||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-linux-386.tar.gz -C $DIST_DIR .
|
- tar -c -C $DIST_DIR um | gzip -9 > "dist/um-linux-386-$(git describe --tags --always).tar.gz"
|
||||||
environment:
|
environment:
|
||||||
GOARCH: "386"
|
GOARCH: "386"
|
||||||
GOOS: linux
|
GOOS: linux
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build linux/386
|
name: go build linux/386
|
||||||
- commands:
|
- commands:
|
||||||
- DIST_DIR=$(mktemp -d)
|
- DIST_DIR=$(mktemp -d)
|
||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-windows-amd64.tar.gz -C $DIST_DIR .
|
- command -v zip >/dev/null || (apt update && apt install -y zip)
|
||||||
|
- zip -9 -j -r "dist/um-windows-amd64-$(git describe --tags --always).zip" $DIST_DIR
|
||||||
environment:
|
environment:
|
||||||
GOARCH: amd64
|
GOARCH: amd64
|
||||||
GOOS: windows
|
GOOS: windows
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build windows/amd64
|
name: go build windows/amd64
|
||||||
- commands:
|
- commands:
|
||||||
- DIST_DIR=$(mktemp -d)
|
- DIST_DIR=$(mktemp -d)
|
||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-windows-386.tar.gz -C $DIST_DIR .
|
- command -v zip >/dev/null || (apt update && apt install -y zip)
|
||||||
|
- zip -9 -j -r "dist/um-windows-arm64-$(git describe --tags --always).zip" $DIST_DIR
|
||||||
|
environment:
|
||||||
|
GOARCH: arm64
|
||||||
|
GOOS: windows
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
|
name: go build windows/arm64
|
||||||
|
- commands:
|
||||||
|
- DIST_DIR=$(mktemp -d)
|
||||||
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
|
- mkdir -p dist
|
||||||
|
- command -v zip >/dev/null || (apt update && apt install -y zip)
|
||||||
|
- zip -9 -j -r "dist/um-windows-386-$(git describe --tags --always).zip" $DIST_DIR
|
||||||
environment:
|
environment:
|
||||||
GOARCH: "386"
|
GOARCH: "386"
|
||||||
GOOS: windows
|
GOOS: windows
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build windows/386
|
name: go build windows/386
|
||||||
- commands:
|
- commands:
|
||||||
- DIST_DIR=$(mktemp -d)
|
- DIST_DIR=$(mktemp -d)
|
||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-darwin-amd64.tar.gz -C $DIST_DIR .
|
- tar -c -C $DIST_DIR um | gzip -9 > "dist/um-darwin-amd64-$(git describe --tags
|
||||||
|
--always).tar.gz"
|
||||||
environment:
|
environment:
|
||||||
GOARCH: amd64
|
GOARCH: amd64
|
||||||
GOOS: darwin
|
GOOS: darwin
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build darwin/amd64
|
name: go build darwin/amd64
|
||||||
- commands:
|
- commands:
|
||||||
- DIST_DIR=$(mktemp -d)
|
- DIST_DIR=$(mktemp -d)
|
||||||
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
|
||||||
--always)" -o $DIST_DIR ./cmd/um
|
--always)" -o $DIST_DIR ./cmd/um
|
||||||
- mkdir -p dist
|
- mkdir -p dist
|
||||||
- tar cz -f dist/um-darwin-arm64.tar.gz -C $DIST_DIR .
|
- tar -c -C $DIST_DIR um | gzip -9 > "dist/um-darwin-arm64-$(git describe --tags
|
||||||
|
--always).tar.gz"
|
||||||
environment:
|
environment:
|
||||||
GOARCH: arm64
|
GOARCH: arm64
|
||||||
GOOS: darwin
|
GOOS: darwin
|
||||||
image: golang:1.19
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
image: golang:1.23
|
||||||
name: go build darwin/arm64
|
name: go build darwin/arm64
|
||||||
|
- commands:
|
||||||
|
- mv dist/*.tar.gz dist/*.zip ./
|
||||||
|
image: golang:1.23
|
||||||
|
name: prepare root
|
||||||
- image: plugins/gitea-release
|
- image: plugins/gitea-release
|
||||||
name: create release
|
name: create release
|
||||||
settings:
|
settings:
|
||||||
@@ -204,7 +247,9 @@ steps:
|
|||||||
base_url: https://git.unlock-music.dev
|
base_url: https://git.unlock-music.dev
|
||||||
checksum: sha256
|
checksum: sha256
|
||||||
draft: true
|
draft: true
|
||||||
files: dist/*
|
files:
|
||||||
|
- um-*.tar.gz
|
||||||
|
- um-*.zip
|
||||||
title: ${DRONE_TAG}
|
title: ${DRONE_TAG}
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
|
|||||||
108
.gitea/workflows/build.yml
Normal file
108
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
name: Build
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- "**/*.go"
|
||||||
|
- "go.mod"
|
||||||
|
- "go.sum"
|
||||||
|
- ".gitea/workflows/*.yml"
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
types: [ opened, synchronize, reopened ]
|
||||||
|
paths:
|
||||||
|
- "**/*.go"
|
||||||
|
- "go.mod"
|
||||||
|
- "go.sum"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
GOOS:
|
||||||
|
- linux
|
||||||
|
- windows
|
||||||
|
- darwin
|
||||||
|
GOARCH:
|
||||||
|
- "amd64"
|
||||||
|
- "386"
|
||||||
|
- "arm64"
|
||||||
|
|
||||||
|
exclude:
|
||||||
|
- GOOS: darwin
|
||||||
|
GOARCH: "386"
|
||||||
|
|
||||||
|
include:
|
||||||
|
- GOOS: windows
|
||||||
|
BIN_SUFFIX: ".exe"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout codebase
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Go 1.23
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: ^1.23
|
||||||
|
|
||||||
|
- name: Setup vars
|
||||||
|
id: vars
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
||||||
|
echo "::set-output name=git_tag::$(git describe --tags --always)"
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test -v ./...
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
env:
|
||||||
|
GOOS: ${{ matrix.GOOS }}
|
||||||
|
GOARCH: ${{ matrix.GOARCH }}
|
||||||
|
CGO_ENABLED: 0
|
||||||
|
run: go build -v -trimpath -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -o um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }} ./cmd/um
|
||||||
|
|
||||||
|
- name: Publish artifact
|
||||||
|
uses: christopherhx/gitea-upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
|
||||||
|
path: ./um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }}
|
||||||
|
|
||||||
|
archive:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- name: prepare archive
|
||||||
|
run: |
|
||||||
|
mkdir -p dist prepare
|
||||||
|
- name: Download artifacts
|
||||||
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: prepare
|
||||||
|
pattern: um-*
|
||||||
|
- name: prepare archive
|
||||||
|
run: |
|
||||||
|
for exe in prepare/*/um-*.exe; do
|
||||||
|
zip -9 -j "dist/$(basename "$exe" .exe).zip" "$exe"
|
||||||
|
rm -f "$exe"
|
||||||
|
done
|
||||||
|
for exe in prepare/*/um-*; do
|
||||||
|
tar \
|
||||||
|
--sort=name --format=posix \
|
||||||
|
--pax-option=exthdr.name=%d/PaxHeaders/%f \
|
||||||
|
--pax-option=delete=atime,delete=ctime \
|
||||||
|
--clamp-mtime --mtime='1970-01-01T00:00:00Z' \
|
||||||
|
--numeric-owner --owner=0 --group=0 \
|
||||||
|
--mode=0755 \
|
||||||
|
-cv \
|
||||||
|
-C "$(dirname "$exe")" \
|
||||||
|
"$(basename "$exe")" \
|
||||||
|
| gzip -9 > "dist/$(basename "$exe").tar.gz"
|
||||||
|
rm -f "$exe"
|
||||||
|
done
|
||||||
|
- name: Publish all-in-one archive
|
||||||
|
uses: christopherhx/gitea-upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: dist-all
|
||||||
|
path: dist
|
||||||
67
.github/workflows/build.yml
vendored
67
.github/workflows/build.yml
vendored
@@ -1,67 +0,0 @@
|
|||||||
name: Build
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
paths:
|
|
||||||
- "**/*.go"
|
|
||||||
- "go.mod"
|
|
||||||
- "go.sum"
|
|
||||||
- ".github/workflows/*.yml"
|
|
||||||
pull_request:
|
|
||||||
branches: [ master ]
|
|
||||||
types: [ opened, synchronize, reopened ]
|
|
||||||
paths:
|
|
||||||
- "**/*.go"
|
|
||||||
- "go.mod"
|
|
||||||
- "go.sum"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- target: "linux/amd64"
|
|
||||||
GOOS: "linux"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
BIN_SUFFIX: ""
|
|
||||||
- target: "windows/amd64"
|
|
||||||
GOOS: "windows"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
BIN_SUFFIX: ".exe"
|
|
||||||
- target: "darwin/amd64"
|
|
||||||
GOOS: "darwin"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
BIN_SUFFIX: ""
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout codebase
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up Go 1.x
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: ^1.17
|
|
||||||
|
|
||||||
- name: Setup vars
|
|
||||||
id: vars
|
|
||||||
run: |
|
|
||||||
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
|
||||||
echo "::set-output name=git_tag::$(git describe --tags --always)"
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: go test -v ./...
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
env:
|
|
||||||
GOOS: ${{ matrix.GOOS }}
|
|
||||||
GOARCH: ${{ matrix.GOARCH }}
|
|
||||||
CGO_ENABLED: 0
|
|
||||||
run: go build -v -trimpath -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -o um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }} ./cmd/um
|
|
||||||
|
|
||||||
- name: Publish artifact
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
|
|
||||||
path: ./um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }}
|
|
||||||
84
.github/workflows/release.yml
vendored
84
.github/workflows/release.yml
vendored
@@ -1,84 +0,0 @@
|
|||||||
name: Create Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- "v*"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
create_release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Get current time
|
|
||||||
id: date
|
|
||||||
run: echo "::set-output name=date::$(date +'%Y/%m/%d')"
|
|
||||||
|
|
||||||
- name: Create release
|
|
||||||
id: release
|
|
||||||
uses: actions/create-release@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
tag_name: ${{ github.ref }}
|
|
||||||
release_name: "Build ${{ steps.date.outputs.date }}"
|
|
||||||
draft: true
|
|
||||||
outputs:
|
|
||||||
upload_url: "${{ steps.release.outputs.upload_url }}"
|
|
||||||
build:
|
|
||||||
needs:
|
|
||||||
- create_release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- target: "linux/amd64"
|
|
||||||
GOOS: "linux"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
BIN_SUFFIX: ""
|
|
||||||
- target: "windows/amd64"
|
|
||||||
GOOS: "windows"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
BIN_SUFFIX: ".exe"
|
|
||||||
- target: "windows/386"
|
|
||||||
GOOS: "windows"
|
|
||||||
GOARCH: "386"
|
|
||||||
BIN_SUFFIX: ".exe"
|
|
||||||
- target: "darwin/amd64"
|
|
||||||
GOOS: "darwin"
|
|
||||||
GOARCH: "amd64"
|
|
||||||
BIN_SUFFIX: ""
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout codebase
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Setup vars
|
|
||||||
id: vars
|
|
||||||
run: |
|
|
||||||
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
|
||||||
echo "::set-output name=git_tag::$(git describe --tags --always)"
|
|
||||||
|
|
||||||
- name: Set up Go 1.x
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: ^1.17
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
env:
|
|
||||||
GOOS: ${{ matrix.GOOS }}
|
|
||||||
GOARCH: ${{ matrix.GOARCH }}
|
|
||||||
CGO_ENABLED: 0
|
|
||||||
run: go build -trimpath -v -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -o um ./cmd/um
|
|
||||||
|
|
||||||
- name: Upload release assets
|
|
||||||
uses: actions/upload-release-asset@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
upload_url: ${{ needs.create_release.outputs.upload_url }}
|
|
||||||
asset_path: um
|
|
||||||
asset_name: um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }}
|
|
||||||
asset_content_type: application/octet-stream
|
|
||||||
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,3 +1,9 @@
|
|||||||
.idea
|
.idea
|
||||||
|
|
||||||
/dist
|
/dist
|
||||||
|
*.exe
|
||||||
|
|
||||||
|
/um
|
||||||
|
/um-*.tar.gz
|
||||||
|
/um-*.zip
|
||||||
|
/.vscode
|
||||||
|
|||||||
32
README.md
32
README.md
@@ -6,21 +6,43 @@ Original: Web Edition https://git.unlock-music.dev/um/web
|
|||||||
- [Release Download](https://git.unlock-music.dev/um/cli/releases/latest)
|
- [Release Download](https://git.unlock-music.dev/um/cli/releases/latest)
|
||||||
- [Latest Build](https://git.unlock-music.dev/um/-/packages/generic/cli-build/)
|
- [Latest Build](https://git.unlock-music.dev/um/-/packages/generic/cli-build/)
|
||||||
|
|
||||||
|
> **WARNING**
|
||||||
|
> 在本站 fork 不会起到备份的作用,只会浪费服务器储存空间。如无必要请勿 fork 该仓库。
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- [x] All Algorithm Supported By `unlock-music/web`
|
- [x] All Algorithm Supported By `unlock-music/web`
|
||||||
- [ ] Complete Cover Image
|
- [x] Complete Metadata & Cover Image
|
||||||
- [ ] Parse Meta Data
|
|
||||||
- [ ] Complete Meta Data
|
|
||||||
|
|
||||||
## Hou to Build
|
## Release
|
||||||
|
|
||||||
- Requirements: **Golang 1.17**
|
[Latest release](https://git.unlock-music.dev/um/cli/releases/latest).
|
||||||
|
|
||||||
|
## Install from source
|
||||||
|
|
||||||
|
- Requirements: **Golang 1.23.3**
|
||||||
|
|
||||||
1. run `go install unlock-music.dev/cli/cmd/um@master`
|
1. run `go install unlock-music.dev/cli/cmd/um@master`
|
||||||
|
|
||||||
|
### Build from repo source
|
||||||
|
|
||||||
|
1. Pull repo source.
|
||||||
|
2. Build with `go build ./cmd/um`.
|
||||||
|
|
||||||
|
It will produce `um` or `um.exe` (Windows).
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
- Drag the encrypted file to `um.exe` (Tested on Windows)
|
- Drag the encrypted file to `um.exe` (Tested on Windows)
|
||||||
- Run: `./um [-o <output dir>] [-i] <input dir/file>`
|
- Run: `./um [-o <output dir>] [-i] <input dir/file>`
|
||||||
- Use `./um -h` to show help menu
|
- Use `./um -h` to show help menu
|
||||||
|
|
||||||
|
## Update CI pipeline
|
||||||
|
|
||||||
|
1. Install [Drone CI binary](https://docs.drone.io/cli/install/)
|
||||||
|
2. Edit `.drone.jsonnet`
|
||||||
|
3. Update drone CI pipeline:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
drone jsonnet --format --stream
|
||||||
|
```
|
||||||
|
|||||||
@@ -15,28 +15,38 @@ type DecoderParams struct {
|
|||||||
FilePath string // optional, source file path
|
FilePath string // optional, source file path
|
||||||
|
|
||||||
Logger *zap.Logger // required
|
Logger *zap.Logger // required
|
||||||
|
|
||||||
|
// KuGou
|
||||||
|
KggDatabasePath string
|
||||||
}
|
}
|
||||||
type NewDecoderFunc func(p *DecoderParams) Decoder
|
type NewDecoderFunc func(p *DecoderParams) Decoder
|
||||||
|
|
||||||
type decoderItem struct {
|
type DecoderFactory struct {
|
||||||
noop bool
|
noop bool
|
||||||
decoder NewDecoderFunc
|
Suffix string
|
||||||
|
Create NewDecoderFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
var DecoderRegistry = make(map[string][]decoderItem)
|
var DecoderRegistry []DecoderFactory
|
||||||
|
|
||||||
func RegisterDecoder(ext string, noop bool, dispatchFunc NewDecoderFunc) {
|
func RegisterDecoder(ext string, noop bool, dispatchFunc NewDecoderFunc) {
|
||||||
DecoderRegistry[ext] = append(DecoderRegistry[ext],
|
DecoderRegistry = append(DecoderRegistry,
|
||||||
decoderItem{noop: noop, decoder: dispatchFunc})
|
DecoderFactory{noop: noop, Create: dispatchFunc, Suffix: "." + strings.TrimPrefix(ext, ".")})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDecoder(filename string, skipNoop bool) (rs []NewDecoderFunc) {
|
func GetDecoder(filename string, skipNoop bool) []DecoderFactory {
|
||||||
ext := strings.ToLower(strings.TrimLeft(filepath.Ext(filename), "."))
|
var result []DecoderFactory
|
||||||
for _, dec := range DecoderRegistry[ext] {
|
// Some extensions contains multiple dots, e.g. ".kgm.flac", hence iterate
|
||||||
|
// all decoders for each extension.
|
||||||
|
name := strings.ToLower(filepath.Base(filename))
|
||||||
|
for _, dec := range DecoderRegistry {
|
||||||
|
if !strings.HasSuffix(name, dec.Suffix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if skipNoop && dec.noop {
|
if skipNoop && dec.noop {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rs = append(rs, dec.decoder)
|
result = append(result, dec)
|
||||||
}
|
}
|
||||||
return
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ type Decoder struct {
|
|||||||
offset int
|
offset int
|
||||||
|
|
||||||
header header
|
header header
|
||||||
|
|
||||||
|
KggDatabasePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
||||||
return &Decoder{rd: p.Reader}
|
return &Decoder{rd: p.Reader, KggDatabasePath: p.KggDatabasePath}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate checks if the file is a valid Kugou (.kgm, .vpr, .kgma) file.
|
// Validate checks if the file is a valid Kugou (.kgm, .vpr, .kgma) file.
|
||||||
@@ -34,6 +36,11 @@ func (d *Decoder) Validate() (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("kgm init crypto v3: %w", err)
|
return fmt.Errorf("kgm init crypto v3: %w", err)
|
||||||
}
|
}
|
||||||
|
case 5:
|
||||||
|
d.cipher, err = newKgmCryptoV5(&d.header, d.KggDatabasePath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("kgm init crypto v5: %w", err)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("kgm: unsupported crypto version %d", d.header.CryptoVersion)
|
return fmt.Errorf("kgm: unsupported crypto version %d", d.header.CryptoVersion)
|
||||||
}
|
}
|
||||||
@@ -57,8 +64,12 @@ func (d *Decoder) Read(buf []byte) (int, error) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Kugou
|
// Kugou
|
||||||
|
common.RegisterDecoder("kgg", false, NewDecoder)
|
||||||
common.RegisterDecoder("kgm", false, NewDecoder)
|
common.RegisterDecoder("kgm", false, NewDecoder)
|
||||||
common.RegisterDecoder("kgma", false, NewDecoder)
|
common.RegisterDecoder("kgma", false, NewDecoder)
|
||||||
// Viper
|
// Viper
|
||||||
common.RegisterDecoder("vpr", false, NewDecoder)
|
common.RegisterDecoder("vpr", false, NewDecoder)
|
||||||
|
// Kugou Android
|
||||||
|
common.RegisterDecoder("kgm.flac", false, NewDecoder)
|
||||||
|
common.RegisterDecoder("vpr.flac", false, NewDecoder)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ type header struct {
|
|||||||
CryptoSlot uint32 // 0x18-0x1b: crypto key slot
|
CryptoSlot uint32 // 0x18-0x1b: crypto key slot
|
||||||
CryptoTestData []byte // 0x1c-0x2b: crypto test data
|
CryptoTestData []byte // 0x1c-0x2b: crypto test data
|
||||||
CryptoKey []byte // 0x2c-0x3b: crypto key
|
CryptoKey []byte // 0x2c-0x3b: crypto key
|
||||||
|
|
||||||
|
AudioHash string // v5: audio hash
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *header) FromFile(rd io.ReadSeeker) error {
|
func (h *header) FromFile(rd io.ReadSeeker) error {
|
||||||
@@ -36,29 +38,56 @@ func (h *header) FromFile(rd io.ReadSeeker) error {
|
|||||||
return fmt.Errorf("kgm seek start: %w", err)
|
return fmt.Errorf("kgm seek start: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, 0x3c)
|
return h.FromBytes(rd)
|
||||||
if _, err := io.ReadFull(rd, buf); err != nil {
|
|
||||||
return fmt.Errorf("kgm read header: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return h.FromBytes(buf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *header) FromBytes(buf []byte) error {
|
func (h *header) FromBytes(r io.ReadSeeker) error {
|
||||||
if len(buf) < 0x3c {
|
h.MagicHeader = make([]byte, 16)
|
||||||
return errors.New("invalid kgm header length")
|
_, err := r.Read(h.MagicHeader)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
h.MagicHeader = buf[:0x10]
|
|
||||||
if !bytes.Equal(kgmHeader, h.MagicHeader) && !bytes.Equal(vprHeader, h.MagicHeader) {
|
if !bytes.Equal(kgmHeader, h.MagicHeader) && !bytes.Equal(vprHeader, h.MagicHeader) {
|
||||||
return ErrKgmMagicHeader
|
return ErrKgmMagicHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
h.AudioOffset = binary.LittleEndian.Uint32(buf[0x10:0x14])
|
err = binary.Read(r, binary.LittleEndian, &h.AudioOffset)
|
||||||
h.CryptoVersion = binary.LittleEndian.Uint32(buf[0x14:0x18])
|
if err != nil {
|
||||||
h.CryptoSlot = binary.LittleEndian.Uint32(buf[0x18:0x1c])
|
return err
|
||||||
h.CryptoTestData = buf[0x1c:0x2c]
|
}
|
||||||
h.CryptoKey = buf[0x2c:0x3c]
|
err = binary.Read(r, binary.LittleEndian, &h.CryptoVersion)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = binary.Read(r, binary.LittleEndian, &h.CryptoSlot)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
h.CryptoTestData = make([]byte, 0x10)
|
||||||
|
_, err = r.Read(h.CryptoTestData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
h.CryptoKey = make([]byte, 0x10)
|
||||||
|
_, err = r.Read(h.CryptoKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if h.CryptoVersion == 5 {
|
||||||
|
r.Seek(0x08, io.SeekCurrent)
|
||||||
|
var audioHashLen uint32 = 0
|
||||||
|
err = binary.Read(r, binary.LittleEndian, &audioHashLen)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
audioHashBuffer := make([]byte, audioHashLen)
|
||||||
|
_, err = r.Read(audioHashBuffer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
h.AudioHash = string(audioHashBuffer)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
30
algo/kgm/kgm_v5.go
Normal file
30
algo/kgm/kgm_v5.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package kgm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"unlock-music.dev/cli/algo/common"
|
||||||
|
"unlock-music.dev/cli/algo/kgm/pc_kugou_db"
|
||||||
|
"unlock-music.dev/cli/algo/qmc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newKgmCryptoV5(header *header, kggDatabasePath string) (common.StreamDecoder, error) {
|
||||||
|
if header.AudioHash == "" {
|
||||||
|
return nil, fmt.Errorf("kgm v5: missing audio hash")
|
||||||
|
}
|
||||||
|
|
||||||
|
if kggDatabasePath == "" {
|
||||||
|
return nil, fmt.Errorf("kgm v5: missing kgg database path")
|
||||||
|
}
|
||||||
|
|
||||||
|
m, err := pc_kugou_db.CachedDumpEKey(kggDatabasePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("kgm v5: decrypt kgg database: %w", err)
|
||||||
|
}
|
||||||
|
ekey, ok := m[header.AudioHash]
|
||||||
|
if !ok || ekey == "" {
|
||||||
|
return nil, fmt.Errorf("kgm v5: ekey missing from db (audio_hash=%s)", header.AudioHash)
|
||||||
|
}
|
||||||
|
|
||||||
|
return qmc.NewQmcCipherDecoderFromEKey([]byte(ekey))
|
||||||
|
}
|
||||||
238
algo/kgm/pc_kugou_db/cipher.go
Normal file
238
algo/kgm/pc_kugou_db/cipher.go
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
package pc_kugou_db
|
||||||
|
|
||||||
|
// ported from lib_um_crypto_rust:
|
||||||
|
// https://git.unlock-music.dev/um/lib_um_crypto_rust/src/tag/v0.1.10/um_crypto/kgm/src/pc_db_decrypt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"crypto/aes"
|
||||||
|
"crypto/cipher"
|
||||||
|
"crypto/md5"
|
||||||
|
"database/sql"
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
_ "modernc.org/sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
|
const PAGE_SIZE = 0x400
|
||||||
|
|
||||||
|
var SQLITE_HEADER = []byte("SQLite format 3\x00")
|
||||||
|
var DEFAULT_MASTER_KEY = []byte{
|
||||||
|
// master key (0x10 bytes)
|
||||||
|
0x1D, 0x61, 0x31, 0x45, 0xB2, 0x47, 0xBF, 0x7F, 0x3D, 0x18, 0x96, 0x72, 0x14, 0x4F, 0xE4, 0xBF,
|
||||||
|
0x00, 0x00, 0x00, 0x00, // page number (le)
|
||||||
|
0x73, 0x41, 0x6C, 0x54, // fixed value
|
||||||
|
}
|
||||||
|
|
||||||
|
func next_page_iv(seed uint32) uint32 {
|
||||||
|
var left uint32 = seed * 0x9EF4
|
||||||
|
var right uint32 = seed / 0xce26 * 0x7FFFFF07
|
||||||
|
var value uint32 = left - right
|
||||||
|
if value&0x8000_0000 == 0 {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return value + 0x7FFF_FF07
|
||||||
|
}
|
||||||
|
|
||||||
|
func derive_page_aes_key(seed uint32) []byte {
|
||||||
|
master_key := make([]byte, len(DEFAULT_MASTER_KEY))
|
||||||
|
copy(master_key, DEFAULT_MASTER_KEY)
|
||||||
|
binary.LittleEndian.PutUint32(master_key[0x10:0x14], seed)
|
||||||
|
digest := md5.Sum(master_key)
|
||||||
|
return digest[:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func derive_page_aes_iv(seed uint32) []byte {
|
||||||
|
iv := make([]byte, 0x10)
|
||||||
|
seed = seed + 1
|
||||||
|
for i := 0; i < 0x10; i += 4 {
|
||||||
|
seed = next_page_iv(seed)
|
||||||
|
binary.LittleEndian.PutUint32(iv[i:i+4], seed)
|
||||||
|
}
|
||||||
|
digest := md5.Sum(iv)
|
||||||
|
return digest[:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func aes128cbcDecryptNoPadding(buffer, key, iv []byte) error {
|
||||||
|
if len(key) != 16 {
|
||||||
|
return fmt.Errorf("invalid key size: %d (must be 16 bytes for AES-128)", len(key))
|
||||||
|
}
|
||||||
|
if len(iv) != aes.BlockSize {
|
||||||
|
return fmt.Errorf("invalid IV size: %d (must be %d bytes)", len(iv), aes.BlockSize)
|
||||||
|
}
|
||||||
|
if len(buffer)%aes.BlockSize != 0 {
|
||||||
|
return fmt.Errorf("ciphertext length must be a multiple of %d bytes", aes.BlockSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mode := cipher.NewCBCDecrypter(block, iv)
|
||||||
|
mode.CryptBlocks(buffer, buffer)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decrypt_db_page(buffer []byte, page_number uint32) error {
|
||||||
|
key := derive_page_aes_key(page_number)
|
||||||
|
iv := derive_page_aes_iv(page_number)
|
||||||
|
|
||||||
|
return aes128cbcDecryptNoPadding(buffer, key, iv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func decrypt_page_1(page []byte) error {
|
||||||
|
if err := validate_page_1_header(page); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backup expected hdr value
|
||||||
|
|
||||||
|
expected_hdr_value := make([]byte, 8)
|
||||||
|
copy(expected_hdr_value, page[0x10:0x18])
|
||||||
|
|
||||||
|
// Copy encrypted hdr over
|
||||||
|
hdr := page[:0x10]
|
||||||
|
copy(page[0x10:0x18], hdr[0x08:0x10])
|
||||||
|
|
||||||
|
if err := decrypt_db_page(page[0x10:], 1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate header
|
||||||
|
if !bytes.Equal(page[0x10:0x18], expected_hdr_value[:8]) {
|
||||||
|
return fmt.Errorf("decrypt page 1 failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply SQLite header
|
||||||
|
copy(hdr, SQLITE_HEADER)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validate_page_1_header(header []byte) error {
|
||||||
|
o10 := binary.LittleEndian.Uint32(header[0x10:0x14])
|
||||||
|
o14 := binary.LittleEndian.Uint32(header[0x14:0x18])
|
||||||
|
|
||||||
|
v6 := ((o10 & 0xff) << 8) | ((o10 & 0xff00) << 16)
|
||||||
|
ok := o14 == 0x20204000 && (v6-0x200) <= 0xFE00 && ((v6-1)&v6) == 0
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid page 1 header")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decryptPcDatabase(buffer []byte) error {
|
||||||
|
db_size := len(buffer)
|
||||||
|
|
||||||
|
// not encrypted
|
||||||
|
if bytes.Equal(buffer[:len(SQLITE_HEADER)], SQLITE_HEADER) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if db_size%PAGE_SIZE != 0 || db_size == 0 {
|
||||||
|
return fmt.Errorf("invalid database size: %d", db_size)
|
||||||
|
}
|
||||||
|
|
||||||
|
last_page := db_size / PAGE_SIZE
|
||||||
|
|
||||||
|
// page 1 is the header
|
||||||
|
if err := decrypt_page_1(buffer[:PAGE_SIZE]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
offset := PAGE_SIZE
|
||||||
|
for page_no := 2; page_no <= last_page; page_no++ {
|
||||||
|
if err := decrypt_db_page(buffer[offset:offset+PAGE_SIZE], uint32(page_no)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
offset += PAGE_SIZE
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractKeyMapping(buffer []byte) (map[string]string, error) {
|
||||||
|
// Create an in-memory SQLite database
|
||||||
|
db, err := sql.Open("sqlite", "file::memory:?mode=memory&cache=shared")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
conn, err := db.Conn(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = func() error {
|
||||||
|
defer conn.Close()
|
||||||
|
return conn.Raw(func(driverConn any) error {
|
||||||
|
type serializer interface {
|
||||||
|
Serialize() ([]byte, error)
|
||||||
|
Deserialize([]byte) error
|
||||||
|
}
|
||||||
|
return driverConn.(serializer).Deserialize(buffer)
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to import db: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err = db.Conn(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := conn.QueryContext(context.Background(), `
|
||||||
|
select EncryptionKeyId, EncryptionKey from ShareFileItems
|
||||||
|
where EncryptionKey != '' and EncryptionKey is not null
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
m := make(map[string]string)
|
||||||
|
for rows.Next() {
|
||||||
|
var keyId, key string
|
||||||
|
if err := rows.Scan(&keyId, &key); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
m[keyId] = key
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var kugouPcDatabaseDumpLock = &sync.Mutex{}
|
||||||
|
var kugouPcDatabaseDump = make(map[string]map[string]string)
|
||||||
|
|
||||||
|
func CachedDumpEKey(dbPath string) (map[string]string, error) {
|
||||||
|
dump, exist := kugouPcDatabaseDump[dbPath]
|
||||||
|
if !exist {
|
||||||
|
kugouPcDatabaseDumpLock.Lock()
|
||||||
|
defer kugouPcDatabaseDumpLock.Unlock()
|
||||||
|
|
||||||
|
if dump, exist = kugouPcDatabaseDump[dbPath]; !exist {
|
||||||
|
buffer, err := os.ReadFile(dbPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = decryptPcDatabase(buffer); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dump, err = extractKeyMapping(buffer)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
kugouPcDatabaseDump[dbPath] = dump
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dump, nil
|
||||||
|
}
|
||||||
22
algo/kgm/pc_kugou_db/cipher_test.go
Normal file
22
algo/kgm/pc_kugou_db/cipher_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package pc_kugou_db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDerivePageAESKey_Page0(t *testing.T) {
|
||||||
|
expectedKey := []byte{0x19, 0x62, 0xc0, 0x5f, 0xa2, 0xeb, 0xbe, 0x24, 0x28, 0xff, 0x52, 0x2b, 0x9e, 0x03, 0xea, 0xd4}
|
||||||
|
pageKey := derive_page_aes_key(0)
|
||||||
|
if !reflect.DeepEqual(expectedKey, pageKey) {
|
||||||
|
t.Errorf("Derived AES key for page 0 does not match expected value: got %v, want %v", pageKey, expectedKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDerivePageAESIv_Page0(t *testing.T) {
|
||||||
|
expectedIv := []byte{0x05, 0x5a, 0x67, 0x35, 0x93, 0x89, 0x2d, 0xdf, 0x3a, 0xb3, 0xb3, 0xc6, 0x21, 0xc3, 0x48, 0x02}
|
||||||
|
pageKey := derive_page_aes_iv(0)
|
||||||
|
if !reflect.DeepEqual(expectedIv, pageKey) {
|
||||||
|
t.Errorf("Derived AES iv for page 0 does not match expected value: got %v, want %v", pageKey, expectedIv)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package ncm
|
package ncm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.uber.org/zap"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"unlock-music.dev/cli/algo/common"
|
"unlock-music.dev/cli/algo/common"
|
||||||
@@ -17,15 +18,14 @@ type ncmMeta interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ncmMetaMusic struct {
|
type ncmMetaMusic struct {
|
||||||
|
logger *zap.Logger
|
||||||
|
|
||||||
Format string `json:"format"`
|
Format string `json:"format"`
|
||||||
MusicID int `json:"musicId"`
|
|
||||||
MusicName string `json:"musicName"`
|
MusicName string `json:"musicName"`
|
||||||
Artist [][]interface{} `json:"artist"`
|
Artist interface{} `json:"artist"`
|
||||||
Album string `json:"album"`
|
Album string `json:"album"`
|
||||||
AlbumID int `json:"albumId"`
|
|
||||||
AlbumPicDocID interface{} `json:"albumPicDocId"`
|
AlbumPicDocID interface{} `json:"albumPicDocId"`
|
||||||
AlbumPic string `json:"albumPic"`
|
AlbumPic string `json:"albumPic"`
|
||||||
MvID int `json:"mvId"`
|
|
||||||
Flag int `json:"flag"`
|
Flag int `json:"flag"`
|
||||||
Bitrate int `json:"bitrate"`
|
Bitrate int `json:"bitrate"`
|
||||||
Duration int `json:"duration"`
|
Duration int `json:"duration"`
|
||||||
@@ -33,20 +33,34 @@ type ncmMetaMusic struct {
|
|||||||
TransNames []interface{} `json:"transNames"`
|
TransNames []interface{} `json:"transNames"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newNcmMetaMusic(logger *zap.Logger) *ncmMetaMusic {
|
||||||
|
ncm := new(ncmMetaMusic)
|
||||||
|
ncm.logger = logger.With(zap.String("module", "ncmMetaMusic"))
|
||||||
|
return ncm
|
||||||
|
}
|
||||||
|
|
||||||
func (m *ncmMetaMusic) GetAlbumImageURL() string {
|
func (m *ncmMetaMusic) GetAlbumImageURL() string {
|
||||||
return m.AlbumPic
|
return m.AlbumPic
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ncmMetaMusic) GetArtists() (artists []string) {
|
func (m *ncmMetaMusic) GetArtists() []string {
|
||||||
for _, artist := range m.Artist {
|
m.logger.Debug("ncm artists", zap.Any("artists", m.Artist))
|
||||||
for _, item := range artist {
|
|
||||||
name, ok := item.(string)
|
var artists []string = nil
|
||||||
if ok {
|
if jsonArtists, ok := m.Artist.([][]string); ok {
|
||||||
|
for _, artist := range jsonArtists {
|
||||||
|
for _, name := range artist {
|
||||||
artists = append(artists, name)
|
artists = append(artists, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if artist, ok := m.Artist.(string); ok {
|
||||||
|
// #78: artist is a string type.
|
||||||
|
// https://git.unlock-music.dev/um/cli/issues/78
|
||||||
|
artists = []string{artist}
|
||||||
|
} else {
|
||||||
|
m.logger.Warn("unexpected artist type", zap.Any("artists", m.Artist))
|
||||||
}
|
}
|
||||||
return
|
return artists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ncmMetaMusic) GetTitle() string {
|
func (m *ncmMetaMusic) GetTitle() string {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go.uber.org/zap"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -30,10 +31,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
func NewDecoder(p *common.DecoderParams) common.Decoder {
|
||||||
return &Decoder{rd: p.Reader}
|
return &Decoder{rd: p.Reader, logger: p.Logger.With(zap.String("module", "ncm"))}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Decoder struct {
|
type Decoder struct {
|
||||||
|
logger *zap.Logger
|
||||||
rd io.ReadSeeker // rd is the original file reader
|
rd io.ReadSeeker // rd is the original file reader
|
||||||
|
|
||||||
offset int
|
offset int
|
||||||
@@ -74,7 +76,7 @@ func (d *Decoder) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := d.parseMeta(); err != nil {
|
if err := d.parseMeta(); err != nil {
|
||||||
return fmt.Errorf("parse meta failed: %w", err)
|
return fmt.Errorf("parse meta failed: %w (raw json=%s)", err, string(d.metaRaw))
|
||||||
}
|
}
|
||||||
|
|
||||||
d.cipher = newNcmCipher(keyData)
|
d.cipher = newNcmCipher(keyData)
|
||||||
@@ -149,12 +151,18 @@ func (d *Decoder) readMetaData() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) readCoverData() error {
|
func (d *Decoder) readCoverData() error {
|
||||||
bCoverCRC := make([]byte, 4)
|
bCoverFrameLen := make([]byte, 4)
|
||||||
if _, err := io.ReadFull(d.rd, bCoverCRC); err != nil {
|
if _, err := io.ReadFull(d.rd, bCoverFrameLen); err != nil {
|
||||||
return fmt.Errorf("ncm read cover crc: %w", err)
|
return fmt.Errorf("ncm read cover length: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bCoverLen := make([]byte, 4) //
|
coverFrameStartOffset, err := d.rd.Seek(0, io.SeekCurrent)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ncm fetch cover frame start offset: %w", err)
|
||||||
|
}
|
||||||
|
coverFrameLen := binary.LittleEndian.Uint32(bCoverFrameLen)
|
||||||
|
|
||||||
|
bCoverLen := make([]byte, 4)
|
||||||
if _, err := io.ReadFull(d.rd, bCoverLen); err != nil {
|
if _, err := io.ReadFull(d.rd, bCoverLen); err != nil {
|
||||||
return fmt.Errorf("ncm read cover length: %w", err)
|
return fmt.Errorf("ncm read cover length: %w", err)
|
||||||
}
|
}
|
||||||
@@ -166,13 +174,16 @@ func (d *Decoder) readCoverData() error {
|
|||||||
}
|
}
|
||||||
d.cover = coverBuf
|
d.cover = coverBuf
|
||||||
|
|
||||||
return nil
|
offsetAudioData := coverFrameStartOffset + int64(coverFrameLen) + 4
|
||||||
|
_, err = d.rd.Seek(offsetAudioData, io.SeekStart)
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) parseMeta() error {
|
func (d *Decoder) parseMeta() error {
|
||||||
switch d.metaType {
|
switch d.metaType {
|
||||||
case "music":
|
case "music":
|
||||||
d.meta = new(ncmMetaMusic)
|
d.meta = newNcmMetaMusic(d.logger)
|
||||||
return json.Unmarshal(d.metaRaw, d.meta)
|
return json.Unmarshal(d.metaRaw, d.meta)
|
||||||
case "dj":
|
case "dj":
|
||||||
d.meta = new(ncmMetaDJ)
|
d.meta = new(ncmMetaDJ)
|
||||||
|
|||||||
@@ -80,6 +80,39 @@ func readKeyFromMMKV(file string, logger *zap.Logger) ([]byte, error) {
|
|||||||
return deriveKey(buf)
|
return deriveKey(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OpenMMKV(mmkvPath string, key string, logger *zap.Logger) error {
|
||||||
|
filePath, fileName := filepath.Split(mmkvPath)
|
||||||
|
mgr, err := mmkv.NewManager(filepath.Dir(filePath))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("init mmkv manager: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If `vaultKey` is empty, the key is ignored.
|
||||||
|
streamKeyVault, err = mgr.OpenVaultCrypto(fileName, key)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("open mmkv vault: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Debug("mmkv vault opened", zap.Strings("keys", streamKeyVault.Keys()))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// /
|
||||||
|
func readKeyFromMMKVCustom(mid string) ([]byte, error) {
|
||||||
|
if streamKeyVault == nil {
|
||||||
|
return nil, fmt.Errorf("mmkv vault not loaded")
|
||||||
|
}
|
||||||
|
|
||||||
|
// get ekey from mmkv vault
|
||||||
|
eKey, err := streamKeyVault.GetBytes(mid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("get eKey error: %w", err)
|
||||||
|
}
|
||||||
|
return deriveKey(eKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// / getRelativeMMKVDir get mmkv dir relative to file (legacy QQMusic for macOS behaviour)
|
||||||
func getRelativeMMKVDir(file string) (string, error) {
|
func getRelativeMMKVDir(file string) (string, error) {
|
||||||
mmkvDir := filepath.Join(filepath.Dir(file), "../mmkv")
|
mmkvDir := filepath.Join(filepath.Dir(file), "../mmkv")
|
||||||
if _, err := os.Stat(mmkvDir); err != nil {
|
if _, err := os.Stat(mmkvDir); err != nil {
|
||||||
@@ -102,7 +135,7 @@ func getDefaultMMKVDir() (string, error) {
|
|||||||
|
|
||||||
mmkvDir := filepath.Join(
|
mmkvDir := filepath.Join(
|
||||||
homeDir,
|
homeDir,
|
||||||
"Library/Containers/com.tencent.QQMusicMac/Data", // todo: make configurable
|
"Library/Containers/com.tencent.QQMusicMac/Data",
|
||||||
"Library/Application Support/QQMusicMac/mmkv",
|
"Library/Application Support/QQMusicMac/mmkv",
|
||||||
)
|
)
|
||||||
if _, err := os.Stat(mmkvDir); err != nil {
|
if _, err := os.Stat(mmkvDir); err != nil {
|
||||||
|
|||||||
@@ -60,6 +60,23 @@ func NewDecoder(p *common.DecoderParams) common.Decoder {
|
|||||||
return &Decoder{raw: p.Reader, params: p, logger: p.Logger}
|
return &Decoder{raw: p.Reader, params: p, logger: p.Logger}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewQmcCipherDecoder(key []byte) (common.StreamDecoder, error) {
|
||||||
|
if len(key) > 300 {
|
||||||
|
return newRC4Cipher(key)
|
||||||
|
} else if len(key) != 0 {
|
||||||
|
return newMapCipher(key)
|
||||||
|
}
|
||||||
|
return newStaticCipher(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewQmcCipherDecoderFromEKey(ekey []byte) (common.StreamDecoder, error) {
|
||||||
|
key, err := deriveKey(ekey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewQmcCipherDecoder(key)
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Decoder) Validate() error {
|
func (d *Decoder) Validate() error {
|
||||||
// search & derive key
|
// search & derive key
|
||||||
err := d.searchKey()
|
err := d.searchKey()
|
||||||
@@ -68,18 +85,9 @@ func (d *Decoder) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check cipher type and init decode cipher
|
// check cipher type and init decode cipher
|
||||||
if len(d.decodedKey) > 300 {
|
d.cipher, err = NewQmcCipherDecoder(d.decodedKey)
|
||||||
d.cipher, err = newRC4Cipher(d.decodedKey)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("qmc init cipher: %w", err)
|
||||||
}
|
|
||||||
} else if len(d.decodedKey) != 0 {
|
|
||||||
d.cipher, err = newMapCipher(d.decodedKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
d.cipher = newStaticCipher()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test with first 16 bytes
|
// test with first 16 bytes
|
||||||
@@ -145,6 +153,17 @@ func (d *Decoder) searchKey() (err error) {
|
|||||||
return d.readRawMetaQTag()
|
return d.readRawMetaQTag()
|
||||||
case "STag":
|
case "STag":
|
||||||
return errors.New("qmc: file with 'STag' suffix doesn't contains media key")
|
return errors.New("qmc: file with 'STag' suffix doesn't contains media key")
|
||||||
|
case "cex\x00":
|
||||||
|
footer, err := NewMusicExTag(d.raw)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.audioLen = fileSize - int(footer.TagSize)
|
||||||
|
d.decodedKey, err = readKeyFromMMKVCustom(footer.MediaFileName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
size := binary.LittleEndian.Uint32(suffixBuf)
|
size := binary.LittleEndian.Uint32(suffixBuf)
|
||||||
|
|
||||||
@@ -175,11 +194,7 @@ func (d *Decoder) readRawKey(rawKeyLen int64) error {
|
|||||||
rawKeyData = bytes.TrimRight(rawKeyData, "\x00")
|
rawKeyData = bytes.TrimRight(rawKeyData, "\x00")
|
||||||
|
|
||||||
d.decodedKey, err = deriveKey(rawKeyData)
|
d.decodedKey, err = deriveKey(rawKeyData)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) readRawMetaQTag() error {
|
func (d *Decoder) readRawMetaQTag() error {
|
||||||
@@ -244,12 +259,20 @@ func init() {
|
|||||||
"6d3461", //QQ Music Weiyun M4a
|
"6d3461", //QQ Music Weiyun M4a
|
||||||
"776176", //QQ Music Weiyun Wav
|
"776176", //QQ Music Weiyun Wav
|
||||||
|
|
||||||
"mgg", "mgg1", "mggl", //QQ Music New Ogg
|
|
||||||
"mflac", "mflac0", "mflach", //QQ Music New Flac
|
|
||||||
|
|
||||||
"mmp4", // QQ Music MP4 Container, tipically used for Dolby EAC3 stream
|
"mmp4", // QQ Music MP4 Container, tipically used for Dolby EAC3 stream
|
||||||
}
|
}
|
||||||
for _, ext := range supportedExts {
|
for _, ext := range supportedExts {
|
||||||
common.RegisterDecoder(ext, false, NewDecoder)
|
common.RegisterDecoder(ext, false, NewDecoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New ogg/flac:
|
||||||
|
extraExtsCanHaveSuffix := []string{"mgg", "mflac"}
|
||||||
|
// Mac also adds some extra suffix to ext:
|
||||||
|
extraExtSuffix := []string{"0", "1", "a", "h", "l", "m"}
|
||||||
|
for _, ext := range extraExtsCanHaveSuffix {
|
||||||
|
common.RegisterDecoder(ext, false, NewDecoder)
|
||||||
|
for _, suffix := range extraExtSuffix {
|
||||||
|
common.RegisterDecoder(ext+suffix, false, NewDecoder)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
93
algo/qmc/qmc_footer_musicex.go
Normal file
93
algo/qmc/qmc_footer_musicex.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package qmc
|
||||||
|
|
||||||
|
import (
|
||||||
|
bytes "bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MusicExTagV1 struct {
|
||||||
|
SongID uint32 // Song ID
|
||||||
|
Unknown1 uint32 // unused & unknown
|
||||||
|
Unknown2 uint32 // unused & unknown
|
||||||
|
MediaID string // Media ID
|
||||||
|
MediaFileName string // real file name
|
||||||
|
Unknown3 uint32 // unused; uninitialized memory?
|
||||||
|
|
||||||
|
// 16 byte at the end of tag.
|
||||||
|
// TagSize should be respected when parsing.
|
||||||
|
TagSize uint32 // 19.57: fixed value: 0xC0
|
||||||
|
TagVersion uint32 // 19.57: fixed value: 0x01
|
||||||
|
TagMagic []byte // fixed value "musicex\0" (8 bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMusicExTag(f io.ReadSeeker) (*MusicExTagV1, error) {
|
||||||
|
_, err := f.Seek(-16, io.SeekEnd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("musicex seek error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer := make([]byte, 16)
|
||||||
|
bytesRead, err := f.Read(buffer)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("get musicex error: %w", err)
|
||||||
|
}
|
||||||
|
if bytesRead != 16 {
|
||||||
|
return nil, fmt.Errorf("MusicExV1: read %d bytes (expected %d)", bytesRead, 16)
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := &MusicExTagV1{
|
||||||
|
TagSize: binary.LittleEndian.Uint32(buffer[0x00:0x04]),
|
||||||
|
TagVersion: binary.LittleEndian.Uint32(buffer[0x04:0x08]),
|
||||||
|
TagMagic: buffer[0x04:0x0C],
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bytes.Equal(tag.TagMagic, []byte("musicex\x00")) {
|
||||||
|
return nil, errors.New("MusicEx magic mismatch")
|
||||||
|
}
|
||||||
|
if tag.TagVersion != 1 {
|
||||||
|
return nil, errors.New(fmt.Sprintf("unsupported musicex tag version. expecting 1, got %d", tag.TagVersion))
|
||||||
|
}
|
||||||
|
|
||||||
|
if tag.TagSize < 0xC0 {
|
||||||
|
return nil, errors.New(fmt.Sprintf("unsupported musicex tag size. expecting at least 0xC0, got 0x%02x", tag.TagSize))
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = make([]byte, tag.TagSize)
|
||||||
|
bytesRead, err = f.Read(buffer)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if uint32(bytesRead) != tag.TagSize {
|
||||||
|
return nil, fmt.Errorf("MusicExV1: read %d bytes (expected %d)", bytesRead, tag.TagSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
tag.SongID = binary.LittleEndian.Uint32(buffer[0x00:0x04])
|
||||||
|
tag.Unknown1 = binary.LittleEndian.Uint32(buffer[0x04:0x08])
|
||||||
|
tag.Unknown2 = binary.LittleEndian.Uint32(buffer[0x08:0x0C])
|
||||||
|
tag.MediaID = readUnicodeTagName(buffer[0x0C:], 30*2)
|
||||||
|
tag.MediaFileName = readUnicodeTagName(buffer[0x48:], 50*2)
|
||||||
|
tag.Unknown3 = binary.LittleEndian.Uint32(buffer[0xAC:0xB0])
|
||||||
|
return tag, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// readUnicodeTagName reads a buffer to maxLen.
|
||||||
|
// reconstruct text by skipping alternate char (ascii chars encoded in UTF-16-LE),
|
||||||
|
// until finding a zero or reaching maxLen.
|
||||||
|
func readUnicodeTagName(buffer []byte, maxLen int) string {
|
||||||
|
builder := strings.Builder{}
|
||||||
|
|
||||||
|
for i := 0; i < maxLen; i += 2 {
|
||||||
|
chr := buffer[i]
|
||||||
|
if chr != 0 {
|
||||||
|
builder.WriteByte(chr)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
279
cmd/um/main.go
279
cmd/um/main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
@@ -14,26 +15,26 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
"unlock-music.dev/cli/algo/common"
|
"unlock-music.dev/cli/algo/common"
|
||||||
_ "unlock-music.dev/cli/algo/kgm"
|
_ "unlock-music.dev/cli/algo/kgm"
|
||||||
_ "unlock-music.dev/cli/algo/kwm"
|
_ "unlock-music.dev/cli/algo/kwm"
|
||||||
_ "unlock-music.dev/cli/algo/ncm"
|
_ "unlock-music.dev/cli/algo/ncm"
|
||||||
_ "unlock-music.dev/cli/algo/qmc"
|
"unlock-music.dev/cli/algo/qmc"
|
||||||
_ "unlock-music.dev/cli/algo/tm"
|
_ "unlock-music.dev/cli/algo/tm"
|
||||||
_ "unlock-music.dev/cli/algo/xiami"
|
_ "unlock-music.dev/cli/algo/xiami"
|
||||||
_ "unlock-music.dev/cli/algo/ximalaya"
|
_ "unlock-music.dev/cli/algo/ximalaya"
|
||||||
"unlock-music.dev/cli/internal/ffmpeg"
|
"unlock-music.dev/cli/internal/ffmpeg"
|
||||||
"unlock-music.dev/cli/internal/logging"
|
|
||||||
"unlock-music.dev/cli/internal/sniff"
|
"unlock-music.dev/cli/internal/sniff"
|
||||||
"unlock-music.dev/cli/internal/utils"
|
"unlock-music.dev/cli/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AppVersion = "v0.0.6"
|
var AppVersion = "custom"
|
||||||
|
|
||||||
var logger, _ = logging.NewZapLogger() // TODO: inject logger to application, instead of using global logger
|
var logger = setupLogger(false) // TODO: inject logger to application, instead of using global logger
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
module, ok := debug.ReadBuildInfo()
|
module, ok := debug.ReadBuildInfo()
|
||||||
@@ -48,9 +49,15 @@ func main() {
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{Name: "input", Aliases: []string{"i"}, Usage: "path to input file or dir", Required: false},
|
&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: "output", Aliases: []string{"o"}, Usage: "path to output dir", Required: false},
|
||||||
|
&cli.StringFlag{Name: "qmc-mmkv", Aliases: []string{"db"}, Usage: "path to qmc mmkv (.crc file also required)", Required: false},
|
||||||
|
&cli.StringFlag{Name: "qmc-mmkv-key", Aliases: []string{"key"}, Usage: "mmkv password (16 ascii chars)", Required: false},
|
||||||
|
&cli.StringFlag{Name: "kgg-db", Usage: "path to kgg db (win32 kugou v11)", Required: false},
|
||||||
&cli.BoolFlag{Name: "remove-source", Aliases: []string{"rs"}, Usage: "remove source file", Required: false, Value: 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: "skip-noop", Aliases: []string{"n"}, Usage: "skip noop decoder", Required: false, Value: true},
|
||||||
|
&cli.BoolFlag{Name: "verbose", Aliases: []string{"V"}, Usage: "verbose logging", Required: false, Value: false},
|
||||||
&cli.BoolFlag{Name: "update-metadata", Usage: "update metadata & album art from network", Required: false, Value: false},
|
&cli.BoolFlag{Name: "update-metadata", Usage: "update metadata & album art from network", Required: false, Value: false},
|
||||||
|
&cli.BoolFlag{Name: "overwrite", Usage: "overwrite output file without asking", Required: false, Value: false},
|
||||||
|
&cli.BoolFlag{Name: "watch", Usage: "watch the input dir and process new files", Required: false, Value: false},
|
||||||
|
|
||||||
&cli.BoolFlag{Name: "supported-ext", Usage: "show supported file extensions and exit", Required: false, Value: false},
|
&cli.BoolFlag{Name: "supported-ext", Usage: "show supported file extensions and exit", Required: false, Value: false},
|
||||||
},
|
},
|
||||||
@@ -60,22 +67,59 @@ func main() {
|
|||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
UsageText: "um [-o /path/to/output/dir] [--extra-flags] [-i] /path/to/input",
|
UsageText: "um [-o /path/to/output/dir] [--extra-flags] [-i] /path/to/input",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal("run app failed", zap.Error(err))
|
logger.Fatal("run app failed", zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printSupportedExtensions() {
|
func printSupportedExtensions() {
|
||||||
var exts []string
|
var exts []string
|
||||||
for ext := range common.DecoderRegistry {
|
extSet := make(map[string]int)
|
||||||
|
for _, factory := range common.DecoderRegistry {
|
||||||
|
ext := strings.TrimPrefix(factory.Suffix, ".")
|
||||||
|
if n, ok := extSet[ext]; ok {
|
||||||
|
extSet[ext] = n + 1
|
||||||
|
} else {
|
||||||
|
extSet[ext] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for ext := range extSet {
|
||||||
exts = append(exts, ext)
|
exts = append(exts, ext)
|
||||||
}
|
}
|
||||||
sort.Strings(exts)
|
sort.Strings(exts)
|
||||||
for _, ext := range exts {
|
for _, ext := range exts {
|
||||||
fmt.Printf("%s: %d\n", ext, len(common.DecoderRegistry[ext]))
|
fmt.Printf("%s: %d\n", ext, extSet[ext])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupLogger(verbose bool) *zap.Logger {
|
||||||
|
logConfig := zap.NewProductionEncoderConfig()
|
||||||
|
logConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||||
|
logConfig.EncodeTime = zapcore.RFC3339TimeEncoder
|
||||||
|
enabler := zap.LevelEnablerFunc(func(level zapcore.Level) bool {
|
||||||
|
if verbose {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return level >= zapcore.InfoLevel
|
||||||
|
})
|
||||||
|
|
||||||
|
return zap.New(zapcore.NewCore(
|
||||||
|
zapcore.NewConsoleEncoder(logConfig),
|
||||||
|
os.Stdout,
|
||||||
|
enabler,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
func appMain(c *cli.Context) (err error) {
|
func appMain(c *cli.Context) (err error) {
|
||||||
|
logger = setupLogger(c.Bool("verbose"))
|
||||||
|
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if c.Bool("supported-ext") {
|
if c.Bool("supported-ext") {
|
||||||
printSupportedExtensions()
|
printSupportedExtensions()
|
||||||
return nil
|
return nil
|
||||||
@@ -84,10 +128,7 @@ func appMain(c *cli.Context) (err error) {
|
|||||||
if input == "" {
|
if input == "" {
|
||||||
switch c.Args().Len() {
|
switch c.Args().Len() {
|
||||||
case 0:
|
case 0:
|
||||||
input, err = os.Getwd()
|
input = cwd
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case 1:
|
case 1:
|
||||||
input = c.Args().Get(0)
|
input = c.Args().Get(0)
|
||||||
default:
|
default:
|
||||||
@@ -95,23 +136,34 @@ func appMain(c *cli.Context) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output := c.String("output")
|
input, absErr := filepath.Abs(input)
|
||||||
if output == "" {
|
if absErr != nil {
|
||||||
var err error
|
return fmt.Errorf("get abs path failed: %w", absErr)
|
||||||
output, err = os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if input == output {
|
|
||||||
return errors.New("input and output path are same")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output := c.String("output")
|
||||||
inputStat, err := os.Stat(input)
|
inputStat, err := os.Stat(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var inputDir string
|
||||||
|
if inputStat.IsDir() {
|
||||||
|
inputDir = input
|
||||||
|
} else {
|
||||||
|
inputDir = filepath.Dir(input)
|
||||||
|
}
|
||||||
|
inputDir, absErr = filepath.Abs(inputDir)
|
||||||
|
if absErr != nil {
|
||||||
|
return fmt.Errorf("get abs path (inputDir) failed: %w", absErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if output == "" {
|
||||||
|
// Default to where the input dir is
|
||||||
|
output = inputDir
|
||||||
|
}
|
||||||
|
logger.Debug("resolve input/output path", zap.String("inputDir", inputDir), zap.String("input", input), zap.String("output", output))
|
||||||
|
|
||||||
outputStat, err := os.Stat(output)
|
outputStat, err := os.Stat(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
@@ -124,15 +176,38 @@ func appMain(c *cli.Context) (err error) {
|
|||||||
return errors.New("output should be a writable directory")
|
return errors.New("output should be a writable directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if mmkv := c.String("qmc-mmkv"); mmkv != "" {
|
||||||
|
// If key is not set, the mmkv vault will be treated as unencrypted.
|
||||||
|
key := c.String("qmc-mmkv-key")
|
||||||
|
err := qmc.OpenMMKV(mmkv, key, logger)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kggDbPath := c.String("kgg-db")
|
||||||
|
if kggDbPath == "" {
|
||||||
|
kggDbPath = filepath.Join(os.Getenv("APPDATA"), "Kugou8", "KGMusicV3.db")
|
||||||
|
}
|
||||||
|
|
||||||
proc := &processor{
|
proc := &processor{
|
||||||
|
logger: logger,
|
||||||
|
inputDir: inputDir,
|
||||||
outputDir: output,
|
outputDir: output,
|
||||||
|
kggDbPath: kggDbPath,
|
||||||
skipNoopDecoder: c.Bool("skip-noop"),
|
skipNoopDecoder: c.Bool("skip-noop"),
|
||||||
removeSource: c.Bool("remove-source"),
|
removeSource: c.Bool("remove-source"),
|
||||||
updateMetadata: c.Bool("update-metadata"),
|
updateMetadata: c.Bool("update-metadata"),
|
||||||
|
overwriteOutput: c.Bool("overwrite"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if inputStat.IsDir() {
|
if inputStat.IsDir() {
|
||||||
|
watchDir := c.Bool("watch")
|
||||||
|
if !watchDir {
|
||||||
return proc.processDir(input)
|
return proc.processDir(input)
|
||||||
|
} else {
|
||||||
|
return proc.watchDir(input)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return proc.processFile(input)
|
return proc.processFile(input)
|
||||||
}
|
}
|
||||||
@@ -140,11 +215,70 @@ func appMain(c *cli.Context) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type processor struct {
|
type processor struct {
|
||||||
|
logger *zap.Logger
|
||||||
|
inputDir string
|
||||||
outputDir string
|
outputDir string
|
||||||
|
|
||||||
|
kggDbPath string
|
||||||
|
|
||||||
skipNoopDecoder bool
|
skipNoopDecoder bool
|
||||||
removeSource bool
|
removeSource bool
|
||||||
updateMetadata bool
|
updateMetadata bool
|
||||||
|
overwriteOutput bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *processor) watchDir(inputDir string) error {
|
||||||
|
if err := p.processDir(inputDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
watcher, err := fsnotify.NewWatcher()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create watcher: %w", err)
|
||||||
|
}
|
||||||
|
defer watcher.Close()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case event, ok := <-watcher.Events:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if event.Has(fsnotify.Create) || event.Has(fsnotify.Write) {
|
||||||
|
// try open with exclusive mode, to avoid file is still writing
|
||||||
|
f, err := os.OpenFile(event.Name, os.O_RDONLY, os.ModeExclusive)
|
||||||
|
if err != nil {
|
||||||
|
logger.Debug("failed to open file exclusively", zap.String("path", event.Name), zap.Error(err))
|
||||||
|
time.Sleep(1 * time.Second) // wait for file writing complete
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_ = f.Close()
|
||||||
|
|
||||||
|
if err := p.processFile(event.Name); err != nil {
|
||||||
|
logger.Warn("failed to process file", zap.String("path", event.Name), zap.Error(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case err, ok := <-watcher.Errors:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logger.Error("file watcher got error", zap.Error(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = watcher.Add(inputDir)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to watch dir %s: %w", inputDir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
signalCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||||
|
defer stop()
|
||||||
|
|
||||||
|
<-signalCtx.Done()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) processDir(inputDir string) error {
|
func (p *processor) processDir(inputDir string) error {
|
||||||
@@ -152,29 +286,64 @@ func (p *processor) processDir(inputDir string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lastError error = nil
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
|
filePath := filepath.Join(inputDir, item.Name())
|
||||||
if item.IsDir() {
|
if item.IsDir() {
|
||||||
|
if err = p.processDir(filePath); err != nil {
|
||||||
|
lastError = err
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath := filepath.Join(inputDir, item.Name())
|
if err := p.processFile(filePath); err != nil {
|
||||||
err := p.processFile(filePath)
|
lastError = err
|
||||||
if err != nil {
|
logger.Error("conversion failed", zap.String("source", item.Name()), zap.Error(err))
|
||||||
logger.Error("conversion failed", zap.String("source", filePath), zap.Error(err))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if lastError != nil {
|
||||||
|
return fmt.Errorf("last error: %w", lastError)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) processFile(filePath string) error {
|
func (p *processor) processFile(filePath string) error {
|
||||||
|
p.logger.Debug("processFile", zap.String("file", filePath), zap.String("inputDir", p.inputDir))
|
||||||
|
|
||||||
allDec := common.GetDecoder(filePath, p.skipNoopDecoder)
|
allDec := common.GetDecoder(filePath, p.skipNoopDecoder)
|
||||||
if len(allDec) == 0 {
|
if len(allDec) == 0 {
|
||||||
logger.Fatal("skipping while no suitable decoder")
|
return errors.New("skipping while no suitable decoder")
|
||||||
}
|
}
|
||||||
return p.process(filePath, allDec)
|
|
||||||
|
if err := p.process(filePath, allDec); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// if source file need to be removed
|
||||||
|
if p.removeSource {
|
||||||
|
err := os.RemoveAll(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("source file removed after success conversion", zap.String("source", filePath))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) process(inputFile string, allDec []common.NewDecoderFunc) error {
|
func (p *processor) findDecoder(decoders []common.DecoderFactory, params *common.DecoderParams) (*common.Decoder, *common.DecoderFactory, error) {
|
||||||
|
for _, factory := range decoders {
|
||||||
|
dec := factory.Create(params)
|
||||||
|
err := dec.Validate()
|
||||||
|
if err == nil {
|
||||||
|
return &dec, &factory, nil
|
||||||
|
}
|
||||||
|
logger.Warn("try decode failed", zap.Error(err))
|
||||||
|
}
|
||||||
|
return nil, nil, errors.New("no any decoder can resolve the file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *processor) process(inputFile string, allDec []common.DecoderFactory) error {
|
||||||
file, err := os.Open(inputFile)
|
file, err := os.Open(inputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -182,26 +351,17 @@ func (p *processor) process(inputFile string, allDec []common.NewDecoderFunc) er
|
|||||||
defer file.Close()
|
defer file.Close()
|
||||||
logger := logger.With(zap.String("source", inputFile))
|
logger := logger.With(zap.String("source", inputFile))
|
||||||
|
|
||||||
decParams := &common.DecoderParams{
|
pDec, decoderFactory, err := p.findDecoder(allDec, &common.DecoderParams{
|
||||||
Reader: file,
|
Reader: file,
|
||||||
Extension: filepath.Ext(inputFile),
|
Extension: filepath.Ext(inputFile),
|
||||||
FilePath: inputFile,
|
FilePath: inputFile,
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
|
KggDatabasePath: p.kggDbPath,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
dec := *pDec
|
||||||
var dec common.Decoder
|
|
||||||
for _, decFunc := range allDec {
|
|
||||||
dec = decFunc(decParams)
|
|
||||||
if err := dec.Validate(); err == nil {
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
logger.Warn("try decode failed", zap.Error(err))
|
|
||||||
dec = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if dec == nil {
|
|
||||||
return errors.New("no any decoder can resolve the file")
|
|
||||||
}
|
|
||||||
|
|
||||||
params := &ffmpeg.UpdateMetadataParams{}
|
params := &ffmpeg.UpdateMetadataParams{}
|
||||||
|
|
||||||
@@ -258,8 +418,23 @@ func (p *processor) process(inputFile string, allDec []common.NewDecoderFunc) er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inFilename := strings.TrimSuffix(filepath.Base(inputFile), filepath.Ext(inputFile))
|
inputRelDir, err := filepath.Rel(p.inputDir, filepath.Dir(inputFile))
|
||||||
outPath := filepath.Join(p.outputDir, inFilename+params.AudioExt)
|
if err != nil {
|
||||||
|
return fmt.Errorf("get relative dir failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
inFilename := strings.TrimSuffix(filepath.Base(inputFile), decoderFactory.Suffix)
|
||||||
|
outPath := filepath.Join(p.outputDir, inputRelDir, inFilename+params.AudioExt)
|
||||||
|
|
||||||
|
if !p.overwriteOutput {
|
||||||
|
_, err := os.Stat(outPath)
|
||||||
|
if err == nil {
|
||||||
|
logger.Warn("output file already exist, skip", zap.String("destination", outPath))
|
||||||
|
return nil
|
||||||
|
} else if !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return fmt.Errorf("stat output file failed: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if params.Meta == nil {
|
if params.Meta == nil {
|
||||||
outFile, err := os.OpenFile(outPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
outFile, err := os.OpenFile(outPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||||
@@ -271,27 +446,15 @@ func (p *processor) process(inputFile string, allDec []common.NewDecoderFunc) er
|
|||||||
if _, err := io.Copy(outFile, audio); err != nil {
|
if _, err := io.Copy(outFile, audio); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
outFile.Close()
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if err := ffmpeg.UpdateMeta(ctx, outPath, params); err != nil {
|
if err := ffmpeg.UpdateMeta(ctx, outPath, params, logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if source file need to be removed
|
|
||||||
if p.removeSource {
|
|
||||||
err := os.RemoveAll(inputFile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
logger.Info("successfully converted, and source file is removed", zap.String("source", inputFile), zap.String("destination", outPath))
|
|
||||||
} else {
|
|
||||||
logger.Info("successfully converted", zap.String("source", inputFile), zap.String("destination", outPath))
|
logger.Info("successfully converted", zap.String("source", inputFile), zap.String("destination", outPath))
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
43
go.mod
43
go.mod
@@ -1,26 +1,35 @@
|
|||||||
module unlock-music.dev/cli
|
module unlock-music.dev/cli
|
||||||
|
|
||||||
go 1.19
|
go 1.23.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-flac/flacpicture v0.2.0
|
github.com/fsnotify/fsnotify v1.8.0
|
||||||
github.com/go-flac/flacvorbis v0.1.0
|
github.com/go-flac/flacpicture v0.3.0
|
||||||
github.com/go-flac/go-flac v0.3.1
|
github.com/go-flac/flacvorbis v0.2.0
|
||||||
github.com/samber/lo v1.36.0
|
github.com/go-flac/go-flac v1.0.0
|
||||||
github.com/urfave/cli/v2 v2.23.6
|
github.com/samber/lo v1.47.0
|
||||||
go.uber.org/zap v1.24.0
|
github.com/urfave/cli/v2 v2.27.5
|
||||||
golang.org/x/crypto v0.3.0
|
go.uber.org/zap v1.27.0
|
||||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db
|
golang.org/x/crypto v0.29.0
|
||||||
golang.org/x/text v0.5.0
|
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394
|
||||||
unlock-music.dev/mmkv v0.0.0-20221204231432-41a75bd29939
|
golang.org/x/text v0.20.0
|
||||||
|
unlock-music.dev/mmkv v0.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||||
go.uber.org/atomic v1.10.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
go.uber.org/multierr v1.8.0 // indirect
|
golang.org/x/sys v0.31.0 // indirect
|
||||||
google.golang.org/protobuf v1.28.1 // indirect
|
google.golang.org/protobuf v1.35.2 // indirect
|
||||||
|
modernc.org/libc v1.62.1 // indirect
|
||||||
|
modernc.org/mathutil v1.7.1 // indirect
|
||||||
|
modernc.org/memory v1.9.1 // indirect
|
||||||
|
modernc.org/sqlite v1.37.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
130
go.sum
130
go.sum
@@ -1,61 +1,83 @@
|
|||||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/ddliu/go-httpclient v0.5.1 h1:ys4KozrhBaGdI1yuWIFwNNILqhnMU9ozTvRNfCTorvs=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
github.com/ddliu/go-httpclient v0.5.1/go.mod h1:8QVbjq00YK2f2MQyiKuWMdaKOFRcoD9VuubkNCNOuZo=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/go-flac/flacpicture v0.2.0 h1:rS/ZOR/ZxlEwMf3yOPFcTAmGyoV6rDtcYdd+6CwWQAw=
|
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||||
github.com/go-flac/flacpicture v0.2.0/go.mod h1:M4a1J0v6B5NHsck4GA1yZg0vFQzETVPd3kuj6Ow+q9o=
|
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||||
github.com/go-flac/flacvorbis v0.1.0 h1:xStJfPrZ/IoA2oBUEwgrlaSf+Opo6/YuQfkqVhkP0cM=
|
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
|
||||||
github.com/go-flac/flacvorbis v0.1.0/go.mod h1:70N9vVkQ4Jew0oBWkwqDMIE21h7pMUtQJpnMD0js6XY=
|
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||||
github.com/go-flac/go-flac v0.3.1 h1:BWA7HdO67S4ZLWSVHCxsDHuedFFu5RiV/wmuhvO6Hxo=
|
github.com/go-flac/flacpicture v0.3.0 h1:LkmTxzFLIynwfhHiZsX0s8xcr3/u33MzvV89u+zOT8I=
|
||||||
github.com/go-flac/go-flac v0.3.1/go.mod h1:jG9IumOfAXr+7J40x0AiQIbJzXf9Y7+Zs/2CNWe4LMk=
|
github.com/go-flac/flacpicture v0.3.0/go.mod h1:DPbrzVYQ3fJcvSgLFp9HXIrEQEdfdk/+m0nQCzwodZI=
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/go-flac/flacvorbis v0.2.0 h1:KH0xjpkNTXFER4cszH4zeJxYcrHbUobz/RticWGOESs=
|
||||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
github.com/go-flac/flacvorbis v0.2.0/go.mod h1:uIysHOtuU7OLGoCRG92bvnkg7QEqHx19qKRV6K1pBrI=
|
||||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/go-flac/go-flac v1.0.0 h1:6qI9XOVLcO50xpzm3nXvO31BgDgHhnr/p/rER/K/doY=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/go-flac/go-flac v1.0.0/go.mod h1:WnZhcpmq4u1UdZMNn9LYSoASpWOCMOoxXxcWEHSzkW8=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||||
|
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/samber/lo v1.36.0 h1:4LaOxH1mHnbDGhTVE0i1z8v/lWaQW8AIfOD3HU4mSaw=
|
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
|
||||||
github.com/samber/lo v1.36.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8=
|
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M=
|
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
|
||||||
github.com/urfave/cli/v2 v2.23.6 h1:iWmtKD+prGo1nKUtLO0Wg4z9esfBM4rAV4QRLQiEmJ4=
|
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||||
github.com/urfave/cli/v2 v2.23.6/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
|
||||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
|
||||||
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||||
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||||
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||||
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
|
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||||
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
|
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o=
|
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
||||||
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
|
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
||||||
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
|
||||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||||
|
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
|
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||||
|
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||||
|
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
|
||||||
|
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
|
||||||
|
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||||
|
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
unlock-music.dev/mmkv v0.0.0-20221204231432-41a75bd29939 h1:qWv734RbYjIHtHhZSRbdSyAEJ5K1rWcPSuUOen86tvI=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
unlock-music.dev/mmkv v0.0.0-20221204231432-41a75bd29939/go.mod h1:1+Hdsrk8gl1i4/oxOnAhx6y51DAcUfi2CDni6Qhk8Kw=
|
modernc.org/libc v1.62.1 h1:s0+fv5E3FymN8eJVmnk0llBe6rOxCu/DEU+XygRbS8s=
|
||||||
|
modernc.org/libc v1.62.1/go.mod h1:iXhATfJQLjG3NWy56a6WVU73lWOcdYVxsvwCgoPljuo=
|
||||||
|
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||||
|
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||||
|
modernc.org/memory v1.9.1 h1:V/Z1solwAVmMW1yttq3nDdZPJqV1rM05Ccq6KMSZ34g=
|
||||||
|
modernc.org/memory v1.9.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||||
|
modernc.org/sqlite v1.37.0 h1:s1TMe7T3Q3ovQiK2Ouz4Jwh7dw4ZDqbebSDTlSJdfjI=
|
||||||
|
modernc.org/sqlite v1.37.0/go.mod h1:5YiWv+YviqGMuGw4V+PNplcyaJ5v+vQd7TQOgkACoJM=
|
||||||
|
unlock-music.dev/mmkv v0.1.0 h1:hgUHo0gJVoiKZ6bOcFOw2LHFqNiefIe+jb5o0OyL720=
|
||||||
|
unlock-music.dev/mmkv v0.1.0/go.mod h1:qr34SM3x8xRxyUfGzefH/rSi+DUXkQZcSfXY/yfuTeo=
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go.uber.org/zap"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -43,9 +44,9 @@ type UpdateMetadataParams struct {
|
|||||||
AlbumArtExt string // required if AlbumArt is not nil
|
AlbumArtExt string // required if AlbumArt is not nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateMeta(ctx context.Context, outPath string, params *UpdateMetadataParams) error {
|
func UpdateMeta(ctx context.Context, outPath string, params *UpdateMetadataParams, logger *zap.Logger) error {
|
||||||
if params.AudioExt == ".flac" {
|
if params.AudioExt == ".flac" {
|
||||||
return updateMetaFlac(ctx, outPath, params)
|
return updateMetaFlac(ctx, outPath, params, logger.With(zap.String("module", "updateMetaFlac")))
|
||||||
} else {
|
} else {
|
||||||
return updateMetaFFmpeg(ctx, outPath, params)
|
return updateMetaFFmpeg(ctx, outPath, params)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package ffmpeg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"go.uber.org/zap"
|
||||||
"mime"
|
"mime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ import (
|
|||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams) error {
|
func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams, logger *zap.Logger) error {
|
||||||
f, err := flac.ParseFile(m.Audio)
|
f, err := flac.ParseFile(m.Audio)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -62,16 +63,18 @@ func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if m.AlbumArt != nil {
|
if m.AlbumArt != nil {
|
||||||
|
coverMime := mime.TypeByExtension(m.AlbumArtExt)
|
||||||
|
logger.Debug("cover image mime detect", zap.String("mime", coverMime))
|
||||||
cover, err := flacpicture.NewFromImageData(
|
cover, err := flacpicture.NewFromImageData(
|
||||||
flacpicture.PictureTypeFrontCover,
|
flacpicture.PictureTypeFrontCover,
|
||||||
"Front cover",
|
"Front cover",
|
||||||
m.AlbumArt,
|
m.AlbumArt,
|
||||||
mime.TypeByExtension(m.AlbumArtExt),
|
coverMime,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
logger.Warn("failed to create flac cover", zap.Error(err))
|
||||||
}
|
} else {
|
||||||
coverBlock := cover.Marshal()
|
coverBlock := cover.Marshal()
|
||||||
f.Meta = append(f.Meta, &coverBlock)
|
f.Meta = append(f.Meta, &coverBlock)
|
||||||
|
|
||||||
@@ -85,6 +88,7 @@ func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams)
|
|||||||
f.Meta[coverIdx] = &coverBlock
|
f.Meta[coverIdx] = &coverBlock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return f.Save(outPath)
|
return f.Save(outPath)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package sniff
|
|||||||
// ref: https://mimesniff.spec.whatwg.org
|
// ref: https://mimesniff.spec.whatwg.org
|
||||||
var imageMIMEs = map[string]Sniffer{
|
var imageMIMEs = map[string]Sniffer{
|
||||||
"image/jpeg": prefixSniffer{0xFF, 0xD8, 0xFF},
|
"image/jpeg": prefixSniffer{0xFF, 0xD8, 0xFF},
|
||||||
"image/png": prefixSniffer{'P', 'N', 'G', '\r', '\n', 0x1A, '\n'},
|
"image/png": prefixSniffer{0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n'},
|
||||||
"image/bmp": prefixSniffer("BM"),
|
"image/bmp": prefixSniffer("BM"),
|
||||||
"image/webp": prefixSniffer("RIFF"),
|
"image/webp": prefixSniffer("RIFF"),
|
||||||
"image/gif": prefixSniffer("GIF8"),
|
"image/gif": prefixSniffer("GIF8"),
|
||||||
|
|||||||
Reference in New Issue
Block a user