Skip to content

Instantly share code, notes, and snippets.

@ssig33
Created January 21, 2014 04:55
Show Gist options
  • Select an option

  • Save ssig33/8534671 to your computer and use it in GitHub Desktop.

Select an option

Save ssig33/8534671 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
require 'digest/md5'
require 'tmpdir'
pwd = Dir.pwd
ARGV.dup.select{|x| x =~ /.azw3$/}.each{|book|
puts "Convert #{book}"
temp = Dir.mktmpdir
FileUtils.cp book, temp
FileUtils.cd temp
book = Dir.glob("*.azw3").first
system 'ebook-convert', book, "temp.epub"
FileUtils.rm book
system "unzip", "temp.epub"
FileUtils.rm "temp.epub"
Dir.glob("*.css").each{|css|
content = open(css).read
content.gsub!(/^.*writing-mode.*\n/, "")
content.gsub(/{/, "{\nfont-family: \"MS P明朝\",\"MS PMincho\";")
open(css, "w"){|f| f.puts content}
}
system "zip", 'temp.epub', *Dir.glob("**/*")
system "ebook-convert", 'temp.epub', "#{pwd}/#{book.sub(/\.azw3$/, '.pdf')}"
FileUtils.cd pwd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment