mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
Compare commits
3 Commits
45677c6b7b
...
c34a255768
Author | SHA1 | Date | |
---|---|---|---|
c34a255768 | |||
b1a398e155 | |||
36512cdb98 |
24
README.md
24
README.md
@ -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:
|
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:
|
To force install a specific version:
|
||||||
```
|
```
|
||||||
# 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
|
# main branch
|
||||||
$ go install github.com/celogeek/go-comic-converter/v2@main
|
$ go install github.com/celogeek/go-comic-converter/v3@main
|
||||||
|
|
||||||
# specific commit
|
# 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
|
Add GOPATH to your PATH
|
||||||
@ -58,19 +58,27 @@ Add GOPATH to your PATH
|
|||||||
$ export PATH=$(go env GOPATH)/bin:$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
|
# Check last version
|
||||||
|
|
||||||
You can check if a new version is available with:
|
You can check if a new version is available with:
|
||||||
```
|
```
|
||||||
$ go-comic-converter -version
|
$ go-comic-converter -version
|
||||||
go-comic-converter
|
go-comic-converter
|
||||||
Path : github.com/celogeek/go-comic-converter/v2
|
Path : github.com/celogeek/go-comic-converter/v3
|
||||||
Sum : h1:tUFF2m/fGlOJOwC0/PlTopMfcBMprKvgr6TiQHQxEeo=
|
Sum : h1:tUFF2m/fGlOJOwC0/PlTopMfcBMprKvgr6TiQHQxEeo=
|
||||||
Version : v2.6.9
|
Version : v3.0.0
|
||||||
Available Version: v2.6.9
|
Available Version: v3.0.0
|
||||||
|
|
||||||
To install the latest version:
|
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
|
# Supported image files
|
||||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module github.com/celogeek/go-comic-converter/v2
|
module github.com/celogeek/go-comic-converter/v3
|
||||||
|
|
||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Converter struct {
|
type Converter struct {
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epuboptions"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
|
"github.com/celogeek/go-comic-converter/v3/pkg/epuboptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Profile struct {
|
type Profile struct {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EPUBImage struct {
|
type EPUBImage struct {
|
||||||
|
@ -27,9 +27,9 @@ import (
|
|||||||
pdfimage "github.com/raff/pdfreader/image"
|
pdfimage "github.com/raff/pdfreader/image"
|
||||||
"github.com/raff/pdfreader/pdfread"
|
"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 {
|
type task struct {
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
|
|
||||||
"github.com/disintegration/gift"
|
"github.com/disintegration/gift"
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimage"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimage"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimagefilters"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimagefilters"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epuboptions"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubprogress"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubprogress"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubzip"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubzip"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
|
"github.com/celogeek/go-comic-converter/v3/pkg/epuboptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EPUBImageProcessor struct {
|
type EPUBImageProcessor struct {
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/schollz/progressbar/v3"
|
"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 {
|
type Options struct {
|
||||||
|
@ -3,9 +3,9 @@ package epubtemplates
|
|||||||
import (
|
import (
|
||||||
"github.com/beevik/etree"
|
"github.com/beevik/etree"
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimage"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimage"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epuboptions"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
|
"github.com/celogeek/go-comic-converter/v3/pkg/epuboptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Content struct {
|
type Content struct {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/beevik/etree"
|
"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
|
// Toc create toc
|
||||||
|
6
main.go
6
main.go
@ -14,9 +14,9 @@ import (
|
|||||||
|
|
||||||
"github.com/tcnksm/go-latest"
|
"github.com/tcnksm/go-latest"
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/converter"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/converter"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epub"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
|
"github.com/celogeek/go-comic-converter/v3/pkg/epub"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -14,17 +14,21 @@ import (
|
|||||||
|
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimage"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimage"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubimageprocessor"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimageprocessor"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epuboptions"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubprogress"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubprogress"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubtemplates"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubtemplates"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubtree"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubtree"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/epubzip"
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/epubzip"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
"github.com/celogeek/go-comic-converter/v2/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
|
epuboptions.EPUBOptions
|
||||||
UID string
|
UID string
|
||||||
Publisher 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) },
|
"zoom": func(s int, z float32) int { return int(float32(s) * z) },
|
||||||
})
|
})
|
||||||
|
|
||||||
return EPUB{
|
return epub{
|
||||||
EPUBOptions: options,
|
EPUBOptions: options,
|
||||||
UID: uid.String(),
|
UID: uid.String(),
|
||||||
Publisher: "GO Comic Converter",
|
Publisher: "GO Comic Converter",
|
||||||
@ -59,7 +63,7 @@ func New(options epuboptions.EPUBOptions) EPUB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// render templates
|
// 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
|
var result strings.Builder
|
||||||
tmpl := template.Must(e.templateProcessor.Parse(templateString))
|
tmpl := template.Must(e.templateProcessor.Parse(templateString))
|
||||||
if err := tmpl.Execute(&result, data); err != nil {
|
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
|
// 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(
|
err := wz.WriteContent(
|
||||||
img.EPUBPagePath(),
|
img.EPUBPagePath(),
|
||||||
[]byte(e.render(epubtemplates.Text, map[string]any{
|
[]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
|
// 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(
|
return wz.WriteContent(
|
||||||
img.EPUBSpacePath(),
|
img.EPUBSpacePath(),
|
||||||
[]byte(e.render(epubtemplates.Blank, map[string]any{
|
[]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
|
// 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"
|
title := "Cover"
|
||||||
text := ""
|
text := ""
|
||||||
if totalParts > 1 {
|
if totalParts > 1 {
|
||||||
@ -141,7 +145,7 @@ func (e EPUB) writeCoverImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, part,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write title image
|
// 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 := ""
|
titleAlign := ""
|
||||||
if !e.Image.View.PortraitOnly {
|
if !e.Image.View.PortraitOnly {
|
||||||
if e.Image.Manga {
|
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
|
// 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()
|
images, err := e.imageProcessor.Load()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -268,7 +272,7 @@ func (e EPUB) getParts() (parts []epubPart, imgStorage epubzip.StorageImageReade
|
|||||||
// create a tree from the directories.
|
// create a tree from the directories.
|
||||||
//
|
//
|
||||||
// this is used to simulate the toc.
|
// 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()
|
t := epubtree.New()
|
||||||
for _, img := range images {
|
for _, img := range images {
|
||||||
if skipFiles {
|
if skipFiles {
|
||||||
@ -285,7 +289,7 @@ func (e EPUB) getTree(images []epubimage.EPUBImage, skipFiles bool) string {
|
|||||||
return c.WriteString("")
|
return c.WriteString("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EPUB) computeAspectRatio(epubParts []epubPart) float64 {
|
func (e epub) computeAspectRatio(epubParts []epubPart) float64 {
|
||||||
var (
|
var (
|
||||||
bestAspectRatio float64
|
bestAspectRatio float64
|
||||||
bestAspectRatioCount int
|
bestAspectRatioCount int
|
||||||
@ -312,7 +316,7 @@ func (e EPUB) computeAspectRatio(epubParts []epubPart) float64 {
|
|||||||
return bestAspectRatio
|
return bestAspectRatio
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EPUB) computeViewPort(epubParts []epubPart) (int, int) {
|
func (e epub) computeViewPort(epubParts []epubPart) (int, int) {
|
||||||
if e.Image.View.AspectRatio == -1 {
|
if e.Image.View.AspectRatio == -1 {
|
||||||
//keep device size
|
//keep device size
|
||||||
return e.Image.View.Width, e.Image.View.Height
|
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)
|
hasTitlePage := e.TitlePage == 1 || (e.TitlePage == 2 && totalParts > 1)
|
||||||
|
|
||||||
wz, err := epubzip.New(path)
|
wz, err := epubzip.New(path)
|
||||||
@ -413,7 +417,7 @@ func (e EPUB) writePart(path string, currentPart, totalParts int, part epubPart,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the zip
|
// create the zip
|
||||||
func (e EPUB) Write() error {
|
func (e epub) Write() error {
|
||||||
epubParts, imgStorage, err := e.getParts()
|
epubParts, imgStorage, err := e.getParts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
@ -1,7 +1,7 @@
|
|||||||
package epuboptions
|
package epuboptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/celogeek/go-comic-converter/v2/internal/pkg/utils"
|
"github.com/celogeek/go-comic-converter/v3/internal/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type View struct {
|
type View struct {
|
Loading…
x
Reference in New Issue
Block a user