mirror of https://github.com/koreader/koreader
calibre: gui to choose default extension
parent
3b6f521e26
commit
a63c22b6fb
@ -1,37 +1,80 @@
|
|||||||
--[[
|
--[[
|
||||||
File formats supported by KOReader. These are reported when the device talks with calibre wireless server.
|
File formats supported by KOReader. These are reported when the device talks with calibre wireless server.
|
||||||
|
|
||||||
Note that the server can allow or restrict file formats based on calibre configuration for each device.
|
calibre assumes that the list is in desired order.
|
||||||
Optionally KOReader users can set their own supported formats to report to the server.
|
When sending documents if no format on the list exists then calibre converts the book to the first format.
|
||||||
|
|
||||||
|
See https://www.mobileread.com/forums/showthread.php?t=341423
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local user_path = require("datastorage"):getDataDir() .. "/calibre-extensions.lua"
|
local valid_ext = {
|
||||||
local ok, extensions = pcall(dofile, user_path)
|
"epub",
|
||||||
|
"fb2",
|
||||||
if ok then
|
"mobi",
|
||||||
return extensions
|
"azw",
|
||||||
else
|
"xps",
|
||||||
return {
|
"doc",
|
||||||
"azw",
|
"docx",
|
||||||
"cbz",
|
"djv",
|
||||||
"chm",
|
"djvu",
|
||||||
"djv",
|
"pdf",
|
||||||
"djvu",
|
"cbz",
|
||||||
"doc",
|
"htm",
|
||||||
"docx",
|
"html",
|
||||||
"epub",
|
"xhtml",
|
||||||
"fb2",
|
"pdb",
|
||||||
"htm",
|
"prc",
|
||||||
"html",
|
"rtf",
|
||||||
"md",
|
"txt",
|
||||||
"mobi",
|
"md",
|
||||||
"pdb",
|
"chm",
|
||||||
"pdf",
|
"zip",
|
||||||
"prc",
|
}
|
||||||
"rtf",
|
|
||||||
"txt",
|
-- if the file "calibre-extensions.lua", under dataDir, returns a table
|
||||||
"xhtml",
|
-- then use it instead of default extensions.
|
||||||
"xps",
|
local function getCustomConfig()
|
||||||
"zip",
|
local path = require("datastorage"):getDataDir()
|
||||||
}
|
local ok, extensions = pcall(dofile, string.format("%s/%s", path, "calibre-extensions.lua"))
|
||||||
|
if ok then return extensions end
|
||||||
|
end
|
||||||
|
|
||||||
|
local CalibreExtensions = {
|
||||||
|
outputs = { "epub", "mobi", "docx", "fb2", "pdf", "txt" },
|
||||||
|
default_output = G_reader_settings:readSetting("calibre_wireless_default_format") or "epub",
|
||||||
|
user_overrides = getCustomConfig(),
|
||||||
|
}
|
||||||
|
|
||||||
|
function CalibreExtensions:get()
|
||||||
|
if type(self.user_overrides) == "table" then
|
||||||
|
return self.user_overrides
|
||||||
|
else
|
||||||
|
local sorted = {}
|
||||||
|
sorted[1] = self.default_output
|
||||||
|
for _, v in ipairs(valid_ext) do
|
||||||
|
if v ~= self.default_output then
|
||||||
|
sorted[#sorted+1] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return sorted
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CalibreExtensions:getInfo()
|
||||||
|
local str = ""
|
||||||
|
local t = self:get()
|
||||||
|
for i, v in ipairs(t) do
|
||||||
|
if i == #t then
|
||||||
|
str = str .. v
|
||||||
|
else
|
||||||
|
str = str .. v .. ", "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
|
function CalibreExtensions:isCustom()
|
||||||
|
return self.user_overrides ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return CalibreExtensions
|
||||||
|
Loading…
Reference in New Issue