This commit is contained in:
Celogeek 2024-10-27 15:53:18 +01:00
parent c9df70fbb3
commit fbaa91aa5c
Signed by: celogeek
GPG Key ID: 850295F3747870DD
9 changed files with 199 additions and 228 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.vscode .vscode
.idea .idea
.DS_Store
/tmp/

View File

@ -105,31 +105,31 @@ func (c *Converter) InitParse() {
c.AddSection("Config") c.AddSection("Config")
c.AddStringParam(&c.Options.Profile, "profile", c.Options.Profile, "Profile to use: \n"+c.Options.AvailableProfiles()) c.AddStringParam(&c.Options.Profile, "profile", c.Options.Profile, "Profile to use: \n"+c.Options.AvailableProfiles())
c.AddIntParam(&c.Options.Quality, "quality", c.Options.Quality, "Quality of the image") c.AddIntParam(&c.Options.Image.Quality, "quality", c.Options.Image.Quality, "Quality of the image")
c.AddBoolParam(&c.Options.Grayscale, "grayscale", c.Options.Grayscale, "Grayscale image. Ideal for eInk devices.") c.AddBoolParam(&c.Options.Image.GrayScale, "grayscale", c.Options.Image.GrayScale, "Grayscale image. Ideal for eInk devices.")
c.AddIntParam(&c.Options.GrayscaleMode, "grayscale-mode", c.Options.GrayscaleMode, "Grayscale Mode\n0 = normal\n1 = average\n2 = luminance") c.AddIntParam(&c.Options.Image.GrayScaleMode, "grayscale-mode", c.Options.Image.GrayScaleMode, "Grayscale Mode\n0 = normal\n1 = average\n2 = luminance")
c.AddBoolParam(&c.Options.Crop, "crop", c.Options.Crop, "Crop images") c.AddBoolParam(&c.Options.Image.Crop.Enabled, "crop", c.Options.Image.Crop.Enabled, "Crop images")
c.AddIntParam(&c.Options.CropRatioLeft, "crop-ratio-left", c.Options.CropRatioLeft, "Crop ratio left: ratio of pixels allow to be non blank while cutting on the left.") c.AddIntParam(&c.Options.Image.Crop.Left, "crop-ratio-left", c.Options.Image.Crop.Left, "Crop ratio left: ratio of pixels allow to be non blank while cutting on the left.")
c.AddIntParam(&c.Options.CropRatioUp, "crop-ratio-up", c.Options.CropRatioUp, "Crop ratio up: ratio of pixels allow to be non blank while cutting on the top.") c.AddIntParam(&c.Options.Image.Crop.Up, "crop-ratio-up", c.Options.Image.Crop.Up, "Crop ratio up: ratio of pixels allow to be non blank while cutting on the top.")
c.AddIntParam(&c.Options.CropRatioRight, "crop-ratio-right", c.Options.CropRatioRight, "Crop ratio right: ratio of pixels allow to be non blank while cutting on the right.") c.AddIntParam(&c.Options.Image.Crop.Right, "crop-ratio-right", c.Options.Image.Crop.Right, "Crop ratio right: ratio of pixels allow to be non blank while cutting on the right.")
c.AddIntParam(&c.Options.CropRatioBottom, "crop-ratio-bottom", c.Options.CropRatioBottom, "Crop ratio bottom: ratio of pixels allow to be non blank while cutting on the bottom.") c.AddIntParam(&c.Options.Image.Crop.Bottom, "crop-ratio-bottom", c.Options.Image.Crop.Bottom, "Crop ratio bottom: ratio of pixels allow to be non blank while cutting on the bottom.")
c.AddIntParam(&c.Options.CropLimit, "crop-limit", c.Options.CropLimit, "Crop limit: maximum number of cropping in percentage allowed. 0 mean unlimited.") c.AddIntParam(&c.Options.Image.Crop.Limit, "crop-limit", c.Options.Image.Crop.Limit, "Crop limit: maximum number of cropping in percentage allowed. 0 mean unlimited.")
c.AddBoolParam(&c.Options.CropSkipIfLimitReached, "crop-skip-if-limit-reached", c.Options.CropSkipIfLimitReached, "Crop skip if limit reached.") c.AddBoolParam(&c.Options.Image.Crop.SkipIfLimitReached, "crop-skip-if-limit-reached", c.Options.Image.Crop.SkipIfLimitReached, "Crop skip if limit reached.")
c.AddIntParam(&c.Options.Brightness, "brightness", c.Options.Brightness, "Brightness readjustment: between -100 and 100, > 0 lighter, < 0 darker") c.AddIntParam(&c.Options.Image.Brightness, "brightness", c.Options.Image.Brightness, "Brightness readjustment: between -100 and 100, > 0 lighter, < 0 darker")
c.AddIntParam(&c.Options.Contrast, "contrast", c.Options.Contrast, "Contrast readjustment: between -100 and 100, > 0 more contrast, < 0 less contrast") c.AddIntParam(&c.Options.Image.Contrast, "contrast", c.Options.Image.Contrast, "Contrast readjustment: between -100 and 100, > 0 more contrast, < 0 less contrast")
c.AddBoolParam(&c.Options.AutoContrast, "autocontrast", c.Options.AutoContrast, "Improve contrast automatically") c.AddBoolParam(&c.Options.Image.AutoContrast, "autocontrast", c.Options.Image.AutoContrast, "Improve contrast automatically")
c.AddBoolParam(&c.Options.AutoRotate, "autorotate", c.Options.AutoRotate, "Auto Rotate page when width > height") c.AddBoolParam(&c.Options.Image.AutoRotate, "autorotate", c.Options.Image.AutoRotate, "Auto Rotate page when width > height")
c.AddBoolParam(&c.Options.AutoSplitDoublePage, "autosplitdoublepage", c.Options.AutoSplitDoublePage, "Auto Split double page when width > height") c.AddBoolParam(&c.Options.Image.AutoSplitDoublePage, "autosplitdoublepage", c.Options.Image.AutoSplitDoublePage, "Auto Split double page when width > height")
c.AddBoolParam(&c.Options.KeepDoublePageIfSplit, "keepdoublepageifsplit", c.Options.KeepDoublePageIfSplit, "Keep the double page if split") c.AddBoolParam(&c.Options.Image.KeepDoublePageIfSplit, "keepdoublepageifsplit", c.Options.Image.KeepDoublePageIfSplit, "Keep the double page if split")
c.AddBoolParam(&c.Options.KeepSplitDoublePageAspect, "keepsplitdoublepageaspect", c.Options.KeepSplitDoublePageAspect, "Keep aspect of split part of a double page (best for landscape rendering)") c.AddBoolParam(&c.Options.Image.KeepSplitDoublePageAspect, "keepsplitdoublepageaspect", c.Options.Image.KeepSplitDoublePageAspect, "Keep aspect of split part of a double page (best for landscape rendering)")
c.AddBoolParam(&c.Options.NoBlankImage, "noblankimage", c.Options.NoBlankImage, "Remove blank image") c.AddBoolParam(&c.Options.Image.NoBlankImage, "noblankimage", c.Options.Image.NoBlankImage, "Remove blank image")
c.AddBoolParam(&c.Options.Manga, "manga", c.Options.Manga, "Manga mode (right to left)") c.AddBoolParam(&c.Options.Image.Manga, "manga", c.Options.Image.Manga, "Manga mode (right to left)")
c.AddBoolParam(&c.Options.HasCover, "hascover", c.Options.HasCover, "Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.") c.AddBoolParam(&c.Options.Image.HasCover, "hascover", c.Options.Image.HasCover, "Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.")
c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the EPUB: Default nolimit (0), Minimum 20") c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the EPUB: Default nolimit (0), Minimum 20")
c.AddBoolParam(&c.Options.StripFirstDirectoryFromToc, "strip", c.Options.StripFirstDirectoryFromToc, "Strip first directory from the TOC if only 1") c.AddBoolParam(&c.Options.StripFirstDirectoryFromToc, "strip", c.Options.StripFirstDirectoryFromToc, "Strip first directory from the TOC if only 1")
c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanumeric for path and alpha for file\n2 = alphanumeric for path and file") c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanumeric for path and alpha for file\n2 = alphanumeric for path and file")
c.AddStringParam(&c.Options.ForegroundColor, "foreground-color", c.Options.ForegroundColor, "Foreground color in hexadecimal format RGB. Black=000, White=FFF") c.AddStringParam(&c.Options.Image.View.Color.Foreground, "foreground-color", c.Options.Image.View.Color.Foreground, "Foreground color in hexadecimal format RGB. Black=000, White=FFF")
c.AddStringParam(&c.Options.BackgroundColor, "background-color", c.Options.BackgroundColor, "Background color in hexadecimal format RGB. Black=000, White=FFF, Light Gray=DDD, Dark Gray=777") c.AddStringParam(&c.Options.Image.View.Color.Background, "background-color", c.Options.Image.View.Color.Background, "Background color in hexadecimal format RGB. Black=000, White=FFF, Light Gray=DDD, Dark Gray=777")
c.AddBoolParam(&c.Options.NoResize, "noresize", c.Options.NoResize, "Do not reduce image size if exceed device size") c.AddBoolParam(&c.Options.NoResize, "noresize", c.Options.NoResize, "Do not reduce image size if exceed device size")
c.AddStringParam(&c.Options.Format, "format", c.Options.Format, "Format of output images: jpeg (lossy), png (lossless)") c.AddStringParam(&c.Options.Format, "format", c.Options.Format, "Format of output images: jpeg (lossy), png (lossless)")
c.AddFloatParam(&c.Options.AspectRatio, "aspect-ratio", c.Options.AspectRatio, "Aspect ratio (height/width) of the output\n -1 = same as device\n 0 = same as source\n1.6 = amazon advice for kindle") c.AddFloatParam(&c.Options.AspectRatio, "aspect-ratio", c.Options.AspectRatio, "Aspect ratio (height/width) of the output\n -1 = same as device\n 0 = same as source\n1.6 = amazon advice for kindle")
@ -235,50 +235,50 @@ func (c *Converter) Parse() {
} }
if c.Options.Auto { if c.Options.Auto {
c.Options.AutoContrast = true c.Options.Image.AutoContrast = true
c.Options.AutoRotate = true c.Options.Image.AutoRotate = true
c.Options.AutoSplitDoublePage = true c.Options.Image.AutoSplitDoublePage = true
} }
if c.Options.MaxQuality { if c.Options.MaxQuality {
c.Options.Format = "png" c.Options.Format = "png"
c.Options.Grayscale = false c.Options.Image.GrayScale = false
c.Options.NoResize = true c.Options.NoResize = true
} else if c.Options.BestQuality { } else if c.Options.BestQuality {
c.Options.Format = "jpeg" c.Options.Format = "jpeg"
c.Options.Quality = 100 c.Options.Image.Quality = 100
c.Options.Grayscale = false c.Options.Image.GrayScale = false
c.Options.NoResize = true c.Options.NoResize = true
} else if c.Options.GreatQuality { } else if c.Options.GreatQuality {
c.Options.Format = "jpeg" c.Options.Format = "jpeg"
c.Options.Quality = 90 c.Options.Image.Quality = 90
c.Options.Grayscale = true c.Options.Image.GrayScale = true
c.Options.NoResize = true c.Options.NoResize = true
} else if c.Options.GoodQuality { } else if c.Options.GoodQuality {
c.Options.Format = "jpeg" c.Options.Format = "jpeg"
c.Options.Quality = 90 c.Options.Image.Quality = 90
c.Options.Grayscale = true c.Options.Image.GrayScale = true
c.Options.NoResize = false c.Options.NoResize = false
} }
if c.Options.NoFilter { if c.Options.NoFilter {
c.Options.Crop = false c.Options.Image.Crop.Enabled = false
c.Options.Brightness = 0 c.Options.Image.Brightness = 0
c.Options.Contrast = 0 c.Options.Image.Contrast = 0
c.Options.AutoContrast = false c.Options.Image.AutoContrast = false
c.Options.AutoRotate = false c.Options.Image.AutoRotate = false
c.Options.NoBlankImage = false c.Options.Image.NoBlankImage = false
c.Options.NoResize = true c.Options.NoResize = true
} }
if c.Options.AppleBookCompatibility { if c.Options.AppleBookCompatibility {
c.Options.AutoSplitDoublePage = true c.Options.Image.AutoSplitDoublePage = true
c.Options.KeepDoublePageIfSplit = false c.Options.Image.KeepDoublePageIfSplit = false
c.Options.KeepSplitDoublePageAspect = true c.Options.Image.KeepSplitDoublePageAspect = true
} }
if c.Options.PortraitOnly { if c.Options.PortraitOnly {
c.Options.KeepSplitDoublePageAspect = false c.Options.Image.KeepSplitDoublePageAspect = false
} }
} }
@ -352,12 +352,12 @@ func (c *Converter) Validate() error {
} }
// Brightness // Brightness
if c.Options.Brightness < -100 || c.Options.Brightness > 100 { if c.Options.Image.Brightness < -100 || c.Options.Image.Brightness > 100 {
return errors.New("brightness should be between -100 and 100") return errors.New("brightness should be between -100 and 100")
} }
// Contrast // Contrast
if c.Options.Contrast < -100 || c.Options.Contrast > 100 { if c.Options.Image.Contrast < -100 || c.Options.Image.Contrast > 100 {
return errors.New("contrast should be between -100 and 100") return errors.New("contrast should be between -100 and 100")
} }
@ -368,11 +368,11 @@ func (c *Converter) Validate() error {
// Color // Color
colorRegex := regexp.MustCompile("^[0-9A-F]{3}$") colorRegex := regexp.MustCompile("^[0-9A-F]{3}$")
if !colorRegex.MatchString(c.Options.ForegroundColor) { if !colorRegex.MatchString(c.Options.Image.View.Color.Foreground) {
return errors.New("foreground color must have color format in hexadecimal: [0-9A-F]{3}") return errors.New("foreground color must have color format in hexadecimal: [0-9A-F]{3}")
} }
if !colorRegex.MatchString(c.Options.BackgroundColor) { if !colorRegex.MatchString(c.Options.Image.View.Color.Background) {
return errors.New("background color must have color format in hexadecimal: [0-9A-F]{3}") return errors.New("background color must have color format in hexadecimal: [0-9A-F]{3}")
} }
@ -392,12 +392,12 @@ func (c *Converter) Validate() error {
} }
// Grayscale Mode // Grayscale Mode
if c.Options.GrayscaleMode < 0 || c.Options.GrayscaleMode > 2 { if c.Options.Image.GrayScaleMode < 0 || c.Options.Image.GrayScaleMode > 2 {
return errors.New("grayscale mode should be 0, 1 or 2") return errors.New("grayscale mode should be 0, 1 or 2")
} }
// crop // crop
if c.Options.CropLimit < 0 || c.Options.CropLimit > 100 { if c.Options.Image.Crop.Limit < 0 || c.Options.Image.Crop.Limit > 100 {
return errors.New("crop limit should be between 0 and 100") return errors.New("crop limit should be between 0 and 100")
} }

