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) - 3 sorting methods (depending on your source, you can ensure the page go in the right order)
- Save and reuse your own perfect settings - Save and reuse your own perfect settings
- Multi tasks for fast conversion - 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: When you read the comic on a Kindle, you can customize how you read it with the `Aa` button:
- Landscape / Portrait - Landscape / Portrait
@ -135,34 +136,35 @@ $ go-comic-converter -input ~/Downloads/mymanga.cbr -profile SR -auto -manga -li
Go Comic Converter Go Comic Converter
Options: Options:
Input : ~/Downloads/mymanga.cbr Input : ~/Downloads/mymanga.cbr
Output : ~/Downloads/mymanga.epub Output : ~/Downloads/mymanga.epub
Author : GO Comic Converter Author : GO Comic Converter
Title : mymanga Title : mymanga
Workers : 8 Workers : 8
Profile : SR - Standard Resolution - 1200x1920 Profile : SR - Standard Resolution - 1200x1920
Format : jpeg Format : jpeg
Quality : 90 Quality : 90
Grayscale : true Grayscale : true
Grayscale Mode : normal Grayscale Mode : normal
Crop : true Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true AutoContrast : true
AutoRotate : false AutoRotate : false
AutoSplitDoublePage : false AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true KeepDoublePageIfSplitted : true
NoBlankImage : true NoBlankImage : true
Manga : true Manga : true
HasCover : true HasCover : true
LimitMb : 200 Mb LimitMb : 200 Mb
StripFirstDirectoryFromToc: true StripFirstDirectoryFromToc : true
SortPathMode : path=alphanum, file=alpha SortPathMode : path=alphanum, file=alpha
Foreground Color : #000 Foreground Color : #000
Background Color : #FFF Background Color : #FFF
Resize : true Resize : true
Aspect Ratio : 1:1.60 Aspect Ratio : 1:1.60
Portrait Only : false Portrait Only : false
Title Page : always Title Page : always
Apple Book Compatibility : false
TOC: TOC:
- mymanga - mymanga
@ -182,34 +184,35 @@ $ go-comic-converter -input ~/Downloads/mymanga.cbr -profile SR -auto -manga -li
Go Comic Converter Go Comic Converter
Options: Options:
Input : ~/Downloads/mymanga.cbr Input : ~/Downloads/mymanga.cbr
Output : ~/Downloads/mymanga.epub Output : ~/Downloads/mymanga.epub
Author : GO Comic Converter Author : GO Comic Converter
Title : mymanga Title : mymanga
Workers : 8 Workers : 8
Profile : SR - Standard Resolution - 1200x1920 Profile : SR - Standard Resolution - 1200x1920
Format : jpeg Format : jpeg
Quality : 90 Quality : 90
Grayscale : true Grayscale : true
Grayscale Mode : normal Grayscale Mode : normal
Crop : true Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true AutoContrast : true
AutoRotate : false AutoRotate : false
AutoSplitDoublePage : false AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true KeepDoublePageIfSplitted : true
NoBlankImage : true NoBlankImage : true
Manga : true Manga : true
HasCover : true HasCover : true
LimitMb : 200 Mb LimitMb : 200 Mb
StripFirstDirectoryFromToc: true StripFirstDirectoryFromToc : true
SortPathMode : path=alphanum, file=alpha SortPathMode : path=alphanum, file=alpha
Foreground Color : #000 Foreground Color : #000
Background Color : #FFF Background Color : #FFF
Resize : true Resize : true
Aspect Ratio : 1:1.60 Aspect Ratio : 1:1.60
Portrait Only : false Portrait Only : false
Title Page : always Title Page : always
Apple Book Compatibility : false
TOC: TOC:
- mymanga - mymanga
@ -244,28 +247,29 @@ $ go-comic-converter -show
Go Comic Converter Go Comic Converter
Options: Options:
Profile : Profile :
Format : jpeg Format : jpeg
Quality : 85 Quality : 85
Grayscale : true Grayscale : true
Grayscale Mode : normal Grayscale Mode : normal
Crop : true Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : false AutoContrast : false
AutoRotate : false AutoRotate : false
AutoSplitDoublePage : false AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true KeepDoublePageIfSplitted : true
NoBlankImage : true NoBlankImage : true
Manga : false Manga : false
HasCover : true HasCover : true
StripFirstDirectoryFromToc: false StripFirstDirectoryFromToc : false
SortPathMode : path=alphanum, file=alpha SortPathMode : path=alphanum, file=alpha
Foreground Color : #000 Foreground Color : #000
Background Color : #FFF Background Color : #FFF
Resize : true Resize : true
Aspect Ratio : auto Aspect Ratio : auto
Portrait Only : false Portrait Only : false
Title Page : always Title Page : always
Apple Book Compatibility : false
``` ```
### Change default settings ### Change default settings
@ -275,29 +279,30 @@ $ go-comic-converter -manga -auto -profile SR -limitmb 200 -save
Go Comic Converter Go Comic Converter
Options: Options:
Profile : SR - Standard Resolution - 1200x1920 Profile : SR - Standard Resolution - 1200x1920
Format : jpeg Format : jpeg
Quality : 85 Quality : 85
Grayscale : true Grayscale : true
Grayscale Mode : normal Grayscale Mode : normal
Crop : true Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true AutoContrast : true
AutoRotate : true AutoRotate : true
AutoSplitDoublePage : true AutoSplitDoublePage : true
KeepDoublePageIfSplitted : true KeepDoublePageIfSplitted : true
NoBlankImage : true NoBlankImage : true
Manga : true Manga : true
HasCover : true HasCover : true
LimitMb : 200 Mb LimitMb : 200 Mb
StripFirstDirectoryFromToc: false StripFirstDirectoryFromToc : false
SortPathMode : path=alphanum, file=alpha SortPathMode : path=alphanum, file=alpha
Foreground Color : #000 Foreground Color : #000
Background Color : #FFF Background Color : #FFF
Resize : true Resize : true
Aspect Ratio : auto Aspect Ratio : auto
Portrait Only : false Portrait Only : false
Title Page : always Title Page : always
Apple Book Compatibility : false
Saving to ~/.go-comic-converter.yaml 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 $ go-comic-converter -manga=0 -save
Options: Options:
Profile : SR - Standard Resolution - 1200x1920 Profile : SR - Standard Resolution - 1200x1920
Format : jpeg Format : jpeg
Quality : 85 Quality : 85
Grayscale : true Grayscale : true
Grayscale Mode : normal Grayscale Mode : normal
Crop : true Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true AutoContrast : true
AutoRotate : true AutoRotate : true
AutoSplitDoublePage : true AutoSplitDoublePage : true
KeepDoublePageIfSplitted : true KeepDoublePageIfSplitted : true
NoBlankImage : true NoBlankImage : true
Manga : false Manga : false
HasCover : true HasCover : true
LimitMb : 200 Mb LimitMb : 200 Mb
StripFirstDirectoryFromToc: false StripFirstDirectoryFromToc : false
SortPathMode : path=alphanum, file=alpha SortPathMode : path=alphanum, file=alpha
Foreground Color : #000 Foreground Color : #000
Background Color : #FFF Background Color : #FFF
Resize : true Resize : true
Aspect Ratio : auto Aspect Ratio : auto
Portrait Only : false Portrait Only : false
Title Page : always Title Page : always
Apple Book Compatibility : false
Saving to ~/.go-comic-converter.yaml Saving to ~/.go-comic-converter.yaml
``` ```
@ -343,27 +349,28 @@ Go Comic Converter
Options: Options:
Profile : Profile :
Format : jpeg Format : jpeg
Quality : 85 Quality : 85
Grayscale : true Grayscale : true
Grayscale Mode : normal Grayscale Mode : normal
Crop : true Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : false AutoContrast : false
AutoRotate : false AutoRotate : false
AutoSplitDoublePage : false AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true KeepDoublePageIfSplitted : true
NoBlankImage : true NoBlankImage : true
Manga : false Manga : false
HasCover : true HasCover : true
StripFirstDirectoryFromToc: false StripFirstDirectoryFromToc : false
SortPathMode : path=alphanum, file=alpha SortPathMode : path=alphanum, file=alpha
Foreground Color : #000 Foreground Color : #000
Background Color : #FFF Background Color : #FFF
Resize : true Resize : true
Aspect Ratio : auto Aspect Ratio : auto
Portrait Only : false Portrait Only : false
Title Page : always Title Page : always
Apple Book Compatibility : false
Reset default to ~/.go-comic-converter.yaml 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 $ go-comic-converter -profile SR -quality 90 -autocontrast -manga -strip -aspect-ratio 1.6 -save
Options: Options:
Profile : SR - Standard Resolution - 1200x1920 Profile : SR - Standard Resolution - 1200x1920
Format : jpeg Format : jpeg
Quality : 90 Quality : 90
Grayscale : true Grayscale : true
Grayscale Mode : normal Grayscale Mode : normal
Crop : true Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
AutoContrast : true AutoContrast : true
AutoRotate : false AutoRotate : false
AutoSplitDoublePage : false AutoSplitDoublePage : false
KeepDoublePageIfSplitted : true KeepDoublePageIfSplitted : true
NoBlankImage : true NoBlankImage : true
Manga : true Manga : true
HasCover : true HasCover : true
StripFirstDirectoryFromToc: true StripFirstDirectoryFromToc : true
SortPathMode : path=alphanum, file=alpha SortPathMode : path=alphanum, file=alpha
Foreground Color : #000 Foreground Color : #000
Background Color : #FFF Background Color : #FFF
Resize : true Resize : true
Aspect Ratio : 1:1.60 Aspect Ratio : 1:1.60
Portrait Only : false Portrait Only : false
Title Page : always Title Page : always
Apple Book Compatibility : false
Saving to ~/.go-comic-converter.yaml Saving to ~/.go-comic-converter.yaml
``` ```
@ -548,6 +556,10 @@ Shortcut:
-goodquality -goodquality
Max quality: grayscale jpg q90 Max quality: grayscale jpg q90
Compatibility:
-applebookcompatibility
Apple book compatibility
Other: Other:
-workers int (default number of CPUs) -workers int (default number of CPUs)
Number of workers 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.GreatQuality, "greatquality", false, "Max quality: grayscale jpg q90 + noresize")
c.AddBoolParam(&c.Options.GoodQuality, "goodquality", false, "Max quality: grayscale jpg q90") 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.AddSection("Other")
c.AddIntParam(&c.Options.Workers, "workers", runtime.NumCPU(), "Number of workers") c.AddIntParam(&c.Options.Workers, "workers", runtime.NumCPU(), "Number of workers")
c.AddBoolParam(&c.Options.Dry, "dry", false, "Dry run to show all options") 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.NoBlankImage = false
c.Options.NoResize = true c.Options.NoResize = true
} }
if c.Options.AppleBookCompatibility {
c.Options.AutoSplitDoublePage = true
c.Options.KeepDoublePageIfSplitted = false
}
} }
// Check parameters // Check parameters

View File

@ -48,6 +48,7 @@ type Options struct {
Format string `yaml:"format"` Format string `yaml:"format"`
AspectRatio float64 `yaml:"aspect_ratio"` AspectRatio float64 `yaml:"aspect_ratio"`
PortraitOnly bool `yaml:"portrait_only"` PortraitOnly bool `yaml:"portrait_only"`
AppleBookCompatibility bool `yaml:"apple_book_compatibility"`
TitlePage int `yaml:"title_page"` TitlePage int `yaml:"title_page"`
// Default Config // Default Config
@ -209,8 +210,8 @@ func (o *Options) ShowConfig() string {
{"Contrast", o.Contrast, o.Contrast != 0}, {"Contrast", o.Contrast, o.Contrast != 0},
{"AutoContrast", o.AutoContrast, true}, {"AutoContrast", o.AutoContrast, true},
{"AutoRotate", o.AutoRotate, true}, {"AutoRotate", o.AutoRotate, true},
{"AutoSplitDoublePage", o.AutoSplitDoublePage, true}, {"AutoSplitDoublePage", o.AutoSplitDoublePage, o.PortraitOnly || !o.AppleBookCompatibility},
{"KeepDoublePageIfSplitted", o.KeepDoublePageIfSplitted, o.AutoSplitDoublePage}, {"KeepDoublePageIfSplitted", o.KeepDoublePageIfSplitted, (o.PortraitOnly || !o.AppleBookCompatibility) && o.AutoSplitDoublePage},
{"NoBlankImage", o.NoBlankImage, true}, {"NoBlankImage", o.NoBlankImage, true},
{"Manga", o.Manga, true}, {"Manga", o.Manga, true},
{"HasCover", o.HasCover, true}, {"HasCover", o.HasCover, true},
@ -223,9 +224,10 @@ func (o *Options) ShowConfig() string {
{"Aspect Ratio", aspectRatio, true}, {"Aspect Ratio", aspectRatio, true},
{"Portrait Only", o.PortraitOnly, true}, {"Portrait Only", o.PortraitOnly, true},
{"Title Page", titlePage, true}, {"Title Page", titlePage, true},
{"Apple Book Compatibility", o.AppleBookCompatibility, !o.PortraitOnly},
} { } {
if v.Condition { 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() return b.String()

View File

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

View File

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

View File

@ -192,6 +192,9 @@ func getManifest(o *ContentOptions) []tag {
// spine part of the content // spine part of the content
func getSpineAuto(o *ContentOptions) []tag { func getSpineAuto(o *ContentOptions) []tag {
isOnTheRight := !o.ImageOptions.Manga isOnTheRight := !o.ImageOptions.Manga
if o.ImageOptions.AppleBookCompatibility {
isOnTheRight = !isOnTheRight
}
getSpread := func(isDoublePage bool) string { getSpread := func(isDoublePage bool) string {
isOnTheRight = !isOnTheRight isOnTheRight = !isOnTheRight
if isDoublePage { if isDoublePage {
@ -211,10 +214,16 @@ func getSpineAuto(o *ContentOptions) []tag {
spine := []tag{} spine := []tag{}
if o.HasTitlePage { if o.HasTitlePage {
spine = append(spine, if !o.ImageOptions.AppleBookCompatibility {
tag{"itemref", tagAttrs{"idref": "space_title", "properties": getSpreadBlank()}, ""}, spine = append(spine,
tag{"itemref", tagAttrs{"idref": "page_title", "properties": getSpread(false)}, ""}, 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 { for _, img := range o.Images {
if (img.DoublePage || img.Part == 1) && o.ImageOptions.Manga == isOnTheRight { 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, GrayScaleMode: cmd.Options.GrayscaleMode,
Resize: !cmd.Options.NoResize, Resize: !cmd.Options.NoResize,
Format: cmd.Options.Format, Format: cmd.Options.Format,
AppleBookCompatibility: cmd.Options.AppleBookCompatibility,
}, },
}).Write(); err != nil { }).Write(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err) fmt.Fprintf(os.Stderr, "Error: %v\n", err)