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
.idea
.DS_Store
/tmp/

View File

@ -105,31 +105,31 @@ func (c *Converter) InitParse() {
c.AddSection("Config")
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.AddBoolParam(&c.Options.Grayscale, "grayscale", c.Options.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.AddBoolParam(&c.Options.Crop, "crop", c.Options.Crop, "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.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.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.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.CropLimit, "crop-limit", c.Options.CropLimit, "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.AddIntParam(&c.Options.Brightness, "brightness", c.Options.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.AddBoolParam(&c.Options.AutoContrast, "autocontrast", c.Options.AutoContrast, "Improve contrast automatically")
c.AddBoolParam(&c.Options.AutoRotate, "autorotate", c.Options.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.KeepDoublePageIfSplit, "keepdoublepageifsplit", c.Options.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.NoBlankImage, "noblankimage", c.Options.NoBlankImage, "Remove blank image")
c.AddBoolParam(&c.Options.Manga, "manga", c.Options.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.AddIntParam(&c.Options.Image.Quality, "quality", c.Options.Image.Quality, "Quality of the image")
c.AddBoolParam(&c.Options.Image.GrayScale, "grayscale", c.Options.Image.GrayScale, "Grayscale image. Ideal for eInk devices.")
c.AddIntParam(&c.Options.Image.GrayScaleMode, "grayscale-mode", c.Options.Image.GrayScaleMode, "Grayscale Mode\n0 = normal\n1 = average\n2 = luminance")
c.AddBoolParam(&c.Options.Image.Crop.Enabled, "crop", c.Options.Image.Crop.Enabled, "Crop images")
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.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.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.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.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.Image.Crop.SkipIfLimitReached, "crop-skip-if-limit-reached", c.Options.Image.Crop.SkipIfLimitReached, "Crop skip if limit reached.")
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.Image.Contrast, "contrast", c.Options.Image.Contrast, "Contrast readjustment: between -100 and 100, > 0 more contrast, < 0 less contrast")
c.AddBoolParam(&c.Options.Image.AutoContrast, "autocontrast", c.Options.Image.AutoContrast, "Improve contrast automatically")
c.AddBoolParam(&c.Options.Image.AutoRotate, "autorotate", c.Options.Image.AutoRotate, "Auto Rotate 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.Image.KeepDoublePageIfSplit, "keepdoublepageifsplit", c.Options.Image.KeepDoublePageIfSplit, "Keep the double page if split")
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.Image.NoBlankImage, "noblankimage", c.Options.Image.NoBlankImage, "Remove blank image")
c.AddBoolParam(&c.Options.Image.Manga, "manga", c.Options.Image.Manga, "Manga mode (right to left)")
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.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.AddStringParam(&c.Options.ForegroundColor, "foreground-color", c.Options.ForegroundColor, "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.Foreground, "foreground-color", c.Options.Image.View.Color.Foreground, "Foreground color in hexadecimal format RGB. Black=000, White=FFF")
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.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")
@ -235,50 +235,50 @@ func (c *Converter) Parse() {
}
if c.Options.Auto {
c.Options.AutoContrast = true
c.Options.AutoRotate = true
c.Options.AutoSplitDoublePage = true
c.Options.Image.AutoContrast = true
c.Options.Image.AutoRotate = true
c.Options.Image.AutoSplitDoublePage = true
}
if c.Options.MaxQuality {
c.Options.Format = "png"
c.Options.Grayscale = false
c.Options.Image.GrayScale = false
c.Options.NoResize = true
} else if c.Options.BestQuality {
c.Options.Format = "jpeg"
c.Options.Quality = 100
c.Options.Grayscale = false
c.Options.Image.Quality = 100
c.Options.Image.GrayScale = false
c.Options.NoResize = true
} else if c.Options.GreatQuality {
c.Options.Format = "jpeg"
c.Options.Quality = 90
c.Options.Grayscale = true
c.Options.Image.Quality = 90
c.Options.Image.GrayScale = true
c.Options.NoResize = true
} else if c.Options.GoodQuality {
c.Options.Format = "jpeg"
c.Options.Quality = 90
c.Options.Grayscale = true
c.Options.Image.Quality = 90
c.Options.Image.GrayScale = true
c.Options.NoResize = false
}
if c.Options.NoFilter {
c.Options.Crop = false
c.Options.Brightness = 0
c.Options.Contrast = 0
c.Options.AutoContrast = false
c.Options.AutoRotate = false
c.Options.NoBlankImage = false
c.Options.Image.Crop.Enabled = false
c.Options.Image.Brightness = 0
c.Options.Image.Contrast = 0
c.Options.Image.AutoContrast = false
c.Options.Image.AutoRotate = false
c.Options.Image.NoBlankImage = false
c.Options.NoResize = true
}
if c.Options.AppleBookCompatibility {
c.Options.AutoSplitDoublePage = true
c.Options.KeepDoublePageIfSplit = false
c.Options.KeepSplitDoublePageAspect = true
c.Options.Image.AutoSplitDoublePage = true
c.Options.Image.KeepDoublePageIfSplit = false
c.Options.Image.KeepSplitDoublePageAspect = true
}
if c.Options.PortraitOnly {
c.Options.KeepSplitDoublePageAspect = false
c.Options.Image.KeepSplitDoublePageAspect = false
}
}
@ -352,12 +352,12 @@ func (c *Converter) Validate() error {
}
// 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")
}
// 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")
}
@ -368,11 +368,11 @@ func (c *Converter) Validate() error {
// Color
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}")
}
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}")
}
@ -392,12 +392,12 @@ func (c *Converter) Validate() error {
}
// 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")
}
// 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")
}

View File

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

View File

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

View File

@ -1,8 +1,11 @@
package epuboptions
type Crop struct {
Enabled bool
Left, Up, Right, Bottom int
Limit int
SkipIfLimitReached bool
Enabled bool `yaml:"enabled"`
Left int `yaml:"left"`
Up int `yaml:"up"`
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
type EPUBOptions struct {
Input string
Output string
Title string
TitlePage int
Author string
LimitMb int
StripFirstDirectoryFromToc bool
Dry bool
DryVerbose bool
SortPathMode int
Quiet bool
Json bool
Workers int
Image Image
// Output
Input string `yaml:"-"`
Output string `yaml:"-"`
Author string `yaml:"-"`
Title string `yaml:"-"`
//Config
TitlePage int `yaml:"title_page"`
LimitMb int `yaml:"limit_mb"`
StripFirstDirectoryFromToc bool `yaml:"strip_first_directory"`
SortPathMode int `yaml:"sort_path_mode"`
Image Image `yaml:"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) {

View File

@ -1,24 +1,24 @@
package epuboptions
type Image struct {
Crop Crop
Quality int
Brightness int
Contrast int
AutoContrast bool
AutoRotate bool
AutoSplitDoublePage bool
KeepDoublePageIfSplit bool
KeepSplitDoublePageAspect bool
NoBlankImage bool
Manga bool
HasCover bool
View View
GrayScale bool
GrayScaleMode int
Resize bool
Format string
AppleBookCompatibility bool
Crop Crop `yaml:"crop"`
Quality int `yaml:"quality"`
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"`
View View `yaml:"view"`
GrayScale bool `yaml:"grayscale"`
GrayScaleMode int `yaml:"grayscale_mode"` // 0 = normal, 1 = average, 2 = luminance
Resize bool `yaml:"resize"`
Format string `yaml:"format"`
AppleBookCompatibility bool `yaml:"apple_book_compatibility"`
}
func (i Image) MediaType() string {

View File

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

35
main.go
View File

@ -130,6 +130,15 @@ func generate(cmd *converter.Converter) {
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{
Input: cmd.Options.Input,
Output: cmd.Options.Output,
@ -145,38 +154,12 @@ func generate(cmd *converter.Converter) {
Quiet: cmd.Options.Quiet,
Json: cmd.Options.Json,
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{
Width: profile.Width,
Height: profile.Height,
AspectRatio: cmd.Options.AspectRatio,
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,
Format: cmd.Options.Format,
AppleBookCompatibility: cmd.Options.AppleBookCompatibility,