Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Signed-off-by: gryffyn <[email protected]>
  • Loading branch information
gryffyn committed Jun 12, 2022
2 parents 4e04925 + 9821497 commit a0d59b0
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 5 deletions.
18 changes: 16 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
package main

import "gopkg.in/yaml.v2"
import (
"gopkg.in/yaml.v3"
)

type config struct {
SeriesYear *bool `yaml:"seriesYear,omitempty"`
Scene *bool `yaml:"scene,omitempty"`
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
}
Expand Down
70 changes: 70 additions & 0 deletions contrib/osiris.1
Original file line number Diff line number Diff line change
@@ -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<title>\[rs]w+).(?P<ep>S\[rs]d{2}E\[rs]d{2})\[rs].(?P<eptitle>[\[rs]w\[rs].]+)\[rs].(?P<scene>WEB-.+)' 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 <[email protected]>.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
40 changes: 38 additions & 2 deletions osiris.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a0d59b0

Please sign in to comment.