add limit option

This commit is contained in:
Celogeek 2022-12-27 15:32:54 +01:00
parent 0ee44ed40b
commit 95eb3497e7
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 21 additions and 7 deletions

View File

@ -45,6 +45,7 @@ type EPub struct {
ViewHeight int ViewHeight int
Quality int Quality int
Crop bool Crop bool
LimitMb int
Images []*Images Images []*Images
FirstImageTitle string FirstImageTitle string
@ -99,6 +100,11 @@ func (e *EPub) SetCrop(c bool) *EPub {
return e return e
} }
func (e *EPub) SetLimitMb(l int) *EPub {
e.LimitMb = l
return e
}
func (e *EPub) WriteString(wz *zip.Writer, file string, content string) error { func (e *EPub) WriteString(wz *zip.Writer, file string, content string) error {
return e.WriteBuffer(wz, file, strings.NewReader(content)) return e.WriteBuffer(wz, file, strings.NewReader(content))
} }

22
main.go
View File

@ -26,6 +26,7 @@ type Option struct {
Title string Title string
Quality int Quality int
NoCrop bool NoCrop bool
LimitMb int
} }
func (o *Option) String() string { func (o *Option) String() string {
@ -36,15 +37,20 @@ func (o *Option) String() string {
width = profile.Width width = profile.Width
height = profile.Height height = profile.Height
} }
limitmb := "nolimit"
if o.LimitMb > 0 {
limitmb = fmt.Sprintf("%d Mb", o.LimitMb)
}
return fmt.Sprintf(`Options: return fmt.Sprintf(`Options:
Input : %s Input : %s
Output : %s Output : %s
Profile: %s - %s - %dx%d Profile: %s - %s - %dx%d
Author : %s Author : %s
Title : %s Title : %s
Quality: %d Quality: %d
Crop : %v Crop : %v
LimitMb: %s
`, `,
o.Input, o.Input,
o.Output, o.Output,
@ -56,6 +62,7 @@ func (o *Option) String() string {
o.Title, o.Title,
o.Quality, o.Quality,
!o.NoCrop, !o.NoCrop,
limitmb,
) )
} }
@ -73,6 +80,7 @@ func main() {
flag.StringVar(&opt.Title, "title", "", "Title of the epub") flag.StringVar(&opt.Title, "title", "", "Title of the epub")
flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image: Default 75") flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image: Default 75")
flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping: Default false") flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping: Default false")
flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit")
flag.Parse() flag.Parse()
if opt.Input == "" || opt.Output == "" { if opt.Input == "" || opt.Output == "" {