Created
May 22, 2016 17:34
-
-
Save rb2k/f8e7512a8c3e37ccc8d7fe90ee9ea706 to your computer and use it in GitHub Desktop.
Quick hack to recompress epub files
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
def compress(file) | |
raise unless system("rm -rf tmp/") | |
raise unless system("unzip -q -o -d tmp/ '#{file}'") | |
raise unless system("imageOptim --directory tmp/ ") | |
raise unless system("pushd tmp/ && zip -q -9 -rX '#{file}' 'mimetype' '*' && popd") | |
end | |
def filesize(file) | |
'%.2f' % (File.size(file).to_f / 2**20) | |
end | |
if File.directory?(ARGV[0]) | |
inputs = Dir[File.join(ARGV[0], '/**/*.epub')] | |
inputs.each do |file| | |
puts "Working on #{file}: #{filesize(file)} MB" | |
compress(file) | |
puts "Done with #{file}: #{filesize(file)} MB" | |
end | |
else | |
compress(ARGV[0]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment