mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
split profiles and options
This commit is contained in:
parent
49056e71d9
commit
3fd1529bb1
@ -9,6 +9,8 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/celogeek/go-comic-converter/internal/converter/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
type converterOrder struct {
|
type converterOrder struct {
|
||||||
@ -20,7 +22,7 @@ type converterOrder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Converter struct {
|
type Converter struct {
|
||||||
Options *Options
|
Options *options.Options
|
||||||
Cmd *flag.FlagSet
|
Cmd *flag.FlagSet
|
||||||
|
|
||||||
order []converterOrder
|
order []converterOrder
|
||||||
@ -28,7 +30,7 @@ type Converter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New() *Converter {
|
func New() *Converter {
|
||||||
options := NewOptions()
|
options := options.New()
|
||||||
cmd := flag.NewFlagSet("go-comic-converter", flag.ExitOnError)
|
cmd := flag.NewFlagSet("go-comic-converter", flag.ExitOnError)
|
||||||
conv := &Converter{
|
conv := &Converter{
|
||||||
Options: options,
|
Options: options,
|
||||||
@ -83,7 +85,7 @@ func (c *Converter) InitParse() {
|
|||||||
c.AddBoolParam(&c.Options.Dry, "dry", false, "Dry run to show all options")
|
c.AddBoolParam(&c.Options.Dry, "dry", false, "Dry run to show all options")
|
||||||
|
|
||||||
c.AddSection("Config")
|
c.AddSection("Config")
|
||||||
c.AddStringParam(&c.Options.Profile, "profile", c.Options.Profile, fmt.Sprintf("Profile to use: \n%s", c.Options.profiles))
|
c.AddStringParam(&c.Options.Profile, "profile", c.Options.Profile, fmt.Sprintf("Profile to use: \n%s", c.Options.AvailableProfiles()))
|
||||||
c.AddIntParam(&c.Options.Quality, "quality", c.Options.Quality, "Quality of the image")
|
c.AddIntParam(&c.Options.Quality, "quality", c.Options.Quality, "Quality of the image")
|
||||||
c.AddBoolParam(&c.Options.Crop, "crop", c.Options.Crop, "Crop images")
|
c.AddBoolParam(&c.Options.Crop, "crop", c.Options.Crop, "Crop images")
|
||||||
c.AddIntParam(&c.Options.Brightness, "brightness", c.Options.Brightness, "Brightness readjustement: between -100 and 100, > 0 lighter, < 0 darker")
|
c.AddIntParam(&c.Options.Brightness, "brightness", c.Options.Brightness, "Brightness readjustement: between -100 and 100, > 0 lighter, < 0 darker")
|
||||||
@ -238,7 +240,7 @@ func (c *Converter) Validate() error {
|
|||||||
return errors.New("profile missing")
|
return errors.New("profile missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := c.Options.profiles[c.Options.Profile]; !ok {
|
if p := c.Options.GetProfile(); p == nil {
|
||||||
return fmt.Errorf("profile %q doesn't exists", c.Options.Profile)
|
return fmt.Errorf("profile %q doesn't exists", c.Options.Profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package converter
|
package options
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/celogeek/go-comic-converter/internal/converter/profiles"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,10 +33,10 @@ type Options struct {
|
|||||||
AddPanelView bool `yaml:"add_panel_view"`
|
AddPanelView bool `yaml:"add_panel_view"`
|
||||||
LimitMb int `yaml:"limit_mb"`
|
LimitMb int `yaml:"limit_mb"`
|
||||||
|
|
||||||
profiles Profiles
|
profiles profiles.Profiles
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOptions() *Options {
|
func New() *Options {
|
||||||
return &Options{
|
return &Options{
|
||||||
Profile: "",
|
Profile: "",
|
||||||
Quality: 85,
|
Quality: 85,
|
||||||
@ -49,8 +50,7 @@ func NewOptions() *Options {
|
|||||||
HasCover: true,
|
HasCover: true,
|
||||||
AddPanelView: false,
|
AddPanelView: false,
|
||||||
LimitMb: 0,
|
LimitMb: 0,
|
||||||
|
profiles: profiles.New(),
|
||||||
profiles: NewProfile(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,14 +96,6 @@ func (o *Options) LoadDefault() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Options) GetProfile() *Profile {
|
|
||||||
if profile, ok := o.profiles[o.Profile]; ok {
|
|
||||||
return &profile
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Options) ShowDefault() string {
|
func (o *Options) ShowDefault() string {
|
||||||
var profileDesc string
|
var profileDesc string
|
||||||
profile := o.GetProfile()
|
profile := o.GetProfile()
|
||||||
@ -158,3 +150,11 @@ func (o *Options) SaveDefault() error {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
return yaml.NewEncoder(f).Encode(o)
|
return yaml.NewEncoder(f).Encode(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Options) GetProfile() *profiles.Profile {
|
||||||
|
return o.profiles.Get(o.Profile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Options) AvailableProfiles() string {
|
||||||
|
return o.profiles.String()
|
||||||
|
}
|
@ -1,69 +0,0 @@
|
|||||||
package converter
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image/color"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/celogeek/go-comic-converter/internal/epub"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Profile struct {
|
|
||||||
Code string
|
|
||||||
Description string
|
|
||||||
Width int
|
|
||||||
Height int
|
|
||||||
Palette color.Palette
|
|
||||||
}
|
|
||||||
|
|
||||||
type Profiles map[string]Profile
|
|
||||||
|
|
||||||
var profiles = []Profile{
|
|
||||||
{"KS", "Kindle 1", 600, 670, epub.PALETTE_4},
|
|
||||||
{"K11", "Kindle 11", 1072, 1448, epub.PALETTE_16},
|
|
||||||
{"K2", "Kindle 2", 600, 670, epub.PALETTE_15},
|
|
||||||
{"K34", "Kindle Keyboard/Touch", 600, 800, epub.PALETTE_16},
|
|
||||||
{"K578", "Kindle", 600, 800, epub.PALETTE_16},
|
|
||||||
{"KDX", "Kindle DX/DXG", 824, 1000, epub.PALETTE_16},
|
|
||||||
{"KPW", "Kindle Paperwhite 1/2", 758, 1024, epub.PALETTE_16},
|
|
||||||
{"KV", "Kindle Paperwhite 3/4/Voyage/Oasis", 1072, 1448, epub.PALETTE_16},
|
|
||||||
{"KPW5", "Kindle Paperwhite 5/Signature Edition", 1236, 1648, epub.PALETTE_16},
|
|
||||||
{"KO", "Kindle Oasis 2/3", 1264, 1680, epub.PALETTE_16},
|
|
||||||
{"KS", "Kindle Scribe", 1860, 2480, epub.PALETTE_16},
|
|
||||||
// Kobo
|
|
||||||
{"KoMT", "Kobo Mini/Touch", 600, 800, epub.PALETTE_16},
|
|
||||||
{"KoG", "Kobo Glo", 768, 1024, epub.PALETTE_16},
|
|
||||||
{"KoGHD", "Kobo Glo HD", 1072, 1448, epub.PALETTE_16},
|
|
||||||
{"KoA", "Kobo Aura", 758, 1024, epub.PALETTE_16},
|
|
||||||
{"KoAHD", "Kobo Aura HD", 1080, 1440, epub.PALETTE_16},
|
|
||||||
{"KoAH2O", "Kobo Aura H2O", 1080, 1430, epub.PALETTE_16},
|
|
||||||
{"KoAO", "Kobo Aura ONE", 1404, 1872, epub.PALETTE_16},
|
|
||||||
{"KoN", "Kobo Nia", 758, 1024, epub.PALETTE_16},
|
|
||||||
{"KoC", "Kobo Clara HD/Kobo Clara 2E", 1072, 1448, epub.PALETTE_16},
|
|
||||||
{"KoL", "Kobo Libra H2O/Kobo Libra 2", 1264, 1680, epub.PALETTE_16},
|
|
||||||
{"KoF", "Kobo Forma", 1440, 1920, epub.PALETTE_16},
|
|
||||||
{"KoS", "Kobo Sage", 1440, 1920, epub.PALETTE_16},
|
|
||||||
{"KoE", "Kobo Elipsa", 1404, 1872, epub.PALETTE_16},
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewProfile() Profiles {
|
|
||||||
r := Profiles{}
|
|
||||||
for _, profile := range profiles {
|
|
||||||
r[profile.Code] = profile
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Profiles) String() string {
|
|
||||||
s := make([]string, 0)
|
|
||||||
for _, v := range profiles {
|
|
||||||
s = append(s, fmt.Sprintf(
|
|
||||||
" - %-7s ( %9s ) - %2d levels of gray - %s",
|
|
||||||
v.Code,
|
|
||||||
fmt.Sprintf("%dx%d", v.Width, v.Height),
|
|
||||||
len(v.Palette),
|
|
||||||
v.Description,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
return strings.Join(s, "\n")
|
|
||||||
}
|
|
72
internal/converter/profiles/core.go
Normal file
72
internal/converter/profiles/core.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package profiles
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"image/color"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/celogeek/go-comic-converter/internal/epub"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Profile struct {
|
||||||
|
Code string
|
||||||
|
Description string
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
|
Palette color.Palette
|
||||||
|
}
|
||||||
|
|
||||||
|
type Profiles []Profile
|
||||||
|
|
||||||
|
func New() Profiles {
|
||||||
|
return []Profile{
|
||||||
|
{"KS", "Kindle 1", 600, 670, epub.PALETTE_4},
|
||||||
|
{"K11", "Kindle 11", 1072, 1448, epub.PALETTE_16},
|
||||||
|
{"K2", "Kindle 2", 600, 670, epub.PALETTE_15},
|
||||||
|
{"K34", "Kindle Keyboard/Touch", 600, 800, epub.PALETTE_16},
|
||||||
|
{"K578", "Kindle", 600, 800, epub.PALETTE_16},
|
||||||
|
{"KDX", "Kindle DX/DXG", 824, 1000, epub.PALETTE_16},
|
||||||
|
{"KPW", "Kindle Paperwhite 1/2", 758, 1024, epub.PALETTE_16},
|
||||||
|
{"KV", "Kindle Paperwhite 3/4/Voyage/Oasis", 1072, 1448, epub.PALETTE_16},
|
||||||
|
{"KPW5", "Kindle Paperwhite 5/Signature Edition", 1236, 1648, epub.PALETTE_16},
|
||||||
|
{"KO", "Kindle Oasis 2/3", 1264, 1680, epub.PALETTE_16},
|
||||||
|
{"KS", "Kindle Scribe", 1860, 2480, epub.PALETTE_16},
|
||||||
|
// Kobo
|
||||||
|
{"KoMT", "Kobo Mini/Touch", 600, 800, epub.PALETTE_16},
|
||||||
|
{"KoG", "Kobo Glo", 768, 1024, epub.PALETTE_16},
|
||||||
|
{"KoGHD", "Kobo Glo HD", 1072, 1448, epub.PALETTE_16},
|
||||||
|
{"KoA", "Kobo Aura", 758, 1024, epub.PALETTE_16},
|
||||||
|
{"KoAHD", "Kobo Aura HD", 1080, 1440, epub.PALETTE_16},
|
||||||
|
{"KoAH2O", "Kobo Aura H2O", 1080, 1430, epub.PALETTE_16},
|
||||||
|
{"KoAO", "Kobo Aura ONE", 1404, 1872, epub.PALETTE_16},
|
||||||
|
{"KoN", "Kobo Nia", 758, 1024, epub.PALETTE_16},
|
||||||
|
{"KoC", "Kobo Clara HD/Kobo Clara 2E", 1072, 1448, epub.PALETTE_16},
|
||||||
|
{"KoL", "Kobo Libra H2O/Kobo Libra 2", 1264, 1680, epub.PALETTE_16},
|
||||||
|
{"KoF", "Kobo Forma", 1440, 1920, epub.PALETTE_16},
|
||||||
|
{"KoS", "Kobo Sage", 1440, 1920, epub.PALETTE_16},
|
||||||
|
{"KoE", "Kobo Elipsa", 1404, 1872, epub.PALETTE_16},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Profiles) String() string {
|
||||||
|
s := make([]string, 0)
|
||||||
|
for _, v := range p {
|
||||||
|
s = append(s, fmt.Sprintf(
|
||||||
|
" - %-7s ( %9s ) - %2d levels of gray - %s",
|
||||||
|
v.Code,
|
||||||
|
fmt.Sprintf("%dx%d", v.Width, v.Height),
|
||||||
|
len(v.Palette),
|
||||||
|
v.Description,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
return strings.Join(s, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Profiles) Get(name string) *Profile {
|
||||||
|
for _, profile := range p {
|
||||||
|
if profile.Code == name {
|
||||||
|
return &profile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user