Skip to content

Instantly share code, notes, and snippets.

@rb2k
Created May 22, 2016 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rb2k/f8e7512a8c3e37ccc8d7fe90ee9ea706 to your computer and use it in GitHub Desktop.
Save rb2k/f8e7512a8c3e37ccc8d7fe90ee9ea706 to your computer and use it in GitHub Desktop.
Quick hack to recompress epub files
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