-
Notifications
You must be signed in to change notification settings - Fork 140
/
miss.groovy
executable file
·86 lines (66 loc) · 1.96 KB
/
miss.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
#!/usr/bin/env -S filebot -script
// sanity checks
if (args.size() == 0) {
die "Illegal usage: no input"
}
def episodes = []
def shows = [] as LinkedHashSet
args.getFiles{ f -> f.video }.each{ f ->
def episode = f.metadata
def seriesInfo = any{ episode.seriesInfo }{ null }
if (episode instanceof Episode && seriesInfo instanceof SeriesInfo) {
log.finest "$seriesInfo | $episode | $f"
shows += seriesInfo
if (episode instanceof MultiEpisode) {
episodes += episode.episodes as List
} else {
episodes += episode
}
}
}
if (episodes.size() == 0) {
die "No xattr tagged files", ExitCode.FAILURE
}
def episodeList = shows.collectMany{ s ->
def episodeList = tryLogCatch{
return getService(s.database).getEpisodeList(s.id, s.order as SortOrder, s.language as Locale)
}
if (episodeList) {
return episodeList
}
// abort if we cannot receive the current episode list information
die "Failed to fetch episode list for $s.name [$s]"
}
// check for episode information changes
if (_args.strict) {
def actual = episodeList.collectEntries{ e -> [e.id, e as String] }
def expected = episodes.collectEntries{ e -> [e.id, e as String] }
expected.each{ k, v ->
if (v != actual[k]) {
help "* Episode #$k has changed: $v -> ${actual[k]}"
}
}
}
// print missing episodes (ignore special episodes)
def regularEpisodes = episodeList.findAll{ e -> e.episode } as LinkedHashSet
def missingEpisodes = regularEpisodes - episodes
// support custom output formatting
def format = _args.expressionFormat
// print missing episodes directly to standard console output (and not to the --log-file)
missingEpisodes.each{ e ->
if (format) {
try {
println format.apply(e)
} catch(error) {
log.warning "$error.message [$e]"
}
} else {
println e
}
}
// return Exit Code 0 (no missing episodes) or Exit Code 100 (some missing episodes)
if (missingEpisodes) {
die "[${missingEpisodes.size()}] missing episodes", ExitCode.NOOP
} else {
log.finest "No missing episodes"
}