Created
May 4, 2013 17:43
-
-
Save peleteiro/5518199 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PERSONALIZED SETTINGS | |
def downloadsDir = "/data/share/download/completed" | |
def quarantineDir = "/data/share/download/quarantine" | |
def episodeFormat = '''/data/share/videos/tv/{n}/Season {s.pad(2)}/{e.pad(2)} - {t}/{n} - {s00e00} - {t}''' | |
def movieFormat = '''/data/share/videos/filmes/{movie}/{movie}''' | |
File.metaClass.isArchive = { _types.getFilter("archive").accept(delegate) || delegate.name =~ /[.]rar$|[.]r[\d]+$/ } | |
File.metaClass.isSample = { delegate.name =~ /(?i).*(sample|trailer|extras|deleted.scenes|music.video|scrapbook).*/ ? true : false } | |
def quarantine = {dir -> | |
dir.moveTo(quarantineDir + '/' + dir.name) | |
} | |
downloadsDir.getFiles().findAll{ it.isVerification() }.each { | |
if (!check(file:it)) { | |
quarantine(it.dir) | |
} | |
} | |
downloadsDir.getFolders{ it.hasFile{ it.isArchive() } }.each{ dir -> | |
// extract all archives found in this folder | |
def paths = extract(folder:dir) | |
// delete original archive volumes after successful extraction | |
if (paths != null && !paths.isEmpty()) { | |
dir.listFiles{ it.isArchive() }*.delete() | |
} | |
} | |
downloadsDir.getFolders{ it.hasFile{ it.isVideo() && !it.isSample() } }.each{ dir -> | |
def files = dir.listFiles{ it.isVideo() && !it.isSample() } | |
if (isEpisode(files[0])) { | |
if (!rename(file:files, db:'TheTVDB', format:episodeFormat, strict: false)) { | |
quarantine(dir) | |
} | |
} else { // Movie | |
if (!rename(file:files, db:'TheMovieDB', format:movieFormat, strict: false)) { | |
quarantine(dir) | |
} | |
} | |
} | |
// delete useless files | |
downloadsDir.getFiles{it.isHidden() || it.isSample() || it.extension =~ /sfv|md5|nfo|txt|sup|idx|srt|sub|png|jpg|jpeg|bmp/}.each{file -> | |
if (file.dir.hasFile{it.isVideo() && !it.isSample()}) return // Preve racecondition com o transmission e o filebot | |
file.delete() | |
} | |
// delete empty folders | |
downloadsDir.getFolders().sort().reverse().each{ | |
if (it.path == downloadsDir) return | |
if (it.listFiles().length == 0) { | |
it.deleteDir() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment