-
Notifications
You must be signed in to change notification settings - Fork 140
/
mediainfo.groovy
executable file
·45 lines (37 loc) · 1.11 KB
/
mediainfo.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
#!/usr/bin/env -S filebot -script
// raw / slow mode (i.e. use libmediainfo and write xattr)
if (_args.mode == /raw/) {
log.finest "# ${MediaInfo.version()}"
return args.files.findAll{ f -> f.video || f.audio }.each{ f ->
try(def mi = new MediaInfo()) {
def read = mi.read(f, 8192)
def raw = mi.raw()
// print stats
log.fine "\n# $f (${read.displaySize} of ${f.displaySize})"
log.info "\n$raw"
// minify and write to xattr
if (raw) {
f.xattr['net.filebot.mediainfo'] = raw.split(/\R+/).findResults{ it.replaceFirst(/[ ]+[:][ ]+/, '\t') }.join('\n')
f.xattr['net.filebot.mediainfo.mtime'] = f.lastModified() as String
}
}
}
}
// default / fast mode (i.e. use local cache or xattr or libmediainfo)
args.files.each{ f ->
log.fine "\n# $f"
try {
f.mediaInfo.each{ kind ->
kind.each{ stream ->
log.finest "\n${stream.StreamKind} #${stream.StreamKindID}"
// find optimal padding
def pad = stream.keySet().flatten().collect{ it.length() }.max()
stream.each{ k,v ->
log.info "${k.padRight(pad)} : $v"
}
}
}
} catch (error) {
log.severe "$error.message"
}
}