diff options
author | Norbert Preining <norbert@preining.info> | 2021-10-01 03:01:47 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2021-10-01 03:01:47 +0000 |
commit | 569e4d488d3398f8ed12807dd67e2b301b7447d5 (patch) | |
tree | b0649aad82d5811ce9251e770edd9a1c94b71f0f /support/tex4ebook/tex4ebook-exec_mobi.lua | |
parent | c0e66330261a0098e8041d4cc1428666ef598c30 (diff) |
CTAN sync 202110010301
Diffstat (limited to 'support/tex4ebook/tex4ebook-exec_mobi.lua')
-rw-r--r-- | support/tex4ebook/tex4ebook-exec_mobi.lua | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/support/tex4ebook/tex4ebook-exec_mobi.lua b/support/tex4ebook/tex4ebook-exec_mobi.lua index 92b70af71c..828baeba4a 100644 --- a/support/tex4ebook/tex4ebook-exec_mobi.lua +++ b/support/tex4ebook/tex4ebook-exec_mobi.lua @@ -11,22 +11,46 @@ function run(out,params) return eb.run(out, params) end +function kindlegen(source, outputfile) + -- try to run kindlegen first + local command = "kindlegen " .. source .. " -o " .. outputfile + local status, output = ebookutils.execute(command) + log:debug("running kindlegen: " .. command, status) + -- if we cannot find kindlegen, try ebook-convert + if not output:match("Amazon") then + log:debug("kindlegen failed, trying epub-convert") + local ebookcmd = "ebook-convert " .. source .. " " .. outputfile + status, output = ebookutils.execute(ebookcmd) + if status > 0 then + log:error("Conversion to the output format failed") + log:error("Do you have either kindlegen or ebook-convert installed?") + return false + end + end + return true +end + function writeContainer() local ret = eb.writeContainer() -- convert the epub file to mobi local epubpath = eb.basedir .. "/" .. eb.outputfile - log:info("Pack mobi "..os.execute("kindlegen " .. epubpath)) -- find the mobi filename - local mobifile = epubpath:gsub("epub$", "mobi") + local mobifile = eb.outputfile:gsub("epub$", "mobi") local mobidist = eb.destdir .. eb.outputfile:gsub("epub$", "mobi") - -- copy the mobi file to the destination directory - -- the destination directory will be created by the epub writer, so it is possible to use - -- the cp function which doesn't try to create directory - ebookutils.cp(mobifile, mobidist) - + log:info("Convert Epub to mobi") + local status = kindlegen(epubpath, mobifile) + if status then + -- copy the mobi file to the destination directory + -- the destination directory will be created by the epub writer, so it is possible to use + -- the cp function which doesn't try to create directory + if mobifile ~= mobidist then + ebookutils.cp(mobifile, mobidist) + end + end return ret end function clean() return eb.clean() end + |