mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Add "last book" screensaver for Kobo
Epub only. If someone knows how to get an jpg/png from a pdf on linux (e.g. convert by imangemagick? But i am not a linux specialist and have no idea how to get that one into koreader) I can add something for linux too. cbz/cbr should be possible too, but I have not looked into it yet. Do I see it right that the Kindle screensavers are handled by Kindle itself? But on Kindle you also profit, you can see picture thumbnails now in the search results (long tap on found book)
This commit is contained in:
@@ -59,6 +59,109 @@ local UIManager = {
|
||||
suspend_msg = nil
|
||||
}
|
||||
|
||||
function UIManager:getPicture(file)
|
||||
|
||||
local contentopf
|
||||
local contentpath
|
||||
local epub_folder = "temp/epub"
|
||||
|
||||
local function check_extension(cover)
|
||||
if cover then
|
||||
local itype = string.lower(string.match(cover, ".+%.([^.]+)") or "")
|
||||
if not (itype == "png" or itype == "jpg" or itype == "jpeg" or itype == "tiff") then
|
||||
cover = nil
|
||||
end
|
||||
end
|
||||
return cover
|
||||
end
|
||||
|
||||
local function getValue(zipfile,which_line,to_find,excludecheck)
|
||||
local f = io.open(zipfile,"r")
|
||||
local i
|
||||
|
||||
if f then
|
||||
local line = f:read()
|
||||
while line and not i do
|
||||
i = line:lower():find(which_line:lower()) -- found something
|
||||
if i then
|
||||
f.close()
|
||||
line = line:match(to_find .. "\"([^\"]+)\".*")
|
||||
if not excludecheck then line = check_extension(line) end
|
||||
if line then
|
||||
return line
|
||||
else
|
||||
i = nil
|
||||
end
|
||||
end
|
||||
if not i then line = f:read() end
|
||||
end
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
|
||||
local function guess(extension)
|
||||
local cover = contentpath .. "Images/cover." .. extension
|
||||
pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder))
|
||||
cover = epub_folder .. "/" .. cover
|
||||
if not io.open(cover,"r") then
|
||||
cover = nil
|
||||
end
|
||||
return cover
|
||||
end
|
||||
|
||||
local function try_content_opf(which_line,to_find,addimage)
|
||||
local cover = getValue(epub_folder .. "/" .. contentopf,which_line,to_find)
|
||||
local imageadd
|
||||
if cover then
|
||||
if addimage then
|
||||
imageadd = "Images/"
|
||||
else
|
||||
imageadd = ""
|
||||
end
|
||||
cover = contentpath .. imageadd .. cover
|
||||
pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder))
|
||||
cover = epub_folder .. "/" .. cover
|
||||
if not io.open(cover,"r") then cover = nil end
|
||||
end
|
||||
return check_extension(cover)
|
||||
end
|
||||
|
||||
local cover
|
||||
if file then
|
||||
pcall(lfs.mkdir("temp"))
|
||||
pcall(os.execute("rm -rf " .. epub_folder))
|
||||
pcall(lfs.mkdir(epub_folder))
|
||||
pcall(os.execute("unzip \"" .. file .. "\" cover.jpeg -oq -d " .. epub_folder))
|
||||
if io.open(epub_folder .. "/cover.jpeg","r") then -- picture in main folder
|
||||
cover = epub_folder .. "/cover.jpeg" -- found one
|
||||
else
|
||||
pcall(os.execute("unzip \"" .. file .. "\" \"META-INF/container.xml\" -oq -d " .. epub_folder)) -- read container.xml
|
||||
contentopf = getValue(epub_folder .. "/META-INF/container.xml","^%s*<rootfile ","full[-]path=",true)
|
||||
if contentopf then
|
||||
contentpath = contentopf:match("(.*)[/][^/]+")
|
||||
if contentpath then
|
||||
contentpath = contentpath .. "/"
|
||||
else
|
||||
contentpath = ""
|
||||
end
|
||||
|
||||
pcall(os.execute("unzip \"" .. file .. "\" \"" .. contentopf .. "\" -oq -d " .. epub_folder)) -- read content.opf
|
||||
|
||||
cover = try_content_opf("^%s*<meta name=\"cover\"","content=",true) -- Make Room
|
||||
if not cover then cover = try_content_opf('id="cover',"item href=",false) end -- Kishon
|
||||
if not cover then cover = try_content_opf("cover","href=",true) end
|
||||
if not cover then cover = try_content_opf("cover","=",true) end
|
||||
if not cover then cover = try_content_opf("cover","=",false) end
|
||||
|
||||
if not cover then guess("jpg") end
|
||||
if not cover then guess("jpeg") end
|
||||
if not cover then guess("png") end
|
||||
end
|
||||
end
|
||||
end
|
||||
return check_extension(cover)
|
||||
end
|
||||
|
||||
function UIManager:getRandomPicture(dir)
|
||||
local pics = {}
|
||||
local i = 0
|
||||
@@ -92,14 +195,22 @@ function UIManager:init()
|
||||
if (input_event == "Power" or input_event == "Suspend")
|
||||
and not Device.screen_saver_mode then
|
||||
if not UIManager.suspend_msg then
|
||||
if type(KOBO_SCREEN_SAVER) == "string" then
|
||||
local file = KOBO_SCREEN_SAVER
|
||||
if lfs.attributes(file, "mode") == "directory" then
|
||||
if string.sub(file,string.len(file)) ~= "/" then
|
||||
file = file .. "/"
|
||||
|
||||
local file
|
||||
if KOBO_SCREEN_SAVER_LAST_BOOK then
|
||||
file = self:getPicture(G_reader_settings:readSetting("lastfile"))
|
||||
end
|
||||
|
||||
if type(KOBO_SCREEN_SAVER) == "string" or file then
|
||||
if not file then
|
||||
file = KOBO_SCREEN_SAVER
|
||||
if lfs.attributes(file, "mode") == "directory" then
|
||||
if string.sub(file,string.len(file)) ~= "/" then
|
||||
file = file .. "/"
|
||||
end
|
||||
local dummy = self:getRandomPicture(file)
|
||||
if dummy then file = file .. dummy end
|
||||
end
|
||||
local dummy = self:getRandomPicture(file)
|
||||
if dummy then file = file .. dummy end
|
||||
end
|
||||
if lfs.attributes(file, "mode") == "file" then
|
||||
UIManager.suspend_msg = ImageWidget:new{
|
||||
@@ -358,7 +469,7 @@ function UIManager:run()
|
||||
|
||||
-- stop when we have no window to show
|
||||
if #self._window_stack == 0 then
|
||||
DEBUG("no dialog left to show, would loop endlessly")
|
||||
DEBUG("no dialog left to show")
|
||||
self:quit()
|
||||
return nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user