mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2026-07-22 11:25:40 +02:00
feat(converter): add --keep-filenames flag to preserve original page filenames
Add a new `--keep-filenames` boolean flag (no shorthand, default false) on both `optimize` and `watch` commands. When enabled, page entries in the output CBZ preserve their original base filenames instead of being renumbered to `%04d` sequential indices. Extension is swapped on format conversion (e.g. `001.png` → `001.webp`), split pages get `-NN` suffixes on the original stem, and duplicate base names fall back to `<stem>_<index>.<ext>`. Watch mode supports the flag via the `keep-filenames` viper config key. Design: data-driven `OriginalName` field on `manga.PageFile`, set at extraction in `cbz_loader.ExtractChapter`. The `Converter` interface is unchanged. Flag off → behavior identical to before. Closes #216
This commit is contained in:
@@ -21,7 +21,12 @@ type OptimizeOptions struct {
|
||||
Quality uint8
|
||||
Override bool
|
||||
Split bool
|
||||
Timeout time.Duration
|
||||
// KeepFilenames preserves the original base filename of each page inside
|
||||
// the output CBZ (with the extension swapped for format conversion)
|
||||
// instead of the historical %04d sequential naming. Off by default so
|
||||
// existing behavior is unchanged.
|
||||
KeepFilenames bool
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// Optimize optimizes a CBZ/CBR file using the specified converter.
|
||||
@@ -38,6 +43,7 @@ func Optimize(options *OptimizeOptions) error {
|
||||
Uint8("quality", options.Quality).
|
||||
Bool("override", options.Override).
|
||||
Bool("split", options.Split).
|
||||
Bool("keep_filenames", options.KeepFilenames).
|
||||
Msg("Optimization parameters")
|
||||
|
||||
// Step 1: Fast conversion check before extracting (new requirement)
|
||||
@@ -64,7 +70,7 @@ func Optimize(options *OptimizeOptions) error {
|
||||
extractCtx = context.Background()
|
||||
}
|
||||
|
||||
chapter, err := cbz.ExtractChapter(extractCtx, options.Path)
|
||||
chapter, err := cbz.ExtractChapter(extractCtx, options.Path, options.KeepFilenames)
|
||||
if err != nil {
|
||||
log.Error().Str("file", options.Path).Err(err).Msg("Failed to extract chapter")
|
||||
return fmt.Errorf("failed to extract chapter: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user