Method: NovelConverter.epub_to_mobi
- Defined in:
- lib/novelconverter.rb
.epub_to_mobi(epub_path, verbose = false) ⇒ Object
EPUBファイルをkindlegenでMOBIへAozoraEpub3.jar と同じ場所に kindlegen が無ければ何もしない
返り値:正常終了 :success、エラー終了 :error、中断終了 :abort
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/novelconverter.rb', line 232 def self.epub_to_mobi(epub_path, verbose = false) kindlegen_path = Narou.kindlegen_path unless File.exist?(kindlegen_path) error "kindlegenが見つかりませんでした。AozoraEpub3と同じディレクトリにインストールして下さい" return :error end if Helper.os_cygwin? epub_path = Helper.convert_to_windows_path(epub_path) end command = %!"#{kindlegen_path}" -locale ja "#{epub_path}"! if Helper.os_windows? command.encode!(Encoding::Windows_31J) end print "kindlegen実行中" res = Helper::AsyncCommand.exec(command) do print "." end stdout_capture, _, proccess_status = res stdout_capture.force_encoding(Encoding::UTF_8) if verbose puts puts "==== kindlegen stdout capture " + "=" * 49 puts stdout_capture.gsub("\n\n", "\n").strip puts "=" * 79 end if proccess_status.exited? if proccess_status.exitstatus == 2 puts "" error "kindlegen実行中にエラーが発生したため、MOBIが出力出来ませんでした" if stdout_capture.scan(/(エラー\(.+?\):\w+?:.+)$/) error $1 end return :error end else puts "" error "kindlegenが中断させられたぽいのでMOBIは出力出来ませんでした" return :abort end puts "変換しました" :success end |