feat: add flags to ignore known non-music file extensions and update processor logic to support this feature

This commit is contained in:
鲁树人
2026-10-19 23:43:47 +09:00
parent 06e97975d8
commit ca8c4aa078
3 changed files with 49 additions and 12 deletions
+3 -1
View File
@@ -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
+25 -11
View File
@@ -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)
+21
View File
@@ -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)
}