Created
October 19, 2011 09:55
-
-
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
This file contains 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
#!/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