Skip to content

Instantly share code, notes, and snippets.

@evenv
Created July 2, 2012 19:53
Show Gist options
  • Save evenv/3035310 to your computer and use it in GitHub Desktop.
Save evenv/3035310 to your computer and use it in GitHub Desktop.
Automatically Unrar Everything In A Folder
def episode(dir)
dir.match "HDTV"
end
def unrar_delete(thefile,allfiles)
if system "/opt/local/bin/unrar e -y %s > /dev/null" % thefile.gsub(' ',' ')
for file in allfiles
File.delete(file)
end
return true
end
return false
end
rootdir = "/Volumes/Filmer/Incoming";
Dir["%s/*"; % rootdir].each do |dir|
if File.directory? dir and not dir.match "UNPACKED"
ok = false
Dir.chdir(dir)
Dir['%s/*.rar' % dir].each do |rarfile|
puts rarfile
ok = unrar_delete(rarfile, Dir[rarfile.gsub("part01","part??")]) if rarfile.match "part01.rar"
ok = unrar_delete(rarfile, Dir[rarfile.gsub(".rar",".r??")]) if not rarfile.match /part[0-9]{2}/
end
if ok
if episode(dir)
system "mv *.avi %s" % rootdir
system "mv *.mkv %s" % rootdir
Dir.chdir(rootdir)
system "rm -r %s" % dir
else
File.rename(dir,"%s UNPACKED" % dir)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment