mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 00:02:37 +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
|
package epubimageprocessing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"image"
|
"image"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -33,31 +31,7 @@ func isSupportedImage(path string) bool {
|
|||||||
func LoadImages(o *Options) ([]*epubimage.Image, error) {
|
func LoadImages(o *Options) ([]*epubimage.Image, error) {
|
||||||
images := make([]*epubimage.Image, 0)
|
images := make([]*epubimage.Image, 0)
|
||||||
|
|
||||||
fi, err := os.Stat(o.Input)
|
imageCount, imageInput, err := o.Load()
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
_ "golang.org/x/image/webp"
|
_ "golang.org/x/image/webp"
|
||||||
@ -42,6 +43,30 @@ type Options struct {
|
|||||||
|
|
||||||
var errNoImagesFound = errors.New("no images found")
|
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
|
// load a directory of images
|
||||||
func (o *Options) loadDir() (totalImages int, output chan *tasks, err error) {
|
func (o *Options) loadDir() (totalImages int, output chan *tasks, err error) {
|
||||||
images := make([]string, 0)
|
images := make([]string, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user