View File

@ -10,49 +10,20 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epuboptions"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils" "github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
) )
type Options struct { type Options struct {
// Output epuboptions.EPUBOptions
Input string `yaml:"-"`
Output string `yaml:"-"`
Author string `yaml:"-"`
Title string `yaml:"-"`
// Config // Config
Profile string `yaml:"profile"` Profile string `yaml:"profile"`
Quality int `yaml:"quality"` NoResize bool `yaml:"noresize"`
Grayscale bool `yaml:"grayscale"` Format string `yaml:"format"`
GrayscaleMode int `yaml:"grayscale_mode"` // 0 = normal, 1 = average, 2 = luminance AspectRatio float64 `yaml:"aspect_ratio"`
Crop bool `yaml:"crop"` PortraitOnly bool `yaml:"portrait_only"`
CropRatioLeft int `yaml:"crop_ratio_left"` AppleBookCompatibility bool `yaml:"apple_book_compatibility"`
CropRatioUp int `yaml:"crop_ratio_up"`
CropRatioRight int `yaml:"crop_ratio_right"`
CropRatioBottom int `yaml:"crop_ratio_bottom"`
CropLimit int `yaml:"crop_limit"`
CropSkipIfLimitReached bool `yaml:"crop_skip_if_limit_reached"`
Brightness int `yaml:"brightness"`
Contrast int `yaml:"contrast"`
AutoContrast bool `yaml:"auto_contrast"`
AutoRotate bool `yaml:"auto_rotate"`
AutoSplitDoublePage bool `yaml:"auto_split_double_page"`
KeepDoublePageIfSplit bool `yaml:"keep_double_page_if_split"`
KeepSplitDoublePageAspect bool `yaml:"keep_split_double_page_aspect"`
NoBlankImage bool `yaml:"no_blank_image"`
Manga bool `yaml:"manga"`
HasCover bool `yaml:"has_cover"`
LimitMb int `yaml:"limit_mb"`
StripFirstDirectoryFromToc bool `yaml:"strip_first_directory_from_toc"`
SortPathMode int `yaml:"sort_path_mode"`
ForegroundColor string `yaml:"foreground_color"`
BackgroundColor string `yaml:"background_color"`
NoResize bool `yaml:"noresize"`
Format string `yaml:"format"`
AspectRatio float64 `yaml:"aspect_ratio"`
PortraitOnly bool `yaml:"portrait_only"`
AppleBookCompatibility bool `yaml:"apple_book_compatibility"`
TitlePage int `yaml:"title_page"`
// Default Config // Default Config
Show bool `yaml:"-"` Show bool `yaml:"-"`
@ -68,13 +39,8 @@ type Options struct {
GoodQuality bool `yaml:"-"` GoodQuality bool `yaml:"-"`
// Other // Other
Workers int `yaml:"-"` Version bool `yaml:"-"`
Dry bool `yaml:"-"` Help bool `yaml:"-"`
DryVerbose bool `yaml:"-"`
Quiet bool `yaml:"-"`
Json bool `yaml:"-"`
Version bool `yaml:"-"`
Help bool `yaml:"-"`
// Internal // Internal
profiles Profiles profiles Profiles
@ -83,24 +49,34 @@ type Options struct {
// NewOptions Initialize default options. // NewOptions Initialize default options.
func NewOptions() *Options { func NewOptions() *Options {
return &Options{ return &Options{
Profile: "SR", Profile: "SR",
Quality: 85, EPUBOptions: epuboptions.EPUBOptions{
Grayscale: true, Image: epuboptions.Image{
Crop: true, Quality: 85,
CropRatioLeft: 1, GrayScale: true,
CropRatioUp: 1, Crop: epuboptions.Crop{
CropRatioRight: 1, Enabled: true,
CropRatioBottom: 3, Left: 1,
NoBlankImage: true, Up: 1,
HasCover: true, Right: 1,
KeepDoublePageIfSplit: true, Bottom: 3,
KeepSplitDoublePageAspect: true, },
SortPathMode: 1, NoBlankImage: true,
ForegroundColor: "000", HasCover: true,
BackgroundColor: "FFF", KeepDoublePageIfSplit: true,
Format: "jpeg", KeepSplitDoublePageAspect: true,
TitlePage: 1, View: epuboptions.View{
profiles: NewProfiles(), Color: epuboptions.Color{
Foreground: "000",
Background: "FFF",
},
},
},
TitlePage: 1,
SortPathMode: 1,
},
Format: "jpeg",
profiles: NewProfiles(),
} }
} }
@ -137,49 +113,49 @@ func (o *Options) MarshalJSON() ([]byte, error) {
"workers": o.Workers, "workers": o.Workers,
"profile": o.GetProfile(), "profile": o.GetProfile(),
"format": o.Format, "format": o.Format,
"grayscale": o.Grayscale, "grayscale": o.Image.GrayScale,
"crop": o.Crop, "crop": o.Image.Crop.Enabled,
"autocontrast": o.AutoContrast, "autocontrast": o.Image.AutoContrast,
"autorotate": o.AutoRotate, "autorotate": o.Image.AutoRotate,
"noblankimage": o.NoBlankImage, "noblankimage": o.Image.NoBlankImage,
"manga": o.Manga, "manga": o.Image.Manga,
"hascover": o.HasCover, "hascover": o.Image.HasCover,
"stripfirstdirectoryfromtoc": o.StripFirstDirectoryFromToc, "stripfirstdirectoryfromtoc": o.StripFirstDirectoryFromToc,
"sortpathmode": o.SortPathMode, "sortpathmode": o.SortPathMode,
"foregroundcolor": o.ForegroundColor, "foregroundcolor": o.Image.View.Color.Foreground,
"backgroundcolor": o.BackgroundColor, "backgroundcolor": o.Image.View.Color.Background,
"resize": !o.NoResize, "resize": !o.NoResize,
"aspectratio": o.AspectRatio, "aspectratio": o.AspectRatio,
"portraitonly": o.PortraitOnly, "portraitonly": o.PortraitOnly,
"titlepage": o.TitlePage, "titlepage": o.TitlePage,
} }
if o.Format == "jpeg" { if o.Format == "jpeg" {
out["quality"] = o.Quality out["quality"] = o.Image.Quality
} }
if o.Grayscale { if o.Image.GrayScale {
out["grayscale_mode"] = o.GrayscaleMode out["grayscale_mode"] = o.Image.GrayScaleMode
} }
if o.Crop { if o.Image.Crop.Enabled {
out["crop_ratio"] = map[string]any{ out["crop_ratio"] = map[string]any{
"left": o.CropRatioLeft, "left": o.Image.Crop.Left,
"right": o.CropRatioRight, "right": o.Image.Crop.Right,
"up": o.CropRatioUp, "up": o.Image.Crop.Up,
"bottom": o.CropRatioBottom, "bottom": o.Image.Crop.Bottom,
} }
out["crop_limit"] = o.CropLimit out["crop_limit"] = o.Image.Crop.Limit
out["crop_skip_if_limit_reached"] = o.CropSkipIfLimitReached out["crop_skip_if_limit_reached"] = o.Image.Crop.SkipIfLimitReached
} }
if o.Brightness != 0 { if o.Image.Brightness != 0 {
out["brightness"] = o.Brightness out["brightness"] = o.Image.Brightness
} }
if o.Contrast != 0 { if o.Image.Contrast != 0 {
out["contrast"] = o.Contrast out["contrast"] = o.Image.Contrast
} }
if o.PortraitOnly || !o.AppleBookCompatibility { if o.PortraitOnly || !o.AppleBookCompatibility {
out["autosplitdoublepage"] = o.AutoSplitDoublePage out["autosplitdoublepage"] = o.Image.AutoSplitDoublePage
if o.AutoSplitDoublePage { if o.Image.AutoSplitDoublePage {
out["keepdoublepageifsplit"] = o.KeepDoublePageIfSplit out["keepdoublepageifsplit"] = o.Image.KeepDoublePageIfSplit
out["keepsplitdoublepageaspect"] = o.KeepSplitDoublePageAspect out["keepsplitdoublepageaspect"] = o.Image.KeepSplitDoublePageAspect
} }
} }
if o.LimitMb != 0 { if o.LimitMb != 0 {
@ -254,7 +230,7 @@ func (o *Options) ShowConfig() string {
} }
grayscaleMode := "normal" grayscaleMode := "normal"
switch o.GrayscaleMode { switch o.Image.GrayScaleMode {
case 1: case 1:
grayscaleMode = "average" grayscaleMode = "average"
case 2: case 2:
@ -269,33 +245,33 @@ func (o *Options) ShowConfig() string {
}{ }{
{"Profile", profileDesc, true}, {"Profile", profileDesc, true},
{"Format", o.Format, true}, {"Format", o.Format, true},
{"Quality", o.Quality, o.Format == "jpeg"}, {"Quality", o.Image.Quality, o.Format == "jpeg"},
{"Grayscale", o.Grayscale, true}, {"Grayscale", o.Image.GrayScale, true},
{"Grayscale mode", grayscaleMode, o.Grayscale}, {"Grayscale mode", grayscaleMode, o.Image.GrayScale},
{"Crop", o.Crop, true}, {"Crop", o.Image.Crop.Enabled, true},
{"Crop ratio", {"Crop ratio",
utils.IntToString(o.CropRatioLeft) + " Left - " + utils.IntToString(o.Image.Crop.Left) + " Left - " +
utils.IntToString(o.CropRatioUp) + " Up - " + utils.IntToString(o.Image.Crop.Up) + " Up - " +
utils.IntToString(o.CropRatioRight) + " Right - " + utils.IntToString(o.Image.Crop.Right) + " Right - " +
utils.IntToString(o.CropRatioBottom) + " Bottom - " + utils.IntToString(o.Image.Crop.Bottom) + " Bottom - " +
"Limit " + utils.IntToString(o.CropLimit) + "% - " + "Limit " + utils.IntToString(o.Image.Crop.Limit) + "% - " +
"Skip " + utils.BoolToString(o.CropSkipIfLimitReached), "Skip " + utils.BoolToString(o.Image.Crop.SkipIfLimitReached),
o.Crop}, o.Image.Crop.Enabled},
{"Brightness", o.Brightness, o.Brightness != 0}, {"Brightness", o.Image.Brightness, o.Image.Brightness != 0},
{"Contrast", o.Contrast, o.Contrast != 0}, {"Contrast", o.Image.Contrast, o.Image.Contrast != 0},
{"Auto contrast", o.AutoContrast, true}, {"Auto contrast", o.Image.AutoContrast, true},
{"Auto rotate", o.AutoRotate, true}, {"Auto rotate", o.Image.AutoRotate, true},
{"Auto split double page", o.AutoSplitDoublePage, o.PortraitOnly || !o.AppleBookCompatibility}, {"Auto split double page", o.Image.AutoSplitDoublePage, o.PortraitOnly || !o.AppleBookCompatibility},
{"Keep double page if split", o.KeepDoublePageIfSplit, (o.PortraitOnly || !o.AppleBookCompatibility) && o.AutoSplitDoublePage}, {"Keep double page if split", o.Image.KeepDoublePageIfSplit, (o.PortraitOnly || !o.AppleBookCompatibility) && o.Image.AutoSplitDoublePage},
{"Keep split double page aspect", o.KeepSplitDoublePageAspect, (o.PortraitOnly || !o.AppleBookCompatibility) && o.AutoSplitDoublePage}, {"Keep split double page aspect", o.Image.KeepSplitDoublePageAspect, (o.PortraitOnly || !o.AppleBookCompatibility) && o.Image.AutoSplitDoublePage},
{"No blank image", o.NoBlankImage, true}, {"No blank image", o.Image.NoBlankImage, true},
{"Manga", o.Manga, true}, {"Manga", o.Image.Manga, true},
{"Has cover", o.HasCover, true}, {"Has cover", o.Image.HasCover, true},
{"Limit", utils.IntToString(o.LimitMb) + " Mb", o.LimitMb != 0}, {"Limit", utils.IntToString(o.LimitMb) + " Mb", o.LimitMb != 0},
{"Strip first directory from toc", o.StripFirstDirectoryFromToc, true}, {"Strip first directory from toc", o.StripFirstDirectoryFromToc, true},
{"Sort path mode", sortpathmode, true}, {"Sort path mode", sortpathmode, true},
{"Foreground color", "#" + o.ForegroundColor, true}, {"Foreground color", "#" + o.Image.View.Color.Foreground, true},
{"Background color", "#" + o.BackgroundColor, true}, {"Background color", "#" + o.Image.View.Color.Background, true},
{"Resize", !o.NoResize, true}, {"Resize", !o.NoResize, true},
{"Aspect ratio", aspectRatio, true}, {"Aspect ratio", aspectRatio, true},
{"Portrait only", o.PortraitOnly, true}, {"Portrait only", o.PortraitOnly, true},

View File

@ -1,5 +1,6 @@
package epuboptions package epuboptions
type Color struct { type Color struct {
Foreground, Background string Foreground string
Background string
} }

View File

@ -1,8 +1,11 @@
package epuboptions package epuboptions
type Crop struct { type Crop struct {
Enabled bool Enabled bool `yaml:"enabled"`
Left, Up, Right, Bottom int Left int `yaml:"left"`
Limit int Up int `yaml:"up"`
SkipIfLimitReached bool Right int `yaml:"right"`
Bottom int `yaml:"bottom"`
Limit int `yaml:"limit"`
SkipIfLimitReached bool `yaml:"skip_if_limit_reached"`
} }

View File

@ -2,20 +2,25 @@
package epuboptions package epuboptions
type EPUBOptions struct { type EPUBOptions struct {
Input string // Output
Output string Input string `yaml:"-"`
Title string Output string `yaml:"-"`
TitlePage int Author string `yaml:"-"`
Author string Title string `yaml:"-"`
LimitMb int
StripFirstDirectoryFromToc bool //Config
Dry bool TitlePage int `yaml:"title_page"`
DryVerbose bool LimitMb int `yaml:"limit_mb"`
SortPathMode int StripFirstDirectoryFromToc bool `yaml:"strip_first_directory"`
Quiet bool SortPathMode int `yaml:"sort_path_mode"`
Json bool Image Image `yaml:"image"`
Workers int
Image Image // Other
Dry bool `yaml:"-"`
DryVerbose bool `yaml:"-"`
Quiet bool `yaml:"-"`
Json bool `yaml:"-"`
Workers int `yaml:"-"`
} }
func (o EPUBOptions) WorkersRatio(pct int) (nbWorkers int) { func (o EPUBOptions) WorkersRatio(pct int) (nbWorkers int) {

View File

@ -1,24 +1,24 @@
package epuboptions package epuboptions
type Image struct { type Image struct {
Crop Crop Crop Crop `yaml:"crop"`
Quality int Quality int `yaml:"quality"`
Brightness int Brightness int `yaml:"brightness"`
Contrast int Contrast int `yaml:"contrast"`
AutoContrast bool AutoContrast bool `yaml:"auto_contrast"`
AutoRotate bool AutoRotate bool `yaml:"auto_rotate"`
AutoSplitDoublePage bool AutoSplitDoublePage bool `yaml:"auto_split_double_page"`
KeepDoublePageIfSplit bool KeepDoublePageIfSplit bool `yaml:"keep_double_page_if_split"`
KeepSplitDoublePageAspect bool KeepSplitDoublePageAspect bool `yaml:"keep_split_double_page_aspect"`
NoBlankImage bool NoBlankImage bool `yaml:"no_blank_image"`
Manga bool Manga bool `yaml:"manga"`
HasCover bool HasCover bool `yaml:"has_cover"`
View View View View `yaml:"view"`
GrayScale bool GrayScale bool `yaml:"grayscale"`
GrayScaleMode int GrayScaleMode int `yaml:"grayscale_mode"` // 0 = normal, 1 = average, 2 = luminance
Resize bool Resize bool `yaml:"resize"`
Format string Format string `yaml:"format"`
AppleBookCompatibility bool AppleBookCompatibility bool `yaml:"apple_book_compatibility"`
} }
func (i Image) MediaType() string { func (i Image) MediaType() string {

View File

@ -5,10 +5,11 @@ import (
) )
type View struct { type View struct {
Width, Height int Width int
AspectRatio float64 Height int
PortraitOnly bool AspectRatio float64
Color Color PortraitOnly bool
Color Color `yaml:"color"`
} }
func (v View) Dimension() string { func (v View) Dimension() string {

35
main.go
View File

@ -130,6 +130,15 @@ func generate(cmd *converter.Converter) {
profile := cmd.Options.GetProfile() profile := cmd.Options.GetProfile()
if err := epub.New(cmd.Options.EPUBOptions).Write(); err != nil {
utils.Fatalf("Error: %v\n", err)
}
if !cmd.Options.Dry {
cmd.Stats()
}
return
if err := epub.New(epuboptions.EPUBOptions{ if err := epub.New(epuboptions.EPUBOptions{
Input: cmd.Options.Input, Input: cmd.Options.Input,
Output: cmd.Options.Output, Output: cmd.Options.Output,
@ -145,38 +154,12 @@ func generate(cmd *converter.Converter) {
Quiet: cmd.Options.Quiet, Quiet: cmd.Options.Quiet,
Json: cmd.Options.Json, Json: cmd.Options.Json,
Image: epuboptions.Image{ Image: epuboptions.Image{
Crop: epuboptions.Crop{
Enabled: cmd.Options.Crop,
Left: cmd.Options.CropRatioLeft,
Up: cmd.Options.CropRatioUp,
Right: cmd.Options.CropRatioRight,
Bottom: cmd.Options.CropRatioBottom,
Limit: cmd.Options.CropLimit,
SkipIfLimitReached: cmd.Options.CropSkipIfLimitReached,
},
Quality: cmd.Options.Quality,
Brightness: cmd.Options.Brightness,
Contrast: cmd.Options.Contrast,
AutoContrast: cmd.Options.AutoContrast,
AutoRotate: cmd.Options.AutoRotate,
AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage,
KeepDoublePageIfSplit: cmd.Options.KeepDoublePageIfSplit,
KeepSplitDoublePageAspect: cmd.Options.KeepSplitDoublePageAspect,
NoBlankImage: cmd.Options.NoBlankImage,
Manga: cmd.Options.Manga,
HasCover: cmd.Options.HasCover,
View: epuboptions.View{ View: epuboptions.View{
Width: profile.Width, Width: profile.Width,
Height: profile.Height, Height: profile.Height,
AspectRatio: cmd.Options.AspectRatio, AspectRatio: cmd.Options.AspectRatio,
PortraitOnly: cmd.Options.PortraitOnly, PortraitOnly: cmd.Options.PortraitOnly,
Color: epuboptions.Color{
Foreground: cmd.Options.ForegroundColor,
Background: cmd.Options.BackgroundColor,
},
}, },
GrayScale: cmd.Options.Grayscale,
GrayScaleMode: cmd.Options.GrayscaleMode,
Resize: !cmd.Options.NoResize, Resize: !cmd.Options.NoResize,
Format: cmd.Options.Format, Format: cmd.Options.Format,
AppleBookCompatibility: cmd.Options.AppleBookCompatibility, AppleBookCompatibility: cmd.Options.AppleBookCompatibility,