forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osdb.explain.groovy
51 lines (39 loc) · 1.37 KB
/
osdb.explain.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
#!/usr/bin/env filebot -script
import static net.filebot.subtitle.SubtitleUtilities.*
import static net.filebot.web.OpenSubtitlesHasher.*
def lang = _args.language.locale
def strict = !_args.nonStrict
def fetch = any{ fetch as boolean }{ false }
args.getFiles{ it.isVideo() }.each{ f ->
println "File: $f"
// hash search
def hash = computeHash(f)
def size = f.length()
println "Hash/Tag Lookup (hash: $hash, size: $size, lang: $lang, tag: $f.nameWithoutExtension)"
def hashMatches = lookupSubtitlesByHash(WebServices.OpenSubtitles, [f], lang, true, strict).get(f)
hashMatches.eachWithIndex{ d, i ->
println "Result ${i+1}: ${d.properties}"
}
def bestHashMatch = getBestMatch(f, hashMatches, strict)
println "Best Hash Match: ${bestHashMatch?.properties}"
// name search
def nameMatches = []
if (!strict) {
println "Name Lookup (file: $f.nameWithoutExtension, strict: $strict, lang: $lang)"
nameMatches = findSubtitlesByName(WebServices.OpenSubtitles, [f], lang, null, true, strict).get(f)
nameMatches.eachWithIndex{ d, i ->
println "Result ${i+1}: ${d.properties}"
}
println "Best Name Match: ${nameMatches[0]?.properties}"
}
// fetch subtitles
if (fetch) {
[hashMatches, nameMatches].collectMany{ it ?: [] }.unique{ d -> d.path }.each{ d ->
def s = f.resolveSibling(d.path)
if (!s.exists()) {
println "Fetch $s"
d.fetch().saveAs(s)
}
}
}
}