From b9115f7f6f7cf6a01bb62ca27a37bb89bb0b8d57 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sun, 16 Apr 2023 11:37:40 +0200 Subject: [PATCH 01/24] add etree to build xml --- go.mod | 2 ++ go.sum | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 6b6696e..5ccb349 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/celogeek/go-comic-converter/v2 go 1.19 require ( + github.com/beevik/etree v1.1.0 github.com/disintegration/gift v1.2.1 github.com/gofrs/uuid v4.4.0+incompatible github.com/nwaples/rardecode v1.1.3 @@ -20,6 +21,7 @@ require ( github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/rivo/uniseg v0.4.4 // indirect + github.com/stretchr/testify v1.8.2 // indirect golang.org/x/net v0.9.0 // indirect golang.org/x/sys v0.7.0 // indirect golang.org/x/term v0.7.0 // indirect diff --git a/go.sum b/go.sum index d664ac8..189f181 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= +github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -31,15 +33,18 @@ github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc github.com/schollz/progressbar/v3 v3.13.1 h1:o8rySDYiQ59Mwzy2FELeHY5ZARXZTVJC7iHD6PEFUiE= github.com/schollz/progressbar/v3 v3.13.1/go.mod h1:xvrbki8kfT1fzWzBT/UZd9L6GA+jdL7HAgq2RFnO6fQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k= github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4= -golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0= golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw= golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -47,7 +52,6 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= @@ -61,14 +65,12 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= @@ -76,7 +78,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -86,5 +87,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From ed1a312027a2a54ac31dcf4cb3c04491c06d0cf3 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sun, 16 Apr 2023 11:44:03 +0200 Subject: [PATCH 02/24] remove panelview --- README.md | 8 -- internal/converter/core.go | 1 - internal/converter/options/core.go | 4 - internal/epub/core.go | 35 ++---- internal/epub/templates.go | 6 - internal/epub/templates/panelview.css.tmpl | 103 ------------------ internal/epub/templates/text.xhtml.tmpl | 31 +----- .../epub/templates/textnopanel.xhtml.tmpl | 14 --- main.go | 1 - 9 files changed, 14 insertions(+), 189 deletions(-) delete mode 100644 internal/epub/templates/panelview.css.tmpl delete mode 100644 internal/epub/templates/textnopanel.xhtml.tmpl diff --git a/README.md b/README.md index 713c584..92309be 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,6 @@ Options: NoBlankPage : false Manga : true HasCover : true - AddPanelView : false LimitMb : 200 Mb StripFirstDirectoryFromToc: true SortPathMode : path=alphanum, file=alpha @@ -162,7 +161,6 @@ Options: NoBlankPage : false Manga : true HasCover : true - AddPanelView : false LimitMb : 200 Mb StripFirstDirectoryFromToc: true SortPathMode : path=alphanum, file=alphanum @@ -210,7 +208,6 @@ Options: NoBlankPage : false Manga : false HasCover : true - AddPanelView : false LimitMb : nolimit StripFirstDirectoryFromToc: false SortPathMode : path=alphanum, file=alpha @@ -233,7 +230,6 @@ Options: NoBlankPage : false Manga : true HasCover : true - AddPanelView : false LimitMb : 200 Mb StripFirstDirectoryFromToc: false SortPathMode : path=alphanum, file=alpha @@ -258,7 +254,6 @@ Options: NoBlankPage : false Manga : false HasCover : true - AddPanelView : false LimitMb : 200 Mb StripFirstDirectoryFromToc: false SortPathMode : path=alphanum, file=alpha @@ -284,7 +279,6 @@ Options: NoBlankPage : false Manga : false HasCover : true - AddPanelView : false LimitMb : nolimit Reset default to ~/.go-comic-converter.yaml @@ -360,8 +354,6 @@ Config: Manga mode (right to left) -hascover (default true) Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title. - -addpanelview - Add an embeded panel view. On kindle you may not need this option as it is handled by the kindle. -limitmb int Limit size of the ePub: Default nolimit (0), Minimum 20 -strip diff --git a/internal/converter/core.go b/internal/converter/core.go index 0a01c78..1e758d0 100644 --- a/internal/converter/core.go +++ b/internal/converter/core.go @@ -95,7 +95,6 @@ func (c *Converter) InitParse() { c.AddBoolParam(&c.Options.NoBlankPage, "noblankpage", c.Options.NoBlankPage, "Remove blank pages") c.AddBoolParam(&c.Options.Manga, "manga", c.Options.Manga, "Manga mode (right to left)") c.AddBoolParam(&c.Options.HasCover, "hascover", c.Options.HasCover, "Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.") - c.AddBoolParam(&c.Options.AddPanelView, "addpanelview", c.Options.AddPanelView, "Add an embeded panel view. On kindle you may not need this option as it is handled by the kindle.") c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the ePub: Default nolimit (0), Minimum 20") c.AddBoolParam(&c.Options.StripFirstDirectoryFromToc, "strip", c.Options.StripFirstDirectoryFromToc, "Strip first directory from the TOC if only 1") c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanum for path and alpha for file\n2 = alphanum for path and file") diff --git a/internal/converter/options/core.go b/internal/converter/options/core.go index bf45a4f..2e372b9 100644 --- a/internal/converter/options/core.go +++ b/internal/converter/options/core.go @@ -31,7 +31,6 @@ type Options struct { NoBlankPage bool `yaml:"no_blank_page"` Manga bool `yaml:"manga"` HasCover bool `yaml:"has_cover"` - AddPanelView bool `yaml:"add_panel_view"` LimitMb int `yaml:"limit_mb"` StripFirstDirectoryFromToc bool `yaml:"strip_first_directory_from_toc"` SortPathMode int `yaml:"sort_path_mode"` @@ -61,7 +60,6 @@ func New() *Options { NoBlankPage: false, Manga: false, HasCover: true, - AddPanelView: false, LimitMb: 0, StripFirstDirectoryFromToc: false, SortPathMode: 1, @@ -150,7 +148,6 @@ func (o *Options) ShowDefault() string { NoBlankPage : %v Manga : %v HasCover : %v - AddPanelView : %v LimitMb : %s StripFirstDirectoryFromToc: %v SortPathMode : %s`, @@ -164,7 +161,6 @@ func (o *Options) ShowDefault() string { o.NoBlankPage, o.Manga, o.HasCover, - o.AddPanelView, limitmb, o.StripFirstDirectoryFromToc, sortpathmode, diff --git a/internal/epub/core.go b/internal/epub/core.go index da0ff2c..d8e9eae 100644 --- a/internal/epub/core.go +++ b/internal/epub/core.go @@ -27,7 +27,6 @@ type ImageOptions struct { NoBlankPage bool Manga bool HasCover bool - AddPanelView bool Workers int } @@ -298,9 +297,6 @@ func (e *ePub) Write() error { "Total": totalParts, })}, } - if e.AddPanelView { - content = append(content, zipContent{"OEBPS/Text/panelview.css", panelViewTmpl}) - } if err = wz.WriteMagic(); err != nil { return err @@ -317,24 +313,21 @@ func (e *ePub) Write() error { wz.WriteImage(part.Cover.Data) } - for _, img := range part.Images { - var content string - if e.AddPanelView { - content = e.render(textTmpl, map[string]any{ - "Image": img, - "Manga": e.Manga, - }) - } else { - content = e.render(textNoPanelTmpl, map[string]any{ - "Image": img, - }) - } - - if err := wz.WriteFile(fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part), content); err != nil { + for i, img := range part.Images { + if err := wz.WriteFile(fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part), e.render(textTmpl, map[string]any{ + "Info": e, + "Image": img, + "Top": fmt.Sprintf("%d", (e.ViewHeight-img.Height)/2), + })); err != nil { return err } - if img.NeedSpace { + if err := wz.WriteImage(img.Data); err != nil { + return err + } + + // Double Page or Last Image + if img.DoublePage || (i+1 == len(part.Images)) { if err := wz.WriteFile( fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id), e.render(blankTmpl, map[string]any{ @@ -345,10 +338,6 @@ func (e *ePub) Write() error { return err } } - - if err := wz.WriteImage(img.Data); err != nil { - return err - } } bar.Add(1) } diff --git a/internal/epub/templates.go b/internal/epub/templates.go index ad5f61d..f0dea83 100644 --- a/internal/epub/templates.go +++ b/internal/epub/templates.go @@ -17,17 +17,11 @@ var navTmpl string //go:embed "templates/style.css.tmpl" var styleTmpl string -//go:embed "templates/panelview.css.tmpl" -var panelViewTmpl string - //go:embed "templates/part.xhtml.tmpl" var partTmpl string //go:embed "templates/text.xhtml.tmpl" var textTmpl string -//go:embed "templates/textnopanel.xhtml.tmpl" -var textNoPanelTmpl string - //go:embed "templates/blank.xhtml.tmpl" var blankTmpl string diff --git a/internal/epub/templates/panelview.css.tmpl b/internal/epub/templates/panelview.css.tmpl deleted file mode 100644 index 88d9feb..0000000 --- a/internal/epub/templates/panelview.css.tmpl +++ /dev/null @@ -1,103 +0,0 @@ -a.app-amzn-magnify { - display: inline-block; - width: 100%; - height: 100%; -} - -#PV { - position: absolute; - width: 100%; - height: 100%; - top: 0; - left: 0; -} - -#PV-T { - top: 0; - width: 100%; - height: 50%; -} - -#PV-B { - bottom: 0; - width: 100%; - height: 50%; -} - -#PV-L { - left: 0; - width: 49.5%; - height: 100%; - float: left; -} - -#PV-R { - right: 0; - width: 49.5%; - height: 100%; - float: right; -} - -#PV-TL { - top: 0; - left: 0; - width: 49.5%; - height: 50%; - float: left; -} - -#PV-TR { - top: 0; - right: 0; - width: 49.5%; - height: 50%; - float: right; -} - -#PV-BL { - bottom: 0; - left: 0; - width: 49.5%; - height: 50%; - float: left; -} - -#PV-BR { - bottom: 0; - right: 0; - width: 49.5%; - height: 50%; - float: right; -} - -.PV-P { - width: 100%; - height: 100%; - top: 0; - position: absolute; - display: none; -} - -div#PV-TL-P img { - position: absolute; - left: 0; - top: 0; -} - -div#PV-TR-P img { - position: absolute; - right: 0; - top: 0; -} - -div#PV-BL-P img { - position: absolute; - left: 0; - bottom: 0; -} - -div#PV-BR-P img { - position: absolute; - right: 0; - bottom: 0; -} \ No newline at end of file diff --git a/internal/epub/templates/text.xhtml.tmpl b/internal/epub/templates/text.xhtml.tmpl index d92b6f6..f22efeb 100644 --- a/internal/epub/templates/text.xhtml.tmpl +++ b/internal/epub/templates/text.xhtml.tmpl @@ -4,38 +4,11 @@