Skip to content

Commit

Permalink
Changed Custom regex to struct, added separate Series and Film regex …
Browse files Browse the repository at this point in the history
…maps. Added example files. Modified readme.

Signed-off-by: gryffyn <[email protected]>
  • Loading branch information
gryffyn committed Dec 4, 2022
1 parent 5fc60a5 commit 8681a7a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 38 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.0.0] - 2022-09-07
### Added
- Added TOML config

### Fixed
- Better error handling

## [0.4.0] - 2022-08-10
### Added
- Added custom presets
Expand Down
30 changes: 3 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,14 @@ the regex argument takes in a regex with specifically-named named capture groups
| Film | {{ .Title }} ({{ .Year }}){{if .Options.Scene }} ({{ .Scene }}){{end}} | Film Title (YEAR).ext |


## Config File Example
## Config File

The configuration file is by default loaded from a file named `osiris.yml` (or `osiris.yaml`, or `osiris.toml`) in the current user's configuration directory (`~/.config/osiris` on Linux). The config file location can be overridden with the `-c` flag.

```yaml
---
seriesYear: true
scene: true
templates:
series: "{{ .Title }}{{if .Options.SeriesYear}} ({{ .Year }}){{end}} - {{ .Episode}}{{if EpisodeTitle}} - {{ .EpisodeTitle}}{{end}}{{if .Options.Scene }} ({{ .Scene }}){{end}}"
film: "{{ .Title }} ({{ .Year }}){{if .Options.Scene }} ({{ .Scene }}){{end}}"
regex:
series: '(?P<title>[\w\.]+)\.(?P<ep>S\d{2}E\d{2})\.(?P<eptitle>[\w\.-]+)(?P<scene>1080p.+)'
film:
custom:
yify: '(?P<title>[\w\.]+)\.(?P<year>\d{4})\.(?P<scene>(?:2160|1080|720)p[\w\.]+YIFY)'
```
```toml
SeriesYear = true
Scene = true

[Templates]
Series = "{{ .Title }}{{if .Options.SeriesYear}} ({{ .Year }}){{end}} - {{ .Episode}}{{if EpisodeTitle}} - {{ .EpisodeTitle}}{{end}}{{if .Options.Scene }} ({{ .Scene }}){{end}}"
Film = "{{ .Title }} ({{ .Year }}){{if .Options.Scene }} ({{ .Scene }}){{end}}"
### Example

[Regex]
Series = '(?P<title>[\w\.]+)\.(?P<ep>S\d{2}E\d{2})\.(?P<eptitle>[\w\.-]+)(?P<scene>1080p.+)'

[Regex.Custom]
yify = '(?P<title>[\w\.]+)\.(?P<year>\d{4})\.(?P<scene>(?:2160|1080|720)p[\w\.]+YIFY)'
```
See [contrib/osiris.example.yml](./contrib/osiris.example.yml) or [contrib/osiris.example.toml](./contrib/osiris.example.toml). Copy one of them to the configuration directory and modify as needed.

## Usage Example

Expand Down
13 changes: 8 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ type config struct {
Film *string `yaml:"film,omitempty"`
} `yaml:"templates,omitempty"`
Regex struct {
Series *string `yaml:"series,omitempty"`
Film *string `yaml:"film,omitempty"`
Custom map[*string]*string `yaml:"custom,omitempty"`
Series *string `yaml:"series,omitempty"`
Film *string `yaml:"film,omitempty"`
Custom struct {
Series map[*string]*string `yaml:"series,omitempty"`
Film map[*string]*string `yaml:"film,omitempty"`
} `yaml:"custom,omitempty"`
} `yaml:"regex,omitempty"`
}

func (c *config) Parse(data []byte) error {
err := toml.Unmarshal(data, c)
err := yaml.Unmarshal(data, c)
if err != nil {
return yaml.Unmarshal(data, c)
return toml.Unmarshal(data, c)
}
return err
}
Expand Down
18 changes: 18 additions & 0 deletions contrib/osiris.example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SeriesYear = true
Scene = true

[Templates]
Series = "{{ .Title }}{{if .Options.SeriesYear}} ({{ .Year }}){{end}} - {{ .Episode}}{{if EpisodeTitle}} - {{ .EpisodeTitle}}{{end}}{{if .Options.Scene }} ({{ .Scene }}){{end}}"
Film = "{{ .Title }} ({{ .Year }}){{if .Options.Scene }} ({{ .Scene }}){{end}}"

[Regex]
Series = '(?P<title>[\w\.]+)\.(?P<ep>S\d{2}E\d{2})\.(?P<eptitle>[\w\.-]+)(?P<scene>1080p.+)'
Film = '(?P<title>[\w\.]+)\.(?P<year>\d{4})\.(?P<scene>(?:2160|1080|720)p[\w\.-]+(?:[\w\.]))'

[Regex.Custom.Film]
# rarbg and yify
Generic = '(?P<title>[\w\.]+)\.(?P<year>\d{4})\.(?P<scene>(?:2160|1080|720)p[\w\.-]+(?:[\w\.]))'

[Regex.Custom.Series]
# rarbg, yify, publichd
Generic = '(?P<title>[\w\.]+)\.(?P<ep>S\d{2}E\d{2})\.(?P<scene>(?:2160|1080|720)p[\w\.-]+(?:[\w\.]]))'
16 changes: 16 additions & 0 deletions contrib/osiris.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
seriesYear: true
scene: true
templates:
series: "{{ .Title }}{{if .Options.SeriesYear}} ({{ .Year }}){{end}} - {{ .Episode}}{{if EpisodeTitle}} - {{ .EpisodeTitle}}{{end}}{{if .Options.Scene }} ({{ .Scene }}){{end}}"
film: "{{ .Title }} ({{ .Year }}){{if .Options.Scene }} ({{ .Scene }}){{end}}"
regex:
series: '(?P<title>[\w\.]+)\.(?P<ep>S\d{2}E\d{2})\.(?P<eptitle>[\w\.-]+)(?P<scene>1080p.+)'
film: '(?P<title>[\w\.]+)\.(?P<year>\d{4})\.(?P<scene>(?:2160|1080|720)p[\w\.-]+(?:[\w\.]))'
custom:
film:
# rarbg and yify
generic: '(?P<title>[\w\.]+)\.(?P<year>\d{4})\.(?P<scene>(?:2160|1080|720)p[\w\.-]+(?:[\w\.]))'
series:
# rarbg, yify, publichd
generic: '(?P<title>[\w\.]+)\.(?P<ep>S\d{2}E\d{2})\.(?P<scene>(?:2160|1080|720)p[\w\.-]+(?:[\w\.]]))'
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module git.gryffyn.io/gryffyn/osiris
go 1.14

require (
github.com/BurntSushi/toml v1.2.0 // indirect
github.com/BurntSushi/toml v1.2.0
github.com/fatih/color v1.13.0
github.com/jessevdk/go-flags v1.5.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
19 changes: 14 additions & 5 deletions osiris.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func main() {
var re *regexp.Regexp

if args.Preset != "" {
pre, err := getCustomPreset(&cfg, &args.Preset)
pre, err := getCustomPreset(&cfg, &args.Preset, args.Film)
if err != nil {
log.Fatalln(err)
}
Expand Down Expand Up @@ -223,10 +223,19 @@ func renameFile(filepath, newfilepath *string) {
}
}

func getCustomPreset(cfg *config, preset *string) (*string, error) {
for k, v := range cfg.Regex.Custom {
if *k == *preset {
return v, nil
func getCustomPreset(cfg *config, preset *string, film bool) (*string, error) {
switch film {
case true:
for k, v := range cfg.Regex.Custom.Film {
if *k == *preset {
return v, nil
}
}
case false:
for k, v := range cfg.Regex.Custom.Series {
if *k == *preset {
return v, nil
}
}
}

Expand Down

0 comments on commit 8681a7a

Please sign in to comment.