From e8401db5194fa740306b9090eed845382ad6bc52 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 18 Jul 2025 16:55:54 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Make=20IntOrString=20support=20?= =?UTF-8?q?TOML=20as=20well?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/int_string.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ types/toml.go | 25 ++++++++++++++++++++++ types/yaml.go | 18 +--------------- 3 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 types/int_string.go create mode 100644 types/toml.go diff --git a/types/int_string.go b/types/int_string.go new file mode 100644 index 0000000..780644d --- /dev/null +++ b/types/int_string.go @@ -0,0 +1,51 @@ +package types + +import "fmt" + +type IntOrString struct { + intVal int + strVal string + isInt bool +} + +func (is *IntOrString) Set(val any) error { + switch v := val.(type) { + case int: + case int8: + case int16: + case int32: + case int64: + case uint: + case uint8: + case uint16: + case uint32: + is.isInt = true + is.intVal = int(v) + return nil + case string: + is.isInt = false + is.strVal = v + return nil + case []byte: + is.isInt = false + is.strVal = string(v) + return nil + } + + //nolint:err113 // Temp skip + return fmt.Errorf("invalid type: %T", val) +} + +func (is IntOrString) IsZero() bool { + if is.isInt { + return is.intVal == 0 + } + return is.strVal == "" +} + +func (is IntOrString) Value() any { + if is.isInt { + return is.intVal + } + return is.strVal +} diff --git a/types/toml.go b/types/toml.go new file mode 100644 index 0000000..cc50593 --- /dev/null +++ b/types/toml.go @@ -0,0 +1,25 @@ +package types + +import "fmt" + +type TomlTypeError struct { + Value any +} + +func (te *TomlTypeError) Error() string { + return fmt.Sprintf("unsupported type: %T", te.Value) +} + +func (is *IntOrString) UnmarshalTOML(val any) error { + switch v := val.(type) { + case string: + is.isInt = false + is.strVal = v + return nil + case int64: + is.isInt = true + is.intVal = int(v) + return nil + } + return &TomlTypeError{Value: val} +} diff --git a/types/yaml.go b/types/yaml.go index 4fa1d1b..d0b7d6d 100644 --- a/types/yaml.go +++ b/types/yaml.go @@ -10,17 +10,8 @@ func (ye *YamlTypeError) Error() string { return ye.Node.Tag + " is not a valid type for this field" } -type IntOrString struct { - intVal int - strVal string - isInt bool -} - func (is IntOrString) MarshalYAML() (any, error) { - if is.isInt { - return is.intVal, nil - } - return is.strVal, nil + return is.Value(), nil } func (is *IntOrString) UnmarshalYAML(value *yaml.Node) error { @@ -36,10 +27,3 @@ func (is *IntOrString) UnmarshalYAML(value *yaml.Node) error { return &YamlTypeError{Node: value} } - -func (is IntOrString) IsZero() bool { - if is.isInt { - return is.intVal == 0 - } - return is.strVal == "" -} From 75c6ce47e1b1dbe49cbd876d1a9a4488057128ee Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Wed, 3 Sep 2025 11:24:23 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20Add=20quality=20to=20mkflex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Taskfile.yml | 17 +++++++++++++++++ convids/models.go | 1 + mkflex/logic.go | 3 +++ 3 files changed, 21 insertions(+) diff --git a/Taskfile.yml b/Taskfile.yml index 50c0b63..29b95a6 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -36,6 +36,22 @@ tasks: cmds: - go build -o build/ ./cmd/{{.CMD}} + build-mkflex: + desc: Builds the mkflex command + sources: + - cmd/mkflex/**/*.go + - cli/**/*.go + - convids/**/*.go + - internal/cli/mkflex/**/*.go + - mkflex/**/*.go + - types/**/*.go + generates: + - builds/mkflex + cmds: + - task: cmd-build + vars: + CMD: mkflex + build-convids: desc: Builds the convids command sources: @@ -77,6 +93,7 @@ tasks: desc: Installs the mkflex command source: - cmd/mkflex/**/*.go + - cli/**/*.go - convids/**/*.go - internal/cli/mkflex/**/*.go - mkflex/**/*.go diff --git a/convids/models.go b/convids/models.go index 5473ffd..779fbfa 100644 --- a/convids/models.go +++ b/convids/models.go @@ -38,6 +38,7 @@ type Show struct { AlternateName []string `yaml:"alternate_name"` Exact bool Skip bool + Quality string } re *regexp.Regexp diff --git a/mkflex/logic.go b/mkflex/logic.go index 963a4d4..5c64b3f 100644 --- a/mkflex/logic.go +++ b/mkflex/logic.go @@ -90,6 +90,9 @@ func getShow(show conutils.Show, sh Series) SeriesGroups { if !show.Flexget.Begin.IsZero() { sh.Begin = show.Flexget.Begin } + if show.Flexget.Quality != "" { + sh.Quality = show.Flexget.Quality + } sh.AlternameName = show.Flexget.AlternateName sh.Exact = show.Flexget.Exact name := cmp.Or(show.Flexget.Name, show.Name, show.Pattern)