summaryrefslogtreecommitdiff
path: root/support/tex4ebook/tex4ebook-exec_azw3.lua
blob: 36c537f7eeb659eca3326cfb78e8db41b3ab801e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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"

function prepare(params)
	return eb.prepare(params)
end

function run(out,params)
	return eb.run(out, params)
end

function writeContainer()
	local ret =  eb.writeContainer()
  -- convert the epub file to azw
  local epubpath = eb.basedir .. "/" .. eb.outputfile

  -- 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)
  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

function clean()
	return eb.clean()
end