2012-07-28 17:17:29 -04:00
|
|
|
// filebot -script fn:cleaner [--action test] /path/to/media/
|
2013-05-07 11:01:50 -04:00
|
|
|
def deleteRootFolder = tryQuietly{ root.toBoolean() }
|
2011-12-20 08:00:38 -05:00
|
|
|
|
|
|
|
/*
|
2012-07-13 07:41:50 -04:00
|
|
|
* Delete orphaned "clutter" files like nfo, jpg, etc and sample files
|
2011-12-20 08:00:38 -05:00
|
|
|
*/
|
2012-07-13 07:41:50 -04:00
|
|
|
def isClutter(f) {
|
2012-10-27 08:39:52 -04:00
|
|
|
def exts = tryQuietly{ exts } ?: /jpg|jpeg|png|gif|nfo|xml|htm|html|log|srt|sub|idx|md5|sfv|txt|rtf|url|db|dna|log/
|
|
|
|
def terms = tryQuietly{ terms } ?: /sample|trailer|extras|deleted.scenes|music.video|scrapbook/
|
|
|
|
def maxsize = tryQuietly{ maxsize as Long } ?: 100 * 1024 * 1024
|
|
|
|
|
|
|
|
// path contains blacklisted terms or extension is blacklisted
|
2012-12-12 04:32:22 -05:00
|
|
|
return (f.extension ==~ "(?i)($exts)" || f.path =~ "(?i)\\b($terms)\\b") && f.length() < maxsize
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-13 07:41:50 -04:00
|
|
|
def clean(f) {
|
|
|
|
println "Delete $f"
|
|
|
|
|
|
|
|
// do a dry run via --action test
|
2012-10-27 08:39:52 -04:00
|
|
|
if (_args.action == 'test') {
|
2012-07-13 07:41:50 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return f.isDirectory() ? f.deleteDir() : f.delete()
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2012-07-13 07:41:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
// delete clutter files in orphaned media folders
|
|
|
|
args.getFiles{ isClutter(it) && !it.dir.hasFile{ (it.isVideo() || it.isAudio()) && !isClutter(it) }}.each { clean(it) }
|
|
|
|
|
|
|
|
// delete empty folders but exclude given args
|
2013-05-07 11:01:50 -04:00
|
|
|
args.getFolders().sort().reverse().each { if (it.listFiles().length == 0) { if (deleteRootFolder || !args.contains(it)) clean(it) } }
|