mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
move load to options as an helper
This commit is contained in:
parent
4553e1e673
commit
02f86eb55e
@ -4,9 +4,7 @@ Extract and transform image into a compressed jpeg.
|
||||
package epubimageprocessing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -33,31 +31,7 @@ func isSupportedImage(path string) bool {
|
||||
func LoadImages(o *Options) ([]*epubimage.Image, error) {
|
||||
images := make([]*epubimage.Image, 0)
|
||||
|
||||
fi, err := os.Stat(o.Input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
imageCount int
|
||||
imageInput chan *tasks
|
||||
)
|
||||
|
||||
// get all images though a channel of bytes
|
||||
if fi.IsDir() {
|
||||
imageCount, imageInput, err = o.loadDir()
|
||||
} else {
|
||||
switch ext := strings.ToLower(filepath.Ext(o.Input)); ext {
|
||||
case ".cbz", ".zip":
|
||||
imageCount, imageInput, err = o.loadCbz()
|
||||
case ".cbr", ".rar":
|
||||
imageCount, imageInput, err = o.loadCbr()
|
||||
case ".pdf":
|
||||
imageCount, imageInput, err = o.loadPdf()
|
||||
default:
|
||||
err = fmt.Errorf("unknown file format (%s): support .cbz, .zip, .cbr, .rar, .pdf", ext)
|
||||
}
|
||||
}
|
||||
imageCount, imageInput, err := o.Load()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
_ "golang.org/x/image/webp"
|
||||
@ -42,6 +43,30 @@ type Options struct {
|
||||
|
||||
var errNoImagesFound = errors.New("no images found")
|
||||
|
||||
func (o *Options) Load() (totalImages int, output chan *tasks, err error) {
|
||||
fi, err := os.Stat(o.Input)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// get all images though a channel of bytes
|
||||
if fi.IsDir() {
|
||||
return o.loadDir()
|
||||
} else {
|
||||
switch ext := strings.ToLower(filepath.Ext(o.Input)); ext {
|
||||
case ".cbz", ".zip":
|
||||
return o.loadCbz()
|
||||
case ".cbr", ".rar":
|
||||
return o.loadCbr()
|
||||
case ".pdf":
|
||||
return o.loadPdf()
|
||||
default:
|
||||
err = fmt.Errorf("unknown file format (%s): support .cbz, .zip, .cbr, .rar, .pdf", ext)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load a directory of images
|
||||
func (o *Options) loadDir() (totalImages int, output chan *tasks, err error) {
|
||||
images := make([]string, 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user