forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.groovy
34 lines (25 loc) · 915 Bytes
/
verify.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
// filebot -script fn:verify /path/to/files
import java.util.concurrent.*
import net.filebot.hash.*
def hashType = HashType.SFV
def xattrkey = 'CRC32'
def files = args.getFiles{ it.isVideo() || it.isAudio() }
def threadPoolSize = Runtime.getRuntime().availableProcessors()
def executor = Executors.newFixedThreadPool(threadPoolSize)
executor.invokeAll(files.collect{ f ->
return {
def attr_hash = f.xattr[xattrkey]
def calc_hash = VerificationUtilities.computeHash(f, hashType)
log.info "$attr_hash $calc_hash $f"
if (attr_hash == null) {
log.warning "Set xattr $xattrkey for [$f]"
f.xattr[xattrkey] = calc_hash
// verify that xattr has been set correctly
if (f.xattr[xattrkey] != calc_hash) {
die "Failed to set xattr $xattrkey for [$f]"
}
} else if (attr_hash != calc_hash) {
die "$xattrkey mismatch (expected $attr_hash, actual: $calc_hash) for [$f]"
}
}
})*.get()