-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser_helper.go
71 lines (58 loc) · 1.78 KB
/
parser_helper.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
61
62
63
64
65
66
67
68
69
70
71
package habari
import (
"regexp"
"strconv"
"strings"
)
func extractSeasonAndEpisode(input string) (season string, separator string, episode string, ok bool) {
re := regexp.MustCompile(`(?i)^(s?)(\d+)(e|x|ep)((\d+)('|([vV]\d{1,2}))?)$`)
captures := re.FindStringSubmatch(input)
if captures == nil {
return "", "", "", false
}
season = strings.TrimSpace(captures[2])
separator = strings.TrimSpace(captures[3])
episode = strings.TrimSpace(captures[4])
ok = true
// Make sure numbers are zero-padded to avoid capturing strings like "1x3"
if strings.ToLower(separator) == "x" {
//nSeason, _ := strconv.Atoi(season)
nEpisode, _ := strconv.Atoi(episode)
//if nSeason < 10 && !strings.HasPrefix(season, "0") {
// return "", "", "", false
//}
if season == "0" && nEpisode > 500 { // avoid 0x539
return "", "", "", false
}
if nEpisode < 10 && !strings.HasPrefix(episode, "0") {
return "", "", "", false
}
}
return
}
func extractSeasonAndPart(input string) (season string, separator string, part string, ok bool) {
re := regexp.MustCompile(`(?i)^(s?)(\d+)(p)((\d+)('|([vV]\d{1,2}))?)$`)
captures := re.FindStringSubmatch(input)
if captures == nil {
return "", "", "", false
}
season = strings.TrimSpace(captures[2])
separator = strings.TrimSpace(captures[3])
part = strings.TrimSpace(captures[4])
ok = true
// Make sure numbers are zero-padded to avoid capturing strings like "1x3"
if strings.ToLower(separator) == "x" {
//nSeason, _ := strconv.Atoi(season)
nPart, _ := strconv.Atoi(part)
//if nSeason < 10 && !strings.HasPrefix(season, "0") {
// return "", "", "", false
//}
if season == "0" && nPart > 500 { // avoid 0x539
return "", "", "", false
}
if nPart < 10 && !strings.HasPrefix(part, "0") {
return "", "", "", false
}
}
return
}