Compare commits

...

10 Commits
v0.2.8 ... main

Author SHA1 Message Date
28ca8cef60 docs: update readme about go version and how to build from source
All checks were successful
continuous-integration/drone/push Build is passing
2024-11-22 00:57:09 +09:00
2b0bd2985e chore: bump golang and dependency version
All checks were successful
continuous-integration/drone/push Build is passing
2024-11-22 00:50:52 +09:00
72ace9fc62 chore: bump version to v0.2.11
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2024-11-05 16:56:40 +09:00
074e4f874f fix #108: rel path resolution in windows
All checks were successful
continuous-integration/drone/push Build is passing
2024-11-05 16:27:14 +09:00
2bfb5ffddf chore: bump version to v0.2.10
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2024-11-04 14:25:02 +09:00
2c9de7c56c fix #107: windows dnd path error 2024-11-04 14:24:32 +09:00
b374c11c86 chore: bump app version to v0.2.9
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2024-11-02 13:59:22 +09:00
6493b2c5fc fix #78: skip parsing cover art if image is unsupported
All checks were successful
continuous-integration/drone/push Build is passing
2024-11-02 13:49:40 +09:00
f753b9c67d fix #78 #106: app crash due to imcompatible ncm metadata json 2024-11-02 13:44:29 +09:00
8829a3b3ba refactor: rework on logging 2024-11-02 13:43:56 +09:00
10 changed files with 180 additions and 99 deletions

View File

