-
Notifications
You must be signed in to change notification settings - Fork 2
/
group.go
40 lines (37 loc) · 1.04 KB
/
group.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
package torrentparser
import (
"regexp"
"strings"
)
var (
groupDZon3 = regexp.MustCompile(`(?i)D-Z0N3`)
groupEnd = regexp.MustCompile(`(?i)- ?([^\-. ]+)(?:\.\w+)?$`)
groupStart = regexp.MustCompile(`(?i)^(\w+-)`)
groupBracketStart = regexp.MustCompile(`(?i)^(\[[^\]]+\])`)
)
func (p *parser) GetGroup() string {
group := p.FindString("group", groupDZon3, FindStringOptions{})
if group != "" {
return group
}
group = p.FindString("group", groupEnd, FindStringOptions{Handler: func(str string) string {
name := strings.TrimPrefix(str, "-")
name = strings.TrimPrefix(name, " ")
return name
}})
if group != "" {
return group
}
group = p.FindString("group", groupStart, FindStringOptions{Handler: func(str string) string {
return strings.TrimSuffix(str, "-")
}})
if group != "" {
return group
}
group = p.FindString("group", groupBracketStart, FindStringOptions{Handler: func(str string) string {
name := strings.TrimPrefix(str, "[")
name = strings.TrimSuffix(name, "]")
return name
}})
return group
}