From ca8c4aa078ddbce852e01b0a11c82a4c1564c076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Mon, 19 Oct 2026 23:43:47 +0900 Subject: [PATCH] feat: add flags to ignore known non-music file extensions and update processor logic to support this feature --- CHANGELOG.md | 4 +++- cmd/um/main.go | 36 +++++++++++++++++++++++++----------- cmd/um/non_music_ext.go | 21 +++++++++++++++++++++ 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 cmd/um/non_music_ext.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ece8f1..495d57a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [v0.2.20] - 2026-10-18 +## [v0.2.20] - 2026-10-20 ### Added - [#2] Support `.mflac2` / `.mgg2` extensions. - [#7] Load QMC ekeys from QQ Music Android `player_process_db` (`--qmc-android-db`). - [#8] Windows: auto-fetch QMC keys via `qmpc-mmkv-cli` (`--qmpc-mmkv-cli-exe`). +- [#5] `--ignore-known-non-music-ext` / `--no-ignore-known-non-music-ext` (default on): skip files with no extension or known non-music file. + ### Changed diff --git a/cmd/um/main.go b/cmd/um/main.go index 3ca7e7d..0c71969 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -56,6 +56,8 @@ func main() { &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: "skip-noop", Aliases: []string{"n"}, Usage: "skip noop decoder", Required: false, Value: true}, + &cli.BoolFlag{Name: "ignore-known-non-music-ext", Usage: "skip files with no extension or known non-music extensions (txt, mmkv, exe, dll)", Required: false, Value: true}, + &cli.BoolFlag{Name: "no-ignore-known-non-music-ext", Usage: "do not skip known non-music extensions", Required: false, Value: false}, &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}, @@ -204,14 +206,20 @@ func appMain(c *cli.Context) (err error) { kggDbPath = filepath.Join(os.Getenv("APPDATA"), "Kugou8", "KGMusicV3.db") } + ignoreKnownNonMusicExt := c.Bool("ignore-known-non-music-ext") + if c.Bool("no-ignore-known-non-music-ext") { + ignoreKnownNonMusicExt = false + } + proc := &processor{ - logger: logger, - inputDir: inputDir, - outputDir: output, - skipNoopDecoder: c.Bool("skip-noop"), - removeSource: c.Bool("remove-source"), - updateMetadata: c.Bool("update-metadata"), - overwriteOutput: c.Bool("overwrite"), + logger: logger, + inputDir: inputDir, + outputDir: output, + skipNoopDecoder: c.Bool("skip-noop"), + ignoreKnownNonMusicExt: ignoreKnownNonMusicExt, + removeSource: c.Bool("remove-source"), + updateMetadata: c.Bool("update-metadata"), + overwriteOutput: c.Bool("overwrite"), crypto: common.CryptoParams{ // KuGou @@ -240,10 +248,11 @@ type processor struct { inputDir string outputDir string - skipNoopDecoder bool - removeSource bool - updateMetadata bool - overwriteOutput bool + skipNoopDecoder bool + ignoreKnownNonMusicExt bool + removeSource bool + updateMetadata bool + overwriteOutput bool crypto common.CryptoParams } @@ -330,6 +339,11 @@ func (p *processor) processDir(inputDir string) error { } func (p *processor) processFile(filePath string) error { + if p.ignoreKnownNonMusicExt && isKnownNonMusicExt(filePath) { + p.logger.Debug("skip known non-music extension", zap.String("file", filePath)) + return nil + } + p.logger.Debug("processFile", zap.String("file", filePath), zap.String("inputDir", p.inputDir)) allDec := common.GetDecoder(filePath, p.skipNoopDecoder) diff --git a/cmd/um/non_music_ext.go b/cmd/um/non_music_ext.go new file mode 100644 index 0000000..bd48cae --- /dev/null +++ b/cmd/um/non_music_ext.go @@ -0,0 +1,21 @@ +package main + +import ( + "path/filepath" + "slices" + "strings" +) + +// knownNonMusicExts are common non-audio suffixes to skip when walking dirs. +var knownNonMusicExts = []string{ + "", + ".txt", + ".mmkv", + ".exe", + ".dll", +} + +func isKnownNonMusicExt(path string) bool { + ext := strings.ToLower(filepath.Ext(path)) + return slices.Contains(knownNonMusicExts, ext) +}