@ -33,7 +33,7 @@ local StepGoBuild(GOOS, GOARCH) = {
],
name: 'go build %s/%s' % [GOOS, GOARCH],
image: 'golang:1.22',
image: 'golang:1.23',
environment: {
GOOS: GOOS,
GOARCH: GOARCH,
@ -54,7 +54,7 @@ local StepUploadArtifact(GOOS, GOARCH) = {
local pkgname = '${DRONE_REPO_NAME}-build',
name: 'upload artifact',
image: 'golang:1.22', // reuse golang:1.19 for curl
image: 'golang:1.23', // reuse golang:1.19 for curl
environment: {
DRONE_GITEA_SERVER: 'https://git.unlock-music.dev',
GITEA_API_KEY: { from_secret: 'GITEA_API_KEY' },
@ -83,7 +83,7 @@ local PipelineBuild(GOOS, GOARCH, RUN_TEST) = {
(
if RUN_TEST then [{
name: 'go test',
image: 'golang:1.22',
image: 'golang:1.23',
environment: {
GOPROXY: 'https://goproxy.io,direct',
},
@ -112,7 +112,7 @@ local PipelineRelease() = {
},
{
name: 'go test',
image: 'golang:1.22',
image: 'golang:1.23',
environment: {
GOPROXY: 'https://goproxy.io,direct',
},
@ -128,7 +128,7 @@ local PipelineRelease() = {
StepGoBuild('darwin', 'arm64'),
{
name: 'prepare root',
image: 'golang:1.22',
image: 'golang:1.23',
commands: [
'mv dist/*.tar.gz dist/*.zip ./',
],

View File

@ -10,7 +10,7 @@ steps:
- go test -v ./...
environment:
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go test
- commands:
- DIST_DIR=$(mktemp -d)
@ -23,7 +23,7 @@ steps:
GOARCH: amd64
GOOS: linux
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build linux/amd64
- commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-linux-amd64-$(git
@ -35,7 +35,7 @@ steps:
DRONE_GITEA_SERVER: https://git.unlock-music.dev
GITEA_API_KEY:
from_secret: GITEA_API_KEY
image: golang:1.22
image: golang:1.23
name: upload artifact
trigger:
event:
@ -61,7 +61,7 @@ steps:
GOARCH: amd64
GOOS: windows
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build windows/amd64
- commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-windows-amd64-$(git
@ -73,7 +73,7 @@ steps:
DRONE_GITEA_SERVER: https://git.unlock-music.dev
GITEA_API_KEY:
from_secret: GITEA_API_KEY
image: golang:1.22
image: golang:1.23
name: upload artifact
trigger:
event:
@ -99,7 +99,7 @@ steps:
GOARCH: amd64
GOOS: darwin
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build darwin/amd64
- commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/um-darwin-amd64-$(git
@ -111,7 +111,7 @@ steps:
DRONE_GITEA_SERVER: https://git.unlock-music.dev
GITEA_API_KEY:
from_secret: GITEA_API_KEY
image: golang:1.22
image: golang:1.23
name: upload artifact
trigger:
event:
@ -130,7 +130,7 @@ steps:
- go test -v ./...
environment:
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go test
- commands:
- DIST_DIR=$(mktemp -d)
@ -143,7 +143,7 @@ steps:
GOARCH: amd64
GOOS: linux
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build linux/amd64
- commands:
- DIST_DIR=$(mktemp -d)
@ -156,7 +156,7 @@ steps:
GOARCH: arm64
GOOS: linux
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build linux/arm64
- commands:
- DIST_DIR=$(mktemp -d)
@ -168,7 +168,7 @@ steps:
GOARCH: "386"
GOOS: linux
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build linux/386
- commands:
- DIST_DIR=$(mktemp -d)
@ -181,7 +181,7 @@ steps:
GOARCH: amd64
GOOS: windows
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build windows/amd64
- commands:
- DIST_DIR=$(mktemp -d)
@ -194,7 +194,7 @@ steps:
GOARCH: arm64
GOOS: windows
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build windows/arm64
- commands:
- DIST_DIR=$(mktemp -d)
@ -207,7 +207,7 @@ steps:
GOARCH: "386"
GOOS: windows
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build windows/386
- commands:
- DIST_DIR=$(mktemp -d)
@ -220,7 +220,7 @@ steps:
GOARCH: amd64
GOOS: darwin
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build darwin/amd64
- commands:
- DIST_DIR=$(mktemp -d)
@ -233,11 +233,11 @@ steps:
GOARCH: arm64
GOOS: darwin
GOPROXY: https://goproxy.io,direct
image: golang:1.22
image: golang:1.23
name: go build darwin/arm64
- commands:
- mv dist/*.tar.gz dist/*.zip ./
image: golang:1.22
image: golang:1.23
name: prepare root
- image: plugins/gitea-release
name: create release

View File

@ -14,12 +14,23 @@ Original: Web Edition https://git.unlock-music.dev/um/web
- [x] All Algorithm Supported By `unlock-music/web`
- [x] Complete Metadata & Cover Image
## Hou to Build
## Release
- Requirements: **Golang 1.19**
[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`
### 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
- Drag the encrypted file to `um.exe` (Tested on Windows)

View File

@ -1,6 +1,7 @@
package ncm
import (
"go.uber.org/zap"
"strings"
"unlock-music.dev/cli/algo/common"
@ -17,9 +18,11 @@ type ncmMeta interface {
}
type ncmMetaMusic struct {
logger *zap.Logger
Format string `json:"format"`
MusicName string `json:"musicName"`
Artist [][]interface{} `json:"artist"`
Artist interface{} `json:"artist"`
Album string `json:"album"`
AlbumPicDocID interface{} `json:"albumPicDocId"`
AlbumPic string `json:"albumPic"`
@ -30,20 +33,34 @@ type ncmMetaMusic struct {
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 {
return m.AlbumPic
}
func (m *ncmMetaMusic) GetArtists() (artists []string) {
for _, artist := range m.Artist {
for _, item := range artist {
name, ok := item.(string)
if ok {
func (m *ncmMetaMusic) GetArtists() []string {
m.logger.Debug("ncm artists", zap.Any("artists", m.Artist))
var artists []string = nil
if jsonArtists, ok := m.Artist.([][]string); ok {
for _, artist := range jsonArtists {
for _, name := range artist {
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 {

View File

@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"go.uber.org/zap"
"io"
"net/http"
"strings"
@ -30,10 +31,11 @@ var (
)
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 {
logger *zap.Logger
rd io.ReadSeeker // rd is the original file reader
offset int
@ -74,7 +76,7 @@ func (d *Decoder) Validate() error {
}
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)
@ -181,7 +183,7 @@ func (d *Decoder) readCoverData() error {
func (d *Decoder) parseMeta() error {
switch d.metaType {
case "music":
d.meta = new(ncmMetaMusic)
d.meta = newNcmMetaMusic(d.logger)
return json.Unmarshal(d.metaRaw, d.meta)
case "dj":
d.meta = new(ncmMetaDJ)

View File

@ -5,21 +5,19 @@ import (
"context"
"errors"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"io"
"os"
"os/signal"
"path"
"path/filepath"
"runtime"
"runtime/debug"
"sort"
"strings"
"time"
"github.com/fsnotify/fsnotify"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"unlock-music.dev/cli/algo/common"
_ "unlock-music.dev/cli/algo/kgm"
_ "unlock-music.dev/cli/algo/kwm"
@ -29,14 +27,13 @@ import (
_ "unlock-music.dev/cli/algo/xiami"
_ "unlock-music.dev/cli/algo/ximalaya"
"unlock-music.dev/cli/internal/ffmpeg"
"unlock-music.dev/cli/internal/logging"
"unlock-music.dev/cli/internal/sniff"
"unlock-music.dev/cli/internal/utils"
)
var AppVersion = "v0.2.8"
var AppVersion = "v0.2.11"
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() {
module, ok := debug.ReadBuildInfo()
@ -55,6 +52,7 @@ func main() {
&cli.StringFlag{Name: "qmc-mmkv-key", Aliases: []string{"key"}, Usage: "mmkv password (16 ascii chars)", Required: false},
&cli.BoolFlag{Name: "remove-source", Aliases: []string{"rs"}, Usage: "remove source file", Required: false, Value: false},
&cli.BoolFlag{Name: "skip-noop", Aliases: []string{"n"}, Usage: "skip noop decoder", Required: false, Value: true},
&cli.BoolFlag{Name: "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: "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},
@ -67,6 +65,7 @@ func main() {
HideHelpCommand: true,
UsageText: "um [-o /path/to/output/dir] [--extra-flags] [-i] /path/to/input",
}
err := app.Run(os.Args)
if err != nil {
logger.Fatal("run app failed", zap.Error(err))
@ -93,7 +92,27 @@ func printSupportedExtensions() {
}
}
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) {
logger = setupLogger(c.Bool("verbose"))
cwd, err := os.Getwd()
if err != nil {
return err
@ -115,6 +134,11 @@ func appMain(c *cli.Context) (err error) {
}
}
input, absErr := filepath.Abs(input)
if absErr != nil {
return fmt.Errorf("get abs path failed: %w", absErr)
}
output := c.String("output")
inputStat, err := os.Stat(input)
if err != nil {
@ -125,13 +149,18 @@ func appMain(c *cli.Context) (err error) {
if inputStat.IsDir() {
inputDir = input
} else {
inputDir = path.Dir(input)
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)
if err != nil {
@ -155,6 +184,7 @@ func appMain(c *cli.Context) (err error) {
}
proc := &processor{
logger: logger,
inputDir: inputDir,
outputDir: output,
skipNoopDecoder: c.Bool("skip-noop"),
@ -177,6 +207,7 @@ func appMain(c *cli.Context) (err error) {
}
type processor struct {
logger *zap.Logger
inputDir string
outputDir string
@ -268,6 +299,8 @@ func (p *processor) processDir(inputDir 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)
if len(allDec) == 0 {
return errors.New("skipping while no suitable decoder")
@ -406,7 +439,7 @@ func (p *processor) process(inputFile string, allDec []common.DecoderFactory) er
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
if err := ffmpeg.UpdateMeta(ctx, outPath, params); err != nil {
if err := ffmpeg.UpdateMeta(ctx, outPath, params, logger); err != nil {
return err
}
}

24
go.mod
View File

@ -1,26 +1,26 @@
module unlock-music.dev/cli
go 1.19
go 1.23.3
require (
github.com/fsnotify/fsnotify v1.7.0
github.com/fsnotify/fsnotify v1.8.0
github.com/go-flac/flacpicture v0.3.0
github.com/go-flac/flacvorbis v0.2.0
github.com/go-flac/go-flac v1.0.0
github.com/samber/lo v1.39.0
github.com/urfave/cli/v2 v2.27.1
github.com/samber/lo v1.47.0
github.com/urfave/cli/v2 v2.27.5
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.26.0
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
golang.org/x/text v0.17.0
unlock-music.dev/mmkv v0.0.0-20240424090133-31549c6a948b
golang.org/x/crypto v0.29.0
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/text v0.20.0
unlock-music.dev/mmkv v0.1.0
)
require (
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.23.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
golang.org/x/sys v0.27.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
)

41
go.sum
View File

@ -1,8 +1,13 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-flac/flacpicture v0.3.0 h1:LkmTxzFLIynwfhHiZsX0s8xcr3/u33MzvV89u+zOT8I=
github.com/go-flac/flacpicture v0.3.0/go.mod h1:DPbrzVYQ3fJcvSgLFp9HXIrEQEdfdk/+m0nQCzwodZI=
github.com/go-flac/flacvorbis v0.2.0 h1:KH0xjpkNTXFER4cszH4zeJxYcrHbUobz/RticWGOESs=
@ -10,38 +15,46 @@ github.com/go-flac/flacvorbis v0.2.0/go.mod h1:uIysHOtuU7OLGoCRG92bvnkg7QEqHx19q
github.com/go-flac/go-flac v1.0.0 h1:6qI9XOVLcO50xpzm3nXvO31BgDgHhnr/p/rER/K/doY=
github.com/go-flac/go-flac v1.0.0/go.mod h1:WnZhcpmq4u1UdZMNn9LYSoASpWOCMOoxXxcWEHSzkW8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
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=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
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=
unlock-music.dev/mmkv v0.0.0-20240424090133-0953e6901f3a h1:UW0sxgwsfGGC/SrKvvAbZ4HZyOQ3fqs8qr3lBxG6Fzo=
unlock-music.dev/mmkv v0.0.0-20240424090133-0953e6901f3a/go.mod h1:qr34SM3x8xRxyUfGzefH/rSi+DUXkQZcSfXY/yfuTeo=
unlock-music.dev/mmkv v0.0.0-20240424090133-31549c6a948b h1:VIJ0mDqj0OgX1ZvL9gbAH8kkqyrDlpVt5yUeGYSJ1/s=
unlock-music.dev/mmkv v0.0.0-20240424090133-31549c6a948b/go.mod h1:qr34SM3x8xRxyUfGzefH/rSi+DUXkQZcSfXY/yfuTeo=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
unlock-music.dev/mmkv v0.1.0 h1:hgUHo0gJVoiKZ6bOcFOw2LHFqNiefIe+jb5o0OyL720=
unlock-music.dev/mmkv v0.1.0/go.mod h1:qr34SM3x8xRxyUfGzefH/rSi+DUXkQZcSfXY/yfuTeo=

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"go.uber.org/zap"
"io"
"os"
"os/exec"
@ -43,9 +44,9 @@ type UpdateMetadataParams struct {
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" {
return updateMetaFlac(ctx, outPath, params)
return updateMetaFlac(ctx, outPath, params, logger.With(zap.String("module", "updateMetaFlac")))
} else {
return updateMetaFFmpeg(ctx, outPath, params)
}

View File

@ -2,6 +2,7 @@ package ffmpeg
import (
"context"
"go.uber.org/zap"
"mime"
"strings"
@ -11,7 +12,7 @@ import (
"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)
if err != nil {
return err
@ -62,16 +63,18 @@ func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams)
}
if m.AlbumArt != nil {
coverMime := mime.TypeByExtension(m.AlbumArtExt)
logger.Debug("cover image mime detect", zap.String("mime", coverMime))
cover, err := flacpicture.NewFromImageData(
flacpicture.PictureTypeFrontCover,
"Front cover",
m.AlbumArt,
mime.TypeByExtension(m.AlbumArtExt),
coverMime,
)
if err != nil {
return err
}
logger.Warn("failed to create flac cover", zap.Error(err))
} else {
coverBlock := cover.Marshal()
f.Meta = append(f.Meta, &coverBlock)
@ -85,6 +88,7 @@ func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams)
f.Meta[coverIdx] = &coverBlock
}
}
}
return f.Save(outPath)
}