-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessor.go
More file actions
36 lines (30 loc) · 876 Bytes
/
Processor.go
File metadata and controls
36 lines (30 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"regexp"
)
type Processor struct {
OutputPattern string
SearchRegex *regexp.Regexp
}
func NewProcessor(searchPattern string, outputPattern string) *Processor {
return &Processor{
OutputPattern: outputPattern,
SearchRegex: regexp.MustCompile(searchPattern),
}
}
func (p *Processor) Match(oldName string) bool {
return p.SearchRegex.MatchString(oldName)
}
func (p *Processor) Replace(oldName string, seasonNum uint, epNum uint) string {
replacement := fmt.Sprintf(p.OutputPattern, seasonNum, epNum)
return p.SearchRegex.ReplaceAllString(oldName, replacement)
}
func getDefaultProcessors() []*Processor {
return []*Processor{
NewProcessor("S[0-9]+E[0-9]+", "S%02dE%02d"),
NewProcessor(" [0-9]{1,2}x[0-9]+ ", " S%02dE%02d "),
NewProcessor("^E[0-9]+", "S%02dE%02d"),
NewProcessor("[_ ][0-9]+[_ .]", "_S%02dE%02d_"),
}
}