-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanami.groovy
230 lines (221 loc) · 9.8 KB
/
manami.groovy
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//file:noinspection unused
//file:noinspection GrMethodMayBeStatic
package lib
import net.filebot.Logging
//--- VERSION 1.2.2
// http://docs.groovy-lang.org/latest/html/documentation/grape.html
// https://mvnrepository.com/artifact/org.apache.commons/commons-text
@Grapes(
@Grab(group='org.apache.commons', module='commons-text', version='1.9')
)
import org.apache.commons.text.similarity.JaroWinklerDistance
import com.cedarsoftware.util.io.JsonObject
import java.util.regex.Matcher
// ---------- Search Anime Offline Database for an AniDB title match using JWD ---------- //
// --- This *should* as such only return unique results
// --- Synonyms in Anime Offline Database are NOT to be trusted to be accurate for the Title Entry
// --- Even for AniDB entries. It is useful to get some possible variations on the Title Name, but
// --- Not for an authoritive match to AID.
Set aodJWDSearchOnlyAniDB(JsonObject fileBotJsonCacheObject, Set searchList, locale, Boolean includeSynonyms = false, Boolean returnAID = false, Boolean strictJWDMatch = false) {
JaroWinklerDistance jaroWinklerDistance = new JaroWinklerDistance()
resultsAsSet = [] as HashSet
fileBotJsonCacheObject.data.each { aodentry ->
if (aodentry.sources =~ /anidb/) {
Matcher matcher = aodentry.sources =~ /https:\/\/anidb\.net\/anime\/(\d+)/
//noinspection GroovyAssignabilityCheck
anidbID = matcher[0][1].toInteger()
if ( includeSynonyms ) {
aodtitles = []
aodtitles += aodentry.title
aodtitles += aodentry.synonyms.flatten()
}
searchList.each { searchItem ->
if ( includeSynonyms ) {
aodtitles.each { title ->
jwdcompare = jaroWinklerDistance.apply(altjwdStringBlender(searchItem), altjwdStringBlender(title))
// At some point I may add a "fuzzy" vs "strict" matcher, aka 1 vs > .98
if ( jwdcompare == 1 ) {
Logging.log.finest "Found this exact Match (1.0) in title entry? ${aodentry.title}"
returnAID == true ? (resultsAsSet += anidbID) : (resultsAsSet += aodentry.title)
// resultsAsSet += aodentry.title
} else if ( strictJWDMatch == false ) {
if ( jwdcompare > 0.990000000 ) {
Logging.log.finest "Found this Likely Match (0.99+)? ${aodentry.title}"
returnAID == true ? (resultsAsSet += anidbID) : (resultsAsSet += aodentry.title)
// resultsAsSet += aodentry.title
} else if ( jwdcompare > 0.980000000 ) {
Logging.log.finest"Found this Possible Match (0.98+)? ${aodentry.title} "
returnAID == true ? (resultsAsSet += anidbID) : (resultsAsSet += aodentry.title)
// resultsAsSet += aodentry.title
}
}
}
} else {
jwdcompare = jaroWinklerDistance.apply(altjwdStringBlender(searchItem), altjwdStringBlender(aodentry.title))
// At some point I may add a "fuzzy" vs "strict" matcher, aka 1 vs > .98
if ( jwdcompare == 1 ) {
Logging.log.finest"Found this exact Match (1.0) in title entry? ${aodentry.title}"
returnAID == true ? (resultsAsSet += anidbID) : (resultsAsSet += aodentry.title)
// resultsAsSet += aodentry.title
} else if ( strictJWDMatch == false ) {
if ( jwdcompare > 0.990000000 ) {
Logging.log.finest "Found this Likely Match (0.99+)? ${aodentry.title}"
returnAID == true ? (resultsAsSet += anidbID) : (resultsAsSet += aodentry.title)
// resultsAsSet += aodentry.title
} else if ( jwdcompare > 0.980000000 ) {
Logging.log.finest "Found this Possible Match (0.98+)? ${aodentry.title} "
returnAID == true ? (resultsAsSet += anidbID) : (resultsAsSet += aodentry.title)
// resultsAsSet += aodentry.title
}
}
}
}
} else {
return
}
}
return resultsAsSet
}
// ---------- Search Anime Offline Database for a NON-AniDB title match using JWD ---------- //
// --- This *should* as such only return unique results
// --- Synonyms in Anime Offline Database are NOT to be trusted to be accurate for the Title Entry
// --- Even for AniDB entries. It is useful to get some possible variations on the Title Name, but
// --- Not for an authoritive match to AID.
Set aodJWDSearchExcludeAniDB(JsonObject fileBotJsonCacheObject, Set searchList, locale, Boolean searchSynonyms = false, Boolean strictJWDMatch = false) {
JaroWinklerDistance jaroWinklerDistance = new JaroWinklerDistance()
resultsAsSet = [] as HashSet
fileBotJsonCacheObject.data.each { aodentry ->
if (aodentry.sources =~ /anidb/) {
return
}
if ( searchSynonyms ) {
aodtitles = []
aodtitles += aodentry.title
aodtitles += aodentry.synonyms.flatten()
}
searchList.each { searchItem ->
if ( searchSynonyms ) {
aodtitles.each { title ->
jwdcompare = jaroWinklerDistance.apply(altjwdStringBlender(searchItem), altjwdStringBlender(title))
// At some point I may add a "fuzzy" vs "strict" matcher, aka 1 vs > .98
if ( jwdcompare == 1 ) {
Logging.log.finest "Found this exact Match (1.0) in title entry? ${aodentry.title}"
resultsAsSet += aodentry.title
} else if ( strictJWDMatch == false ) {
if ( jwdcompare > 0.990000000 ) {
Logging.log.finest "Found this Likely Match (0.99+)? ${aodentry.title}"
resultsAsSet += aodentry.title
} else if ( jwdcompare > 0.980000000 ) {
Logging.log.finest "Found this Possible Match (0.98+)? ${aodentry.title} "
resultsAsSet += aodentry.title
}
}
}
} else {
jwdcompare = jaroWinklerDistance.apply(altjwdStringBlender(searchItem), altjwdStringBlender(aodentry.title))
// At some point I may add a "fuzzy" vs "strict" matcher, aka 1 vs > .98
if ( jwdcompare == 1 ) {
Logging.log.finest "Found this exact Match (1.0) in title entry? ${aodentry.title}"
resultsAsSet += aodentry.title
} else if ( strictJWDMatch == false ) {
if ( jwdcompare > 0.990000000 ) {
Logging.log.finest "Found this Likely Match (0.99+)? ${aodentry.title}"
resultsAsSet += aodentry.title
} else if ( jwdcompare > 0.980000000 ) {
Logging.log.finest "Found this Possible Match (0.98+)? ${aodentry.title} "
resultsAsSet += aodentry.title
}
}
}
}
}
return resultsAsSet
}
// ---------- Search Anime Offline Database for an AID ---------- //
// --- Return true if it's type is Not "TV"
// --- Return false if the type is "TV"
Boolean aodIsAIDTypeNotTV(JsonObject fileBotJsonCacheObject, Integer AID) {
Logging.log.finest "The AID I'm Searching for is:[${AID}]"
JsonObject myAniDBEntry = fileBotJsonCacheObject.data.find { aodentry ->
// https://anidb.net/anime/1
aodentry.sources.find { it ==~ /https:\/\/anidb\.net\/anime\/${AID}$/ }
} as JsonObject
Logging.log.finest "myAniDBEntry.getclass:[${myAniDBEntry.getClass()}]"
Logging.log.finest "myAniDBEntry:${myAniDBEntry}"
// --- It will be null if an AID is not in the AOD List --- //
if ( myAniDBEntry == null ) {
return true
} else {
return myAniDBEntry.type != 'TV'
}
}
String aodGetTypeForAID(JsonObject fileBotJsonCacheObject, Integer AnimeID) {
JsonObject myAniDBEntry = fileBotJsonCacheObject.data.find { aodentry ->
aodentry.sources.find { it ==~ /https:\/\/anidb\.net\/anime\/${AnimeID}$/ }
} as JsonObject
// --- It will be null if an AID is not in the AOD List --- //
if ( myAniDBEntry == null ) {
return true
} else {
// Types are "Special", "Movie", "OVA", "ONA", "TV" - It is unknown if it matches AniDB 100% however.
return myAniDBEntry.type
}
}
Integer aodGetEpisodeNumberForAID(JsonObject fileBotJsonCacheObject, Integer AnimeID) {
JsonObject myAniDBEntry = fileBotJsonCacheObject.data.find { aodentry ->
aodentry.sources.find { it ==~ /https:\/\/anidb\.net\/anime\/${AnimeID}$/ }
} as JsonObject
// --- It will be null if an AID is not in the AOD List --- //
if ( myAniDBEntry == null ) {
return 0
} else {
return myAniDBEntry.episodes as Integer
}
}
LinkedHashMap setAnimeTypeFromAID(JsonObject animeOfflineDatabase, Integer animeID, def specialType, Boolean isSpecialType, Boolean isMovieType) {
//--- Set options on if this is a Movie/ONA/OVA or Special/TV
def getAnimeType = aodGetTypeForAID(animeOfflineDatabase, animeID)
switch (getAnimeType.toUpperCase()) {
case ["MOVIE"]:
isMovieType = true
isSpecialType = false
break
case ["TV"]:
isMovieType = false
isSpecialType = false
specialType = null
break
case ["UNKNOWN"]:
isMovieType = false
isSpecialType = false
specialType = null
break
case ["SPECIAL","OVA","ONA"]:
isMovieType = false
isSpecialType = true
specialType = getAnimeType
break
default:
break
}
return [ isSpecialType: isSpecialType, isMovieType: isMovieType, specialType: specialType]
}
/**
* Search Anime Offline Database using a set of search terms and return all the title and all synonyms for that entry.
* A literal match is used.
*
* @param animeOfflinejsonObject Json Object of the Anime Offline Database
* @param searchList A Set of names we will be searching for
* @return the search results as a set for all the search terms
*/
Set aodReturnAllTitlesAndSynonyms(animeOfflinejsonObject, Set searchList) {
HashSet returnAsSet = []
searchList.each { lead ->
Logging.log.finest "lead:${lead}"
returnAsSet << lead
animeOfflinejsonObject.data.find { it.title == lead }.synonyms.collect { it }.each {
returnAsSet << it.toLowerCase()
}
}
return returnAsSet
}