forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmi.groovy
40 lines (32 loc) · 1.25 KB
/
mi.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
#!/usr/bin/env filebot -script
/*
* Print media info of all video files to CSV file
*/
def model = '''Name;Container;Resolution;Video Codec;Video Format;Audio Codec;Audio Format;Audio Language(s);Subtitle Language(s);Duration;File Size;Folder Size;Folder Count;Path'''
def template = '''{fn};{cf};{resolution};{vc};{vf};{ac};{af};{media.AudioLanguageList};{media.TextLanguageList};{media.DurationString3};{file.length()};{folder.listFiles().sum{ it.length() }};{folder.listFiles().sum{ it.isFile() ? 1 : 0 }};{file.getCanonicalPath()}'''
def csvFile = args[-1] as File
if (csvFile.name.endsWith('.csv')) {
// open destination file (writing files requires -trust-script)
csvFile.withWriter('UTF-8'){ output ->
// print to console
println "Writing CSV file [$csvFile]"
println model
// print header
output.write(model)
output.write('\n')
// print info for each video file (sorted by filename)
args.getFiles{ it.isVideo() }.sort{ a, b -> a.name.compareToIgnoreCase(b.name) }.each{
def mi = getMediaInfo(it, template)
// print to console
println mi
// append to file
output.write(mi)
output.write('\n')
}
}
} else {
// pipe usage
getMediaInfo(file: args.getFiles{ it.isVideo() }, format: template).each{
println it
}
}