mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2025-10-14 04:28:51 +02:00
fix: check for converter ready to do its job
This commit is contained in:
@@ -50,6 +50,11 @@ func ConvertCbzCommand(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get chapterConverter: %v", err)
|
return fmt.Errorf("failed to get chapterConverter: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = chapterConverter.PrepareConverter()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to prepare converter: %v", err)
|
||||||
|
}
|
||||||
// Channel to manage the files to process
|
// Channel to manage the files to process
|
||||||
fileChan := make(chan string)
|
fileChan := make(chan string)
|
||||||
|
|
||||||
|
@@ -13,6 +13,7 @@ type Converter interface {
|
|||||||
// Format of the converter
|
// Format of the converter
|
||||||
Format() (format constant.ConversionFormat)
|
Format() (format constant.ConversionFormat)
|
||||||
ConvertChapter(chapter *packer.Chapter, quality uint8, progress func(string)) (*packer.Chapter, error)
|
ConvertChapter(chapter *packer.Chapter, quality uint8, progress func(string)) (*packer.Chapter, error)
|
||||||
|
PrepareConverter() error
|
||||||
}
|
}
|
||||||
|
|
||||||
var converters = map[constant.ConversionFormat]Converter{
|
var converters = map[constant.ConversionFormat]Converter{
|
||||||
|
@@ -21,6 +21,7 @@ import (
|
|||||||
type Converter struct {
|
type Converter struct {
|
||||||
maxHeight int
|
maxHeight int
|
||||||
cropHeight int
|
cropHeight int
|
||||||
|
isPrepared bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (converter *Converter) Format() (format constant.ConversionFormat) {
|
func (converter *Converter) Format() (format constant.ConversionFormat) {
|
||||||
@@ -32,11 +33,24 @@ func New() *Converter {
|
|||||||
//maxHeight: 16383 / 2,
|
//maxHeight: 16383 / 2,
|
||||||
maxHeight: 4000,
|
maxHeight: 4000,
|
||||||
cropHeight: 2000,
|
cropHeight: 2000,
|
||||||
|
isPrepared: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (converter *Converter) ConvertChapter(chapter *packer2.Chapter, quality uint8, progress func(string)) (*packer2.Chapter, error) {
|
func (converter *Converter) PrepareConverter() error {
|
||||||
|
if converter.isPrepared {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
err := PrepareEncoder()
|
err := PrepareEncoder()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
converter.isPrepared = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (converter *Converter) ConvertChapter(chapter *packer2.Chapter, quality uint8, progress func(string)) (*packer2.Chapter, error) {
|
||||||
|
err := converter.PrepareConverter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user