diff options
author | Karl Berry <karl@freefriends.org> | 2021-09-30 20:14:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-09-30 20:14:09 +0000 |
commit | 5e4f6a0bf05cf8bd840661f660ac8ce227f3efe7 (patch) | |
tree | 84dc2ea3ac9e73463848b8f0df0ee3f8e4f4b342 /Master/texmf-dist/scripts | |
parent | e145e1504f6609805f20556912bcbbfab32655f2 (diff) |
tex4ebook (30sep21)
git-svn-id: svn://tug.org/texlive/trunk@60663 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
4 files changed, 55 insertions, 22 deletions
diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook b/Master/texmf-dist/scripts/tex4ebook/tex4ebook index 2b2b38b1133..5c6aca5546e 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook @@ -67,7 +67,7 @@ else end if args.version then - print "tex4ebook v0.3d" + print "tex4ebook v0.3e" return end diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw.lua b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw.lua index 397292b648b..ebf8d341446 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw.lua +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw.lua @@ -1,5 +1,6 @@ module(...,package.seeall) local eb = require("tex4ebook-exec_epub") +local mobi = require("tex4ebook-exec_mobi") local ebookutils = require("mkutils") local log = logging.new "exec_azw" @@ -19,13 +20,15 @@ function writeContainer() -- find the azw filename local azwfile = eb.outputfile:gsub("epub$", "azw") local azwdist = eb.destdir .. azwfile - local command = "kindlegen " .. epubpath .. " -o " .. azwfile - log:info("Pack azw ".. command) - local status, output = ebookutils.execute(command) - -- copy the azw 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(eb.basedir .. "/" .. azwfile, azwdist) + local status = mobi.kindlegen(epubpath, azwfile) + if status then + -- copy the azw 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 azwfile ~= azwdist then + ebookutils.cp(azwfile, azwdist) + end + end return ret end diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw3.lua b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw3.lua index 33e8a1182c5..36c537f7eeb 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw3.lua +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw3.lua @@ -1,5 +1,6 @@ module(...,package.seeall) local eb = require("tex4ebook-exec_epub") +local mobi = require("tex4ebook-exec_mobi") local ebookutils = require("mkutils") local log = logging.new "exec_azw" @@ -19,13 +20,18 @@ function writeContainer() -- find the azw filename local azwfile = eb.outputfile:gsub("epub$", "azw3") local azwdist = eb.destdir .. azwfile - local command = "kindlegen " .. epubpath .. " -o " .. azwfile - log:info("Pack azw ".. command) - local status, output = ebookutils.execute(command) - -- copy the azw 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(eb.basedir .. "/" .. azwfile, azwdist) + -- local command = "kindlegen " .. epubpath .. " -o " .. azwfile + -- log:info("Pack azw ".. command) + -- local status, output = ebookutils.execute(command) + local status = mobi.kindlegen(epubpath, azwfile) + if status then + -- copy the azw 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 azwfile ~= azwdist then + ebookutils.cp(azwfile, azwdist) + end + end return ret end diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_mobi.lua b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_mobi.lua index 92b70af71c3..828baeba4ae 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_mobi.lua +++ b/Master/texmf-dist/scripts/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 + |