Skip to content

Instantly share code, notes, and snippets.

@venj
Created October 19, 2011 09:55
Show Gist options
  • Save venj/1297871 to your computer and use it in GitHub Desktop.
Save venj/1297871 to your computer and use it in GitHub Desktop.
This is a simple script to batch unpack and rename books downloaded from "that" ebook site. If you are want to know about "my rename ..." command, pay a visit to https://gist.github.com/1149120
#!/usr/bin/env ruby
require "fileutils"
PUBS = ["Oreilly", "Microsoft Publication",
"Sitepoint", "Apress"]
def normalize(name)
n = name.gsub(/\w{3,4}\.[0-9]{4}$/, "").gsub(/\.\w+\.Edition/i, "").gsub(/[^[:alnum:]]/, " ")
PUBS.each do |p|
r = Regexp.new(p, true)
next unless r.match(n)
return n.gsub(r, "").strip
end
end
ARGV.size > 0 ? folder = ARGV[0] : folder = FileUtils.pwd
FileUtils.cd folder do
Dir["*.rar"].each do |f|
name = normalize(File.basename(f, ".rar"))
system %[my rename #{f} "#{name}"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment