diff --git a/config.go b/config.go
index 20be917..a5d4cae 100644
--- a/config.go
+++ b/config.go
@@ -1,6 +1,8 @@
package main
-import "gopkg.in/yaml.v2"
+import (
+ "gopkg.in/yaml.v3"
+)
type config struct {
SeriesYear *bool `yaml:"seriesYear,omitempty"`
@@ -8,14 +10,26 @@ type config struct {
Templates struct {
Series *string `yaml:"series,omitempty"`
Film *string `yaml:"film,omitempty"`
- } `yaml:"templates"`
+ } `yaml:"templates,omitempty"`
+ Regex struct {
+ Series *string `yaml:"series,omitempty"`
+ Film *string `yaml:"film,omitempty"`
+ } `yaml:"regex,omitempty"`
}
func (c *config) Parse(data []byte) error {
return yaml.Unmarshal(data, c)
}
+// Argparse replaces config values with provided cli flag values
func (c *config) Argparse(args *args) {
+ if args.Regex != "" {
+ if args.Film {
+ c.Regex.Film = &args.Regex
+ } else {
+ c.Regex.Series = &args.Regex
+ }
+ }
if args.Scene {
c.Scene = &args.Scene
}
diff --git a/contrib/osiris.1 b/contrib/osiris.1
new file mode 100644
index 0000000..2c356a3
--- /dev/null
+++ b/contrib/osiris.1
@@ -0,0 +1,70 @@
+.\" Automatically generated by Pandoc 2.18
+.\"
+.\" Define V font for inline verbatim, using C font in formats
+.\" that render this, and otherwise B font.
+.ie "\f[CB]x\f[]"x" \{\
+. ftr V B
+. ftr VI BI
+. ftr VB B
+. ftr VBI BI
+.\}
+.el \{\
+. ftr V CR
+. ftr VI CI
+. ftr VB CB
+. ftr VBI CBI
+.\}
+.TH "OSIRIS" "1" "June 2022" "osiris 0.3.0" ""
+.hy
+.SH NAME
+.PP
+osiris - rename films / tv series based on named regex capture groups
+and Go templates
+.SH SYNOPSIS
+.PP
+\f[B]osiris\f[R] [\f[I]OPTIONS\f[R]] [\f[I]FILENAME\&...\f[R]]
+.SH DESCRIPTION
+.PP
+\f[B]osiris\f[R] uses named capture groups in regex patterns and Go
+templates to format film / tv series filenames.
+.SH OPTIONS
+.TP
+\f[B]-d\f[R], \f[B]\[en]dryrun\f[R]
+perform a dry run (does not modify files)
+.TP
+\f[B]-s\f[R], \f[B]\[en]silent\f[R]
+does not print output, useful for scripts
+.TP
+\f[B]-f\f[R], \f[B]\[en]film\f[R]
+uses film input and output formats
+.TP
+\f[B]-Y\f[R], \f[B]\[en]seriesyear\f[R]
+toggles series year in output
+.TP
+\f[B]-S\f[R], \f[B]\[en]scene\f[R]
+toggles scene info in output
+.TP
+\f[B]-y\f[R], \f[B]\[en]year=\f[R]
+release year override
+.TP
+\f[B]-t\f[R], \f[B]\[en]title=\f[R]
+release title override
+.TP
+\f[B]-c\f[R], \f[B]\[en]config=\f[R]
+config file (default \[ti]/.config/osiris/osiris.yml)
+.TP
+\f[B]-r\f[R], \f[B]\[en]regex\f[R]
+input regex pattern
+.SH EXAMPLES
+.TP
+\f[B]osiris -h\f[R]
+displays usage information, then exits
+.TP
+\f[B]osiris -r `(?P
\[rs]w+).(?PS\[rs]d{2}E\[rs]d{2})\[rs].(?P[\[rs]w\[rs].]+)\[rs].(?PWEB-.+)' Title.S01E01.Episode.Title.WEB-DL.H264.SCENE.mkv\f[R]
+renames provided file according to the default output template, using
+the provided input regex
+.SH BUGS
+.PP
+probably
+.SH AUTHORS
+gryffyn .
diff --git a/go.mod b/go.mod
index b13de9d..b5bc6e2 100644
--- a/go.mod
+++ b/go.mod
@@ -5,6 +5,5 @@ go 1.14
require (
github.com/fatih/color v1.13.0
github.com/jessevdk/go-flags v1.5.0
- gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
diff --git a/osiris.go b/osiris.go
index 7bcaf21..dcea8ba 100644
--- a/osiris.go
+++ b/osiris.go
@@ -1,3 +1,27 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2022.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
package main
import (
@@ -39,8 +63,8 @@ type args struct {
Year string `short:"y" long:"year" description:"release year override"`
Title string `short:"t" long:"title" description:"release title override"`
ConfigFile string `short:"c" long:"config" description:"config file (default ~/.config/osiris/osiris.yml"`
+ Regex string `short:"r" long:"regex" description:"input regex pattern"`
Positional struct {
- Regex string `positional-arg-name:"regex" required:"true"`
Filename []string `positional-arg-name:"filename" required:"true"`
} `positional-args:"true"`
}
@@ -87,7 +111,19 @@ func main() {
}
cfg.Argparse(&args)
- re, err := regexp.Compile(args.Positional.Regex)
+ var re *regexp.Regexp
+ if args.Film {
+ if cfg.Regex.Film == nil || *cfg.Regex.Film == "" {
+ log.Fatalln("Regex must be provided by `-r` flag or in osiris.yml")
+ }
+ re, err = regexp.Compile(*cfg.Regex.Film)
+ } else {
+ if cfg.Regex.Series == nil || *cfg.Regex.Series == "" {
+ log.Fatalln("Regex must be provided by `-r` flag or in osiris.yml")
+ }
+ re, err = regexp.Compile(*cfg.Regex.Series)
+ }
+
if err != nil {
log.Fatalf("Failed to parse regex: %v\n", err)
}