mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 00:02:37 +02:00
151 lines
4.5 KiB
Go
151 lines
4.5 KiB
Go
/*
|
|
Convert CBZ/CBR/Dir into EPUB for e-reader devices (Kindle Devices, ...)
|
|
|
|
My goal is to make a simple, crossplatform, and fast tool to convert comics into EPUB.
|
|
|
|
EPUB is now support by Amazon through [SendToKindle](https://www.amazon.com/gp/sendtokindle/), by Email or by using the App. So I've made it simple to support the size limit constraint of those services.
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"runtime/debug"
|
|
|
|
"github.com/celogeek/go-comic-converter/v2/internal/converter"
|
|
"github.com/celogeek/go-comic-converter/v2/internal/epub"
|
|
epuboptions "github.com/celogeek/go-comic-converter/v2/internal/epub/options"
|
|
"github.com/tcnksm/go-latest"
|
|
)
|
|
|
|
func main() {
|
|
cmd := converter.New()
|
|
if err := cmd.LoadConfig(); err != nil {
|
|
cmd.Fatal(err)
|
|
}
|
|
cmd.InitParse()
|
|
cmd.Parse()
|
|
|
|
if cmd.Options.Version {
|
|
bi, ok := debug.ReadBuildInfo()
|
|
if !ok {
|
|
fmt.Fprintln(os.Stderr, "failed to fetch current version")
|
|
os.Exit(1)
|
|
}
|
|
|
|
githubTag := &latest.GithubTag{
|
|
Owner: "celogeek",
|
|
Repository: "go-comic-converter",
|
|
}
|
|
v, err := githubTag.Fetch()
|
|
if err != nil || len(v.Versions) < 1 {
|
|
fmt.Fprintln(os.Stderr, "failed to fetch the latest version")
|
|
os.Exit(1)
|
|
}
|
|
latest_version := v.Versions[0]
|
|
|
|
fmt.Fprintf(os.Stderr, `go-comic-converter
|
|
Path : %s
|
|
Sum : %s
|
|
Version : %s
|
|
Available Version: %s
|
|
|
|
To install the latest version:
|
|
$ go install github.com/celogeek/go-comic-converter/v%d@%s
|
|
`,
|
|
bi.Main.Path,
|
|
bi.Main.Sum,
|
|
bi.Main.Version,
|
|
latest_version.Original(),
|
|
latest_version.Segments()[0],
|
|
latest_version.Original(),
|
|
)
|
|
return
|
|
}
|
|
|
|
if cmd.Options.Save {
|
|
cmd.Options.SaveConfig()
|
|
fmt.Fprintf(
|
|
os.Stderr,
|
|
"%s%s\n\nSaving to %s\n",
|
|
cmd.Options.Header(),
|
|
cmd.Options.ShowConfig(),
|
|
cmd.Options.FileName(),
|
|
)
|
|
return
|
|
}
|
|
|
|
if cmd.Options.Show {
|
|
fmt.Fprintln(os.Stderr, cmd.Options.Header(), cmd.Options.ShowConfig())
|
|
return
|
|
}
|
|
|
|
if cmd.Options.Reset {
|
|
cmd.Options.ResetConfig()
|
|
fmt.Fprintf(
|
|
os.Stderr,
|
|
"%s%s\n\nReset default to %s\n",
|
|
cmd.Options.Header(),
|
|
cmd.Options.ShowConfig(),
|
|
cmd.Options.FileName(),
|
|
)
|
|
return
|
|
}
|
|
|
|
if err := cmd.Validate(); err != nil {
|
|
cmd.Fatal(err)
|
|
}
|
|
|
|
if cmd.Options.Json {
|
|
json.NewEncoder(os.Stdout).Encode(map[string]any{
|
|
"type": "options", "data": cmd.Options,
|
|
})
|
|
} else {
|
|
fmt.Fprintln(os.Stderr, cmd.Options)
|
|
}
|
|
|
|
profile := cmd.Options.GetProfile()
|
|
|
|
if err := epub.New(&epuboptions.Options{
|
|
Input: cmd.Options.Input,
|
|
Output: cmd.Options.Output,
|
|
LimitMb: cmd.Options.LimitMb,
|
|
Title: cmd.Options.Title,
|
|
TitlePage: cmd.Options.TitlePage,
|
|
Author: cmd.Options.Author,
|
|
StripFirstDirectoryFromToc: cmd.Options.StripFirstDirectoryFromToc,
|
|
SortPathMode: cmd.Options.SortPathMode,
|
|
Workers: cmd.Options.Workers,
|
|
Dry: cmd.Options.Dry,
|
|
DryVerbose: cmd.Options.DryVerbose,
|
|
Quiet: cmd.Options.Quiet,
|
|
Json: cmd.Options.Json,
|
|
Image: &epuboptions.Image{
|
|
Crop: &epuboptions.Crop{Enabled: cmd.Options.Crop, Left: cmd.Options.CropRatioLeft, Up: cmd.Options.CropRatioUp, Right: cmd.Options.CropRatioRight, Bottom: cmd.Options.CropRatioBottom},
|
|
Quality: cmd.Options.Quality,
|
|
Brightness: cmd.Options.Brightness,
|
|
Contrast: cmd.Options.Contrast,
|
|
AutoContrast: cmd.Options.AutoContrast,
|
|
AutoRotate: cmd.Options.AutoRotate,
|
|
AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage,
|
|
KeepDoublePageIfSplitted: cmd.Options.KeepDoublePageIfSplitted,
|
|
NoBlankImage: cmd.Options.NoBlankImage,
|
|
Manga: cmd.Options.Manga,
|
|
HasCover: cmd.Options.HasCover,
|
|
View: &epuboptions.View{Width: profile.Width, Height: profile.Height, AspectRatio: cmd.Options.AspectRatio, PortraitOnly: cmd.Options.PortraitOnly, Color: epuboptions.Color{Foreground: cmd.Options.ForegroundColor, Background: cmd.Options.BackgroundColor}},
|
|
GrayScale: cmd.Options.Grayscale,
|
|
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)
|
|
os.Exit(1)
|
|
}
|
|
if !cmd.Options.Dry {
|
|
cmd.Stats()
|
|
}
|
|
}
|