mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
params for conversion
This commit is contained in:
parent
1563458214
commit
4dbc7b5f8a
179
main.go
179
main.go
@ -1,112 +1,97 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
"go-comic-converter/internal/epub"
|
"go-comic-converter/internal/epub"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// type File struct {
|
type Profile struct {
|
||||||
// Path string
|
Width int
|
||||||
// Name string
|
Height int
|
||||||
// Title string
|
}
|
||||||
// Data string
|
|
||||||
// InternalPath string
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func addImages(doc *epub2.Epub, imagesPath []string) {
|
var Profiles = map[string]Profile{
|
||||||
// wg := &sync.WaitGroup{}
|
"KS": {1860, 2480},
|
||||||
// todos := make(chan string, runtime.NumCPU())
|
}
|
||||||
// imageResult := make(chan *File)
|
|
||||||
|
|
||||||
// wg.Add(runtime.NumCPU())
|
type Option struct {
|
||||||
// for i := 0; i < runtime.NumCPU(); i++ {
|
Input string
|
||||||
// go func() {
|
Output string
|
||||||
// defer wg.Done()
|
Profile string
|
||||||
// for imagePath := range todos {
|
Author string
|
||||||
// name := filepath.Base(imagePath)
|
Title string
|
||||||
// ext := filepath.Ext(name)
|
Quality int
|
||||||
// title := name[0 : len(name)-len(ext)]
|
}
|
||||||
// imageResult <- &File{
|
|
||||||
// Path: imagePath,
|
|
||||||
// Name: name,
|
|
||||||
// Title: title,
|
|
||||||
// Data: imageconverter.Convert(imagePath, true, 1860, 2480, 75),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }()
|
|
||||||
// }
|
|
||||||
// go func() {
|
|
||||||
// for _, imagePath := range imagesPath {
|
|
||||||
// todos <- imagePath
|
|
||||||
// }
|
|
||||||
// close(todos)
|
|
||||||
// wg.Wait()
|
|
||||||
// close(imageResult)
|
|
||||||
// }()
|
|
||||||
|
|
||||||
// results := make([]*File, 0)
|
func (o *Option) String() string {
|
||||||
// for result := range imageResult {
|
var width, height int
|
||||||
// fmt.Println(result.Name)
|
profile, profileMatch := Profiles[o.Profile]
|
||||||
// internalPath, _ := doc.AddImage(result.Data, result.Name)
|
if profileMatch {
|
||||||
// result.InternalPath = internalPath
|
width = profile.Width
|
||||||
// results = append(results, result)
|
height = profile.Height
|
||||||
// }
|
}
|
||||||
// sort.SliceStable(results, func(i, j int) bool {
|
|
||||||
// return strings.Compare(
|
|
||||||
// results[i].Path, results[j].Path,
|
|
||||||
// ) < 0
|
|
||||||
// })
|
|
||||||
// for i, result := range results {
|
|
||||||
// if i == 0 {
|
|
||||||
// doc.SetCover(result.InternalPath, "")
|
|
||||||
// } else {
|
|
||||||
// doc.AddSection(
|
|
||||||
// fmt.Sprintf("<img src=\"%s\" />", result.InternalPath),
|
|
||||||
// result.Title,
|
|
||||||
// fmt.Sprintf("%s.xhtml", result.Title),
|
|
||||||
// "../css/cover.css",
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func getImages(dirname string) []string {
|
return fmt.Sprintf(`Options:
|
||||||
// images := make([]string, 0)
|
Input : %s
|
||||||
// filepath.WalkDir(dirname, func(path string, d fs.DirEntry, err error) error {
|
Output : %s
|
||||||
// if d.IsDir() {
|
Profile: %s (%dx%d)
|
||||||
// return nil
|
Author : %s
|
||||||
// }
|
Title : %s
|
||||||
// ext := filepath.Ext(path)
|
Quality: %d
|
||||||
// if strings.ToLower(ext) != ".jpg" {
|
`,
|
||||||
// return nil
|
o.Input,
|
||||||
// }
|
o.Output,
|
||||||
// images = append(images, path)
|
o.Profile,
|
||||||
// return nil
|
width,
|
||||||
// })
|
height,
|
||||||
// sort.Strings(images)
|
o.Author,
|
||||||
// return images
|
o.Title,
|
||||||
// }
|
o.Quality,
|
||||||
|
)
|
||||||
// func main2() {
|
}
|
||||||
// imagesPath := getImages("/Users/vincent/Downloads/Bleach T01 (Tite KUBO) [eBook officiel 1920]")
|
|
||||||
|
|
||||||
// doc := epub2.NewEpub("Bleach T01 (Tite KUBO) [eBook officiel 1920]")
|
|
||||||
// doc.SetAuthor("Bachelier Vincent")
|
|
||||||
|
|
||||||
// addImages(doc, imagesPath)
|
|
||||||
|
|
||||||
// if err := doc.Write("/Users/vincent/Downloads/test.epub"); err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := epub.NewEpub("/Users/vincent/Downloads/test.epub").
|
availableProfiles := make([]string, 0)
|
||||||
SetSize(1860, 2480).
|
for k := range Profiles {
|
||||||
SetQuality(75).
|
availableProfiles = append(availableProfiles, k)
|
||||||
SetTitle("Bleach T01 (Tite KUBO) [eBook officiel 1920]").
|
}
|
||||||
SetAuthor("Bachelier Vincent").
|
|
||||||
LoadDir("/Users/vincent/Downloads/Bleach T01 (Tite KUBO) [eBook officiel 1920]").
|
opt := &Option{}
|
||||||
|
flag.StringVar(&opt.Input, "input", "", "Source of comic to convert")
|
||||||
|
flag.StringVar(&opt.Output, "output", "", "Output of the epub")
|
||||||
|
flag.StringVar(&opt.Profile, "profile", "", fmt.Sprintf("Profile to use: %s", strings.Join(availableProfiles, ", ")))
|
||||||
|
flag.StringVar(&opt.Author, "author", "GO Comic Converter", "Author of the epub")
|
||||||
|
flag.StringVar(&opt.Title, "title", "", "Title of the epub")
|
||||||
|
flag.IntVar(&opt.Quality, "quality", 75, "Quality of the image: Default 75")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if opt.Input == "" || opt.Output == "" {
|
||||||
|
fmt.Println("Missing input or output!")
|
||||||
|
flag.Usage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
profile, profileMatch := Profiles[opt.Profile]
|
||||||
|
if !profileMatch {
|
||||||
|
fmt.Println("Profile doesn't exists!")
|
||||||
|
flag.Usage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if opt.Title == "" {
|
||||||
|
opt.Title = filepath.Base(opt.Input)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(opt)
|
||||||
|
|
||||||
|
err := epub.NewEpub(opt.Output).
|
||||||
|
SetSize(profile.Width, profile.Height).
|
||||||
|
SetQuality(opt.Quality).
|
||||||
|
SetTitle(opt.Input).
|
||||||
|
SetAuthor(opt.Author).
|
||||||
|
LoadDir(opt.Input).
|
||||||
Write()
|
Write()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user