diff --git a/README.md b/README.md index c8ac542..3440c85 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/internal/converter/converter.go b/internal/converter/converter.go index 9bd7eec..f458b16 100644 --- a/internal/converter/converter.go +++ b/internal/converter/converter.go @@ -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 diff --git a/internal/converter/options/converter_options.go b/internal/converter/options/converter_options.go index 6187aea..585a452 100644 --- a/internal/converter/options/converter_options.go +++ b/internal/converter/options/converter_options.go @@ -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() diff --git a/internal/epub/options/epub_options.go b/internal/epub/options/epub_options.go index 3f6f44c..9ac548d 100644 --- a/internal/epub/options/epub_options.go +++ b/internal/epub/options/epub_options.go @@ -38,6 +38,7 @@ type Image struct { GrayScaleMode int Resize bool Format string + AppleBookCompatibility bool } type Options struct { diff --git a/internal/epub/templates/epub_templates_applebooks.xml.tmpl b/internal/epub/templates/epub_templates_applebooks.xml.tmpl index aad0f8c..a00f429 100644 --- a/internal/epub/templates/epub_templates_applebooks.xml.tmpl +++ b/internal/epub/templates/epub_templates_applebooks.xml.tmpl @@ -1,6 +1,8 @@ + + \ No newline at end of file diff --git a/internal/epub/templates/epub_templates_content.go b/internal/epub/templates/epub_templates_content.go index 55e5cec..2d6c267 100644 --- a/internal/epub/templates/epub_templates_content.go +++ b/internal/epub/templates/epub_templates_content.go @@ -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 { diff --git a/main.go b/main.go index e600f78..de25384 100644 --- a/main.go +++ b/main.go @@ -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)