-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplexarr.go
60 lines (46 loc) · 1.01 KB
/
plexarr.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package plexarr
import (
"github.com/pkg/errors"
"regexp"
)
type Pvr interface {
GetLibraryItems() (map[string]PvrItem, error)
}
type PvrItem struct {
Title string
Path string
PvrPath string
GUID []string
}
type LibraryType int
var (
MovieLibrary LibraryType = 1
TvLibrary LibraryType = 2
)
var (
// ErrPlexUnavailable may occur when a plex api cannot be validated
ErrPlexUnavailable = errors.New("plex unavailable")
// ErrFatal indicates a severe problem related to development.
ErrFatal = errors.New("fatal development related error")
)
type Rewrite struct {
From string `yaml:"from"`
To string `yaml:"to"`
}
type Rewriter func(string) string
func NewRewriter(r Rewrite) (Rewriter, error) {
if r.From == "" || r.To == "" {
rewriter := func(input string) string {
return input
}
return rewriter, nil
}
re, err := regexp.Compile(r.From)
if err != nil {
return nil, err
}
rewriter := func(input string) string {
return re.ReplaceAllString(input, r.To)
}
return rewriter, nil
}