-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtvdb.groovy
189 lines (180 loc) · 8.25 KB
/
tvdb.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
//file:noinspection unused
//file:noinspection GrMethodMayBeStatic
package lib
import net.filebot.Logging
import net.filebot.WebServices
import net.filebot.web.Episode
import net.filebot.web.SortOrder
import net.filebot.web.SeriesInfo
//--- VERSION 1.2.3
/**
* Have filebot Search TVDB using a list, and return the results as a Set
* This *should* as such only return unique results in the Set<TheTVDBSeriesInfo>
*
* @param searchList Set of Shows to search for. A Show can be the TVDBID # or a Show name.
* @param locale The Locale
* @return Set of shows from the filebot search.
*/
Set filebotTVDBSearch(Set searchList, locale) {
resultsAsSet = [] as HashSet
searchList.each { item ->
myTVDBSearch = WebServices.TheTVDB.search(item, locale)
if (myTVDBSearch.isEmpty()) {
} else {
resultsAsSet += myTVDBSearch
}
}
return resultsAsSet
}
/**
* Have filebot get the Episode List for a TVDB Series and return it using the default series order (usually airdate)
* and locale.ENGLISH
*
* @param tvdbSeriesID The TVDB ID we want to get the Episode List for.
* @return Collection<Episode> of Episodes from TVDB
*/
Collection<Episode> filebotTVDBgetEpisodeList(Integer tvdbSeriesID) {
SeriesInfo myTVDBseriesInfo
try {
myTVDBseriesInfo = WebServices.TheTVDB.getSeriesInfo(tvdbSeriesID, Locale.ENGLISH)
} catch (e) {
Logging.log.severe "WebServices.TheTVDB.getSeriesInfo Caught error: ${e}"
Episode myEpisode = new Episode()
return [myEpisode]
}
return WebServices.TheTVDB.getEpisodeList(myTVDBseriesInfo.id, myTVDBseriesInfo.order as SortOrder, Locale.ENGLISH)
}
/**
* Return all TVDB Episodes in a specific Season of a TVDB Series by Series order (absolute or airdate)
*
* @param myTVDBEpisodes Collection<Episode> of TVDB Episodes (See filebotTVDBgetEpisodeList)
* @param season The Season we want to return all episodes of
* @param order The order type we want to use, defaults to absolute. The other option is airdate.
* @return Collection<Episode> of Episodes from TVDB
*/
ArrayList filebotTVDBSeasonEpisodeRange(Collection<Episode> myTVDBEpisodes, Integer season, String order = 'absolute') {
return net.filebot.web.EpisodeUtilities.filterBySeason(myTVDBEpisodes, season).findAll { it."${order}" }
}
/**
* Return all TVDB Episodes in a specific Season of a TVDB Series (ignoring series order)
*
* @param myTVDBEpisodes Collection<Episode> of TVDB Episodes (See filebotTVDBgetEpisodeList)
* @param season The Season we want to return all episodes of
* @return Collection<Episode> of Episodes from TVDB
*/
ArrayList filebotTVDBSeasonEpisodes(Collection<Episode> myTVDBEpisodes, Integer season) {
return net.filebot.web.EpisodeUtilities.filterBySeason(myTVDBEpisodes, season)
}
/**
* Determine if an episode is contained in a collection of Episodes. With filebotTVDBSeasonEpisodes() or
* filebotTVDBgetEpisodeList() usually being used to create a Collection<Episode> of episodes in which we will search
*
* @param myTVDBEpisodes Collection<Episode> of TVDB Episodes (See filebotTVDBSeasonEpisodes() or filebotTVDBgetEpisodeList() )
* @param episodeNumber The Episode Number we are looking for
* @param order The Episode Order we will use when searching, defaults to absolute, can also be set to airdate
* @param returnEpisode Return the full Episode entry instead of a true/false Boolean
* @param seasonNumber The Season number we will use when searching if order is airdate
* @param whatAboutSpecials What do we do about specials in our search? Defaults to exclude, can also be include or only. When set to only, then ONLY specials will be searched.
* @return with returnEpisode = false (the default) returns Boolean, with returnEpisode = true returns net.filebot.web.Episode
*/
def filebotTVDBSeasonContainsEpisodeNumber(Collection<Episode> myTVDBEpisodes, Integer episodeNumber, String order = 'absolute', Boolean returnEpisode = false, Integer seasonNumber = 0, String whatAboutSpecials = 'exclude') {
switch(order) {
case 'absolute':
switch (whatAboutSpecials) {
case 'exclude':
if ( returnEpisode ) {
return myTVDBEpisodes.find { it.regular && (it.absolute == episodeNumber || ( it.absolute == null && it.episode == episodeNumber ) ) }
} else {
return myTVDBEpisodes.find { it.regular && (it.absolute == episodeNumber || ( it.absolute == null && it.episode == episodeNumber ) ) } != null
}
break
case 'include':
if ( returnEpisode ) {
return myTVDBEpisodes.find { (it.absolute == episodeNumber || ( it.absolute == null && it.episode == episodeNumber ) ) }
} else {
return myTVDBEpisodes.find { (it.absolute == episodeNumber || ( it.absolute == null && it.episode == episodeNumber ) ) } != null
}
break
case 'only':
if ( returnEpisode ) {
return myTVDBEpisodes.find { it.special && (it.absolute == episodeNumber || ( it.absolute == null && it.episode == episodeNumber ) ) }
} else {
return myTVDBEpisodes.find { it.special && (it.absolute == episodeNumber || ( it.absolute == null && it.episode == episodeNumber ) ) } != null
}
break
default:
Logging.log.warning '1:ERROR in filebotTVDBSeasonContainsEpisodeNumber'
return []
break
}
break
case 'airdate':
switch (whatAboutSpecials) {
case 'exclude':
if ( returnEpisode ) {
return myTVDBEpisodes.find { it.regular && (it.episode == episodeNumber && it.season == seasonNumber) }
} else {
return myTVDBEpisodes.find { it.regular && (it.episode == episodeNumber && it.season == seasonNumber) } != null
}
break
case 'include':
if ( returnEpisode ) {
return myTVDBEpisodes.find { (it.episode == episodeNumber && it.season == seasonNumber) }
} else {
return myTVDBEpisodes.find { (it.episode == episodeNumber && it.season == seasonNumber) } != null
}
break
case 'only':
if ( returnEpisode ) {
return myTVDBEpisodes.find { it.special && (it.episode == episodeNumber && it.season == seasonNumber) }
} else {
return myTVDBEpisodes.find { it.special && (it.episode == episodeNumber && it.season == seasonNumber) } != null
}
break
default:
Logging.log.warning '2:ERROR in filebotTVDBSeasonContainsEpisodeNumber'
return []
break
}
break
default:
Logging.log.warning '3:ERROR in filebotTVDBSeasonContainsEpisodeNumber'
return []
break
}
}
/**
* Search Filebot's cache of AnimeLists for the specific TVDB ID.
*
* @param tvDBID The TVDB ID we are searching for in Filebot's AnimeLists cache
* @return Will return an ArrayList<net.filebot.web.AnimeLists$Entry> of all maps if the search succeeds, else it will return null
*/
def filebotAnimeListReturnFromTVDBID(Integer tvDBID) {
def mySearchResult = tryQuietly {
WebServices.AnimeList.model.anime.findAll {
it.tvdbid == tvDBID
}
}
if (mySearchResult == null || mySearchResult.isEmpty() ) {
return null
}
return mySearchResult
}
/**
* Try to determine the AniDB AID for a specific episode using TVDB ID # and Filebot's AnimeLists cache
* This method is NOT meant to be used unless you already know there is an AnimeList entry in which to try to match.
*
* @param tvDBID The TVDB ID we are searching for in Filebot's AnimeLists cache
* @param seasonNumber The TVDB Season we will use
* @param episodeNumber The Episode # we will use
* @return Will return a single AnimeList Entry (net.filebot.web.AnimeLists$Entry)
*/
def filebotAnimeListReturnAIDEntry(Integer tvDBID, Integer seasonNumber, Integer episodeNumber = 0){
// Will always return the non-offset (1st), AND offset for Episode # as 2nd assuming you give an Episode #
ArrayList returnThing = filebotAnimeListReturnFromTVDBID(tvDBID).findAll { it.defaulttvdbseason == seasonNumber && (it.episodeoffset != null ? it.episodeoffset < episodeNumber : true) }
if ( returnThing.size() > 1 && episodeNumber > 0 ) {
return returnThing[1] // Class is net.filebot.web.AnimeLists$Entry
} else {
return returnThing[0] // Class is net.filebot.web.AnimeLists$Entry
}
}