forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suball.groovy
77 lines (58 loc) · 2.15 KB
/
suball.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
#!/usr/bin/env filebot -script
def languages = any{ _args.lang.split(/\W+/) }{ ['en'] } as List
def minAgeDays = any{ minAgeDays.toDouble() }{ 0d }
def maxAgeDays = any{ maxAgeDays.toDouble() }{ 30d }
def maxAgeDaysLimit = any{ maxAgeDaysLimit.toBoolean() }{ true }
def minFileSize = any{ minFileSize.toLong() }{ 50 * 1000 * 1000L }
def minLengthMS = any{ minLengthMS.toLong() }{ 10 * 60 * 1000L }
def ignore = any{ ignore }{ null }
def ignoreTextLanguage = any{ ignoreTextLanguage }{ languages.join('|') }
def minAgeTimeStamp = now.time - (minAgeDays.toDouble() * 24 * 60 * 60 * 1000L) as long
def maxAgeTimeStamp = now.time - (maxAgeDays.toDouble() * 24 * 60 * 60 * 1000L) as long
// sanity check
if (maxAgeDaysLimit && (maxAgeDays == null || maxAgeDays.toDouble() > 30)) {
die "maxAgeDays must be between 0 and 30. $maxAgeDays not reasonable."
}
def accept = { f ->
def creationDate = f.creationDate
// ignore files that are too old
if (maxAgeTimeStamp != null && creationDate < maxAgeTimeStamp) {
log.finest "Ignore old: $f"
return false
}
// ignore files that are too young
if (minAgeTimeStamp != null && creationDate > minAgeTimeStamp) {
log.finest "Ignore young: $f"
return false
}
// ignore files that match the give ignore pattern
if (f.path.findMatch(ignore)) {
log.finest "Ignore pattern: $f"
return false
}
// ignore files that are too small
if (minFileSize > 0 && f.length() < minFileSize) {
log.fine "Ignore small: $f"
return false
}
// ignore files that are too short
if (minLengthMS > 0 && any{ f.mediaCharacteristics.duration.toMillis() < minLengthMS }{ false }) {
log.fine "Ignore short: $f"
return false
}
// ignore files that already have subtitles
if (ignoreTextLanguage != null && any{ f.mediaCharacteristics.subtitleLanguage.findMatch(ignoreTextLanguage) }{ false }) {
log.fine "Ignore text language: $f"
return false
}
return true
}
/*
* Get subtitles for all your media files
*/
args.getFiles{ it.isVideo() && accept(it) }.groupBy{ it.dir }.each{ dir, files ->
log.fine "Fetch subtitles for [$dir]"
languages.each{
getMissingSubtitles(lang: it, file: files, output: 'srt', encoding: 'UTF-8')
}
}