add apple book compatibility mode

This commit is contained in:
Celogeek 2023-09-24 13:36:17 +02:00
parent cd73416a5c
commit 77d6600a36
Signed by: celogeek
SSH Key Fingerprint: SHA256:DEDfxIK2nUWXbslbRkww3zsauDjhWHlTXar+ak4lDJ4
7 changed files with 209 additions and 174 deletions

346
README.md
View File

@ -25,6 +25,7 @@ EPUB is now support by Amazon through [SendToKindle](https://www.amazon.com/gp/s
- 3 sorting methods (depending on your source, you can ensure the page go in the right order)
- Save and reuse your own perfect settings
- Multi tasks for fast conversion
- Apple Book Compatibility Mode
When you read the comic on a Kindle, you can customize how you read it with the `Aa` button:
- Landscape / Portrait
@ -135,34 +136,35 @@ $ go-comic-converter -input ~/Downloads/mymanga.cbr -profile SR -auto -manga -li
Go Comic Converter
Options:
Input : ~/Downloads/mymanga.cbr
Output : ~/Downloads/mymanga.epub
Author : GO Comic Converter
Title : mymanga
Workers : 8
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 90
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc: true
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : 1:1.60
Portrait Only : false
Title Page : always
Input : ~/Downloads/mymanga.cbr
Output : ~/Downloads/mymanga.epub
Author : GO Comic Converter
Title : mymanga
Workers : 8
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 90
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc : true
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : 1:1.60
Portrait Only : false
Title Page : always
Apple Book Compatibility : false
TOC:
- mymanga
@ -182,34 +184,35 @@ $ go-comic-converter -input ~/Downloads/mymanga.cbr -profile SR -auto -manga -li
Go Comic Converter
Options:
Input : ~/Downloads/mymanga.cbr
Output : ~/Downloads/mymanga.epub
Author : GO Comic Converter
Title : mymanga
Workers : 8
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 90
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc: true
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : 1:1.60
Portrait Only : false
Title Page : always
Input : ~/Downloads/mymanga.cbr
Output : ~/Downloads/mymanga.epub
Author : GO Comic Converter
Title : mymanga
Workers : 8
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 90
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc : true
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : 1:1.60
Portrait Only : false
Title Page : always
Apple Book Compatibility : false
TOC:
- mymanga
@ -244,28 +247,29 @@ $ go-comic-converter -show
Go Comic Converter
Options:
Profile :
Format : jpeg
Quality : 85
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : false
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : false
HasCover : true
StripFirstDirectoryFromToc: false
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : auto
Portrait Only : false
Title Page : always
Profile :
Format : jpeg
Quality : 85
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : false
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : false
HasCover : true
StripFirstDirectoryFromToc : false
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : auto
Portrait Only : false
Title Page : always
Apple Book Compatibility : false
```
### Change default settings
@ -275,29 +279,30 @@ $ go-comic-converter -manga -auto -profile SR -limitmb 200 -save
Go Comic Converter
Options:
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 85
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : true
AutoSplitDoublePage : true
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc: false
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : auto
Portrait Only : false
Title Page : always
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 85
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : true
AutoSplitDoublePage : true
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc : false
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : auto
Portrait Only : false
Title Page : always
Apple Book Compatibility : false
Saving to ~/.go-comic-converter.yaml
```
@ -307,29 +312,30 @@ If you want to change a setting, you can change only one of them
$ go-comic-converter -manga=0 -save
Options:
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 85
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : true
AutoSplitDoublePage : true
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : false
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc: false
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : auto
Portrait Only : false
Title Page : always
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 85
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : true
AutoSplitDoublePage : true
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : false
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc : false
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : auto
Portrait Only : false
Title Page : always
Apple Book Compatibility : false
Saving to ~/.go-comic-converter.yaml
```
@ -343,27 +349,28 @@ Go Comic Converter
Options:
Profile :
Format : jpeg
Quality : 85
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : false
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : false
HasCover : true
StripFirstDirectoryFromToc: false
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : auto
Portrait Only : false
Title Page : always
Format : jpeg
Quality : 85
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : false
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : false
HasCover : true
StripFirstDirectoryFromToc : false
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : auto
Portrait Only : false
Title Page : always
Apple Book Compatibility : false
Reset default to ~/.go-comic-converter.yaml
```
@ -377,28 +384,29 @@ $ go-comic-converter -reset
$ go-comic-converter -profile SR -quality 90 -autocontrast -manga -strip -aspect-ratio 1.6 -save
Options:
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 90
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : true
HasCover : true
StripFirstDirectoryFromToc: true
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : 1:1.60
Portrait Only : false
Title Page : always
Profile : SR - Standard Resolution - 1200x1920
Format : jpeg
Quality : 90
Grayscale : true
Grayscale Mode : normal
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true
AutoRotate : false
AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true
NoBlankImage : true
Manga : true
HasCover : true
StripFirstDirectoryFromToc : true
SortPathMode : path=alphanum, file=alpha
Foreground Color : #000
Background Color : #FFF
Resize : true
Aspect Ratio : 1:1.60
Portrait Only : false
Title Page : always
Apple Book Compatibility : false
Saving to ~/.go-comic-converter.yaml
```
@ -548,6 +556,10 @@ Shortcut:
-goodquality
Max quality: grayscale jpg q90
Compatibility:
-applebookcompatibility
Apple book compatibility
Other:
-workers int (default number of CPUs)
Number of workers

View File

@ -147,6 +147,9 @@ func (c *Converter) InitParse() {
c.AddBoolParam(&c.Options.GreatQuality, "greatquality", false, "Max quality: grayscale jpg q90 + noresize")
c.AddBoolParam(&c.Options.GoodQuality, "goodquality", false, "Max quality: grayscale jpg q90")
c.AddSection("Compatibility")
c.AddBoolParam(&c.Options.AppleBookCompatibility, "applebookcompatibility", c.Options.AppleBookCompatibility, "Apple book compatibility")
c.AddSection("Other")
c.AddIntParam(&c.Options.Workers, "workers", runtime.NumCPU(), "Number of workers")
c.AddBoolParam(&c.Options.Dry, "dry", false, "Dry run to show all options")
@ -264,6 +267,11 @@ func (c *Converter) Parse() {
c.Options.NoBlankImage = false
c.Options.NoResize = true
}
if c.Options.AppleBookCompatibility {
c.Options.AutoSplitDoublePage = true
c.Options.KeepDoublePageIfSplitted = false
}
}
// Check parameters

View File

@ -48,6 +48,7 @@ type Options struct {
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
@ -209,8 +210,8 @@ func (o *Options) ShowConfig() string {
{"Contrast", o.Contrast, o.Contrast != 0},
{"AutoContrast", o.AutoContrast, true},
{"AutoRotate", o.AutoRotate, true},
{"AutoSplitDoublePage", o.AutoSplitDoublePage, true},
{"KeepDoublePageIfSplitted", o.KeepDoublePageIfSplitted, o.AutoSplitDoublePage},
{"AutoSplitDoublePage", o.AutoSplitDoublePage, o.PortraitOnly || !o.AppleBookCompatibility},
{"KeepDoublePageIfSplitted", o.KeepDoublePageIfSplitted, (o.PortraitOnly || !o.AppleBookCompatibility) && o.AutoSplitDoublePage},
{"NoBlankImage", o.NoBlankImage, true},
{"Manga", o.Manga, true},
{"HasCover", o.HasCover, true},
@ -223,9 +224,10 @@ func (o *Options) ShowConfig() string {
{"Aspect Ratio", aspectRatio, true},
{"Portrait Only", o.PortraitOnly, true},
{"Title Page", titlePage, true},
{"Apple Book Compatibility", o.AppleBookCompatibility, !o.PortraitOnly},
} {
if v.Condition {
b.WriteString(fmt.Sprintf("\n %-26s: %v", v.Key, v.Value))
b.WriteString(fmt.Sprintf("\n %-30s: %v", v.Key, v.Value))
}
}
return b.String()

View File

@ -38,6 +38,7 @@ type Image struct {
GrayScaleMode int
Resize bool
Format string
AppleBookCompatibility bool
}
type Options struct {

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<display_options>
<platform name="*">
<option name="interactive">true</option>
<option name="fixed-layout">true</option>
<option name="open-to-spread">true</option>
</platform>
</display_options>

View File

@ -192,6 +192,9 @@ func getManifest(o *ContentOptions) []tag {
// spine part of the content
func getSpineAuto(o *ContentOptions) []tag {
isOnTheRight := !o.ImageOptions.Manga
if o.ImageOptions.AppleBookCompatibility {
isOnTheRight = !isOnTheRight
}
getSpread := func(isDoublePage bool) string {
isOnTheRight = !isOnTheRight
if isDoublePage {
@ -211,10 +214,16 @@ func getSpineAuto(o *ContentOptions) []tag {
spine := []tag{}
if o.HasTitlePage {
spine = append(spine,
tag{"itemref", tagAttrs{"idref": "space_title", "properties": getSpreadBlank()}, ""},
tag{"itemref", tagAttrs{"idref": "page_title", "properties": getSpread(false)}, ""},
)
if !o.ImageOptions.AppleBookCompatibility {
spine = append(spine,
tag{"itemref", tagAttrs{"idref": "space_title", "properties": getSpreadBlank()}, ""},
tag{"itemref", tagAttrs{"idref": "page_title", "properties": getSpread(false)}, ""},
)
} else {
spine = append(spine,
tag{"itemref", tagAttrs{"idref": "page_title", "properties": getSpread(true)}, ""},
)
}
}
for _, img := range o.Images {
if (img.DoublePage || img.Part == 1) && o.ImageOptions.Manga == isOnTheRight {

View File

@ -130,6 +130,7 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
GrayScaleMode: cmd.Options.GrayscaleMode,
Resize: !cmd.Options.NoResize,
Format: cmd.Options.Format,
AppleBookCompatibility: cmd.Options.AppleBookCompatibility,
},
}).Write(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)