-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeywords.go
123 lines (101 loc) · 1.87 KB
/
keywords.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package animenames
import (
"strings"
)
var aliases = map[string]string{
"blu-ray": "bd",
"bluray": "bd",
"h.264": "h264",
"x264": "h264",
"sps": "specials",
"special": "specials",
}
var resolutions = []string{
"1080p",
"360p",
"480p",
"720p",
}
var quality = []string{
"10bit",
"8bit",
"bd",
"dvd",
"tv",
}
var videoCodecs = []string{
"h264",
"hevc",
}
var audioCodecs = []string{
"aac",
"ac3",
"flac",
"opus",
}
var extensions = []string{
"ass",
"mkv",
"mp4",
}
var otherProperties = []string{
"censored",
"complete",
"dual",
"dub",
"english",
"simuldub",
"uncensored",
"specials",
}
var keywordsMap = map[string]bool{}
func init() {
lists := [][]string{
resolutions,
quality,
videoCodecs,
audioCodecs,
extensions,
otherProperties,
}
for _, list := range lists {
for _, keyword := range list {
keywordsMap[keyword] = true
}
}
}
// isKeyword returns true when word is a known keyword and false otherwise.
func isKeyword(word string) bool {
if _, ok := aliases[word]; ok {
return true
}
return keywordsMap[word]
}
// removeKeywords returns a slice with words from text, without any keywords.
func removeKeywords(text string) []string {
words := make([]string, 0)
allWords := splitByWords(text)
for _, word := range allWords {
if isKeyword(strings.ToLower(word)) {
continue
}
words = append(words, word)
}
return words
}
// parseKeywords tries to extract information from the keywords present in the
// chunk, and updates `*anime`.
func parseKeywords(chunk string, anime *Anime) {
words := splitByWords(chunk)
for _, word := range words {
lword := strings.ToLower(word)
if lword == "bd" || lword == "bdrip" || lword == "blu-ray" || lword == "bluray" {
anime.IsBD = true
continue
}
if lword == "special" || lword == "specials" || lword == "sps" {
anime.HasSpecials = true
continue
}
}
}