Compare commits

...

3 Commits

Author SHA1 Message Date
c34a255768
26 expose the internal epub and epub options package (#44)
* make epub and epub options public

* export only interface
2025-01-05 16:57:23 +01:00
b1a398e155
add upgrade notice 2025-01-05 15:36:36 +01:00
36512cdb98
update to v3 2025-01-05 15:32:57 +01:00
18 changed files with 64 additions and 52 deletions

View File

@ -38,19 +38,19 @@ First ensure to have a working version of GO: [Installation](https://go.dev/doc/
Then install the last version of the tool:
```
$ go install github.com/celogeek/go-comic-converter/v2
$ go install github.com/celogeek/go-comic-converter/v3
```
To force install a specific version:
```
# specific version
$ go install github.com/celogeek/go-comic-converter/v2@v2.6.9
$ go install github.com/celogeek/go-comic-converter/v3@v3.0.0
# main branch
$ go install github.com/celogeek/go-comic-converter/v2@main
$ go install github.com/celogeek/go-comic-converter/v3@main
# specific commit
$ go install github.com/celogeek/go-comic-converter/v2@141aeae
$ go install github.com/celogeek/go-comic-converter/v3@COMMIT_HASH
```
Add GOPATH to your PATH
@ -58,19 +58,27 @@ Add GOPATH to your PATH
$ export PATH=$(go env GOPATH)/bin:$PATH
```
# Upgrade from V2
The configuration file structure changes in the v3 compare to v2.
You need to recreate your config and save it again.
Use the `show`, `reset` and `save` option.
# Check last version
You can check if a new version is available with:
```
$ go-comic-converter -version
go-comic-converter
Path : github.com/celogeek/go-comic-converter/v2
Path : github.com/celogeek/go-comic-converter/v3
Sum : h1:tUFF2m/fGlOJOwC0/PlTopMfcBMprKvgr6TiQHQxEeo=
Version : v2.6.9
Available Version: v2.6.9
Version : v3.0.0
Available Version: v3.0.0
To install the latest version:
$ go install github.com/celogeek/go-comic-converter/v2@v2.6.9
$ go install github.com/celogeek/go-comic-converter/v3@v3.0.0
```
# Supported image files

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/celogeek/go-comic-converter/v2
module github.com/celogeek/go-comic-converter/v3
go 1.23

View File

@ -18,7 +18,7 @@ import (
"strings"
"time"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
)
type Converter struct {

View File

@ -9,8 +9,8 @@ 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"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/pkg/epuboptions"
)
type Options struct {

View File

@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
)
type Profile struct {

View File

@ -5,7 +5,7 @@ import (
"image"
"strings"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
)
type EPUBImage struct {

View File

@ -27,9 +27,9 @@ import (
pdfimage "github.com/raff/pdfreader/image"
"github.com/raff/pdfreader/pdfread"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/sortpath"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/sortpath"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
)
type task struct {

View File

@ -9,12 +9,12 @@ import (
"github.com/disintegration/gift"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimage"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimagefilters"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epuboptions"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubprogress"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubzip"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimage"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimagefilters"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubprogress"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubzip"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/pkg/epuboptions"
)
type EPUBImageProcessor struct {

View File

@ -9,7 +9,7 @@ import (
"github.com/schollz/progressbar/v3"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
)
type Options struct {

View File

@ -3,9 +3,9 @@ package epubtemplates
import (
"github.com/beevik/etree"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimage"
"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/v3/internal/pkg/epubimage"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/pkg/epuboptions"
)
type Content struct {

View File

@ -6,7 +6,7 @@ import (
"github.com/beevik/etree"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimage"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimage"
)
// Toc create toc

View File

@ -14,9 +14,9 @@ import (
"github.com/tcnksm/go-latest"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/converter"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epub"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/converter"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/pkg/epub"
)
func main() {

View File

@ -14,17 +14,21 @@ import (
"github.com/gofrs/uuid"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimage"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimageprocessor"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epuboptions"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubprogress"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubtemplates"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubtree"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubzip"
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimage"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimageprocessor"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubprogress"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubtemplates"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubtree"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubzip"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/pkg/epuboptions"
)
type EPUB struct {
type EPUB interface {
Write() error
}
type epub struct {
epuboptions.EPUBOptions
UID string
Publisher string
@ -48,7 +52,7 @@ func New(options epuboptions.EPUBOptions) EPUB {
"zoom": func(s int, z float32) int { return int(float32(s) * z) },
})
return EPUB{
return epub{
EPUBOptions: options,
UID: uid.String(),
Publisher: "GO Comic Converter",
@ -59,7 +63,7 @@ func New(options epuboptions.EPUBOptions) EPUB {
}
// render templates
func (e EPUB) render(templateString string, data map[string]any) string {
func (e epub) render(templateString string, data map[string]any) string {
var result strings.Builder
tmpl := template.Must(e.templateProcessor.Parse(templateString))
if err := tmpl.Execute(&result, data); err != nil {
@ -69,7 +73,7 @@ func (e EPUB) render(templateString string, data map[string]any) string {
}
// write image to the zip
func (e EPUB) writeImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, zipImg *zip.File) error {
func (e epub) writeImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, zipImg *zip.File) error {
err := wz.WriteContent(
img.EPUBPagePath(),
[]byte(e.render(epubtemplates.Text, map[string]any{
@ -87,7 +91,7 @@ func (e EPUB) writeImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, zipImg *zi
}
// write blank page
func (e EPUB) writeBlank(wz epubzip.EPUBZip, img epubimage.EPUBImage) error {
func (e epub) writeBlank(wz epubzip.EPUBZip, img epubimage.EPUBImage) error {
return wz.WriteContent(
img.EPUBSpacePath(),
[]byte(e.render(epubtemplates.Blank, map[string]any{
@ -98,7 +102,7 @@ func (e EPUB) writeBlank(wz epubzip.EPUBZip, img epubimage.EPUBImage) error {
}
// write title image
func (e EPUB) writeCoverImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, part, totalParts int) error {
func (e epub) writeCoverImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, part, totalParts int) error {
title := "Cover"
text := ""
if totalParts > 1 {
@ -141,7 +145,7 @@ func (e EPUB) writeCoverImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, part,
}
// write title image
func (e EPUB) writeTitleImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, title string) error {
func (e epub) writeTitleImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, title string) error {
titleAlign := ""
if !e.Image.View.PortraitOnly {
if e.Image.Manga {
@ -197,7 +201,7 @@ func (e EPUB) writeTitleImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, title
}
// extract image and split it into part
func (e EPUB) getParts() (parts []epubPart, imgStorage epubzip.StorageImageReader, err error) {
func (e epub) getParts() (parts []epubPart, imgStorage epubzip.StorageImageReader, err error) {
images, err := e.imageProcessor.Load()
if err != nil {
@ -268,7 +272,7 @@ func (e EPUB) getParts() (parts []epubPart, imgStorage epubzip.StorageImageReade
// create a tree from the directories.
//
// this is used to simulate the toc.
func (e EPUB) getTree(images []epubimage.EPUBImage, skipFiles bool) string {
func (e epub) getTree(images []epubimage.EPUBImage, skipFiles bool) string {
t := epubtree.New()
for _, img := range images {
if skipFiles {
@ -285,7 +289,7 @@ func (e EPUB) getTree(images []epubimage.EPUBImage, skipFiles bool) string {
return c.WriteString("")
}
func (e EPUB) computeAspectRatio(epubParts []epubPart) float64 {
func (e epub) computeAspectRatio(epubParts []epubPart) float64 {
var (
bestAspectRatio float64
bestAspectRatioCount int
@ -312,7 +316,7 @@ func (e EPUB) computeAspectRatio(epubParts []epubPart) float64 {
return bestAspectRatio
}
func (e EPUB) computeViewPort(epubParts []epubPart) (int, int) {
func (e epub) computeViewPort(epubParts []epubPart) (int, int) {
if e.Image.View.AspectRatio == -1 {
//keep device size
return e.Image.View.Width, e.Image.View.Height
@ -332,7 +336,7 @@ func (e EPUB) computeViewPort(epubParts []epubPart) (int, int) {
}
}
func (e EPUB) writePart(path string, currentPart, totalParts int, part epubPart, imgStorage epubzip.StorageImageReader) error {
func (e epub) writePart(path string, currentPart, totalParts int, part epubPart, imgStorage epubzip.StorageImageReader) error {
hasTitlePage := e.TitlePage == 1 || (e.TitlePage == 2 && totalParts > 1)
wz, err := epubzip.New(path)
@ -413,7 +417,7 @@ func (e EPUB) writePart(path string, currentPart, totalParts int, part epubPart,
}
// create the zip
func (e EPUB) Write() error {
func (e epub) Write() error {
epubParts, imgStorage, err := e.getParts()
if err != nil {
return err

View File

@ -1,7 +1,7 @@
package epuboptions
import (
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
)
type View struct {