✨ (kmoe): 下载的 EPUB 按页序转成 CBZ

转不了时仍打开原来的 EPUB,已下载的卷不再重新扣额度。
This commit is contained in:
Garfield committed 2026-12-01 11:34:05 +08:00
1 parent 6fddb67ab3
commit fd1cd66cd6
7 files changed
+497 -55

No files matched your search

@@ -1,7 +1,7 @@
--[[--
Kmoe 数据源门面。
书城与搜索匿名可用;卷列表、下载、书架要登录。一卷是一章,下载整卷 EPUB 阅读。
书城与搜索匿名可用;卷列表、下载、书架要登录。一卷是一章,下载 EPUB 后转成 CBZ 阅读。
书架是网站的「收藏」,经 Shelf 双向同步。网站没有阅读进度接口,进度只在本机。
@module moonsource_kmoe.source
@@ -213,14 +213,21 @@ function Source:openBookAsync(identity, opts, cb)
cb(ok and path or nil, err)
end
-- 已下载的卷直接交给阅读器,不经过联网门控。
-- 已转好的 CBZ 直接开。只有 EPUB 时离线转换,不重新下载。
local toc = Toc.read(identity.source_id, identity.stable_id)
local local_chapter, local_idx
if toc then
local idx = startIndex(identity, opts, toc)
local path = Chapter.existing(identity, toc[idx])
if path then return SourceBase.defer(finish, path, idx) end
local_idx = startIndex(identity, opts, toc)
local_chapter = toc[local_idx]
local ready = Chapter.existing(identity, local_chapter)
if ready then
local leftover = Chapter.epubOnDisk(identity, local_chapter)
if leftover then os.remove(leftover) end
return SourceBase.defer(finish, ready, local_idx)
end
end
if not require("ui/network/manager"):isConnected() then
local local_epub = local_chapter and Chapter.epubOnDisk(identity, local_chapter)
if not local_epub and not require("ui/network/manager"):isConnected() then
return SourceBase.defer(cb, nil, _("网络不可用,请先连接 Wi-Fi"))
end
@@ -228,6 +235,27 @@ function Source:openBookAsync(identity, opts, cb)
local function closeDialog()
if dialog then dialog:close(); dialog = nil end
end
---@param fresh KmoeChapter[]
local function materialize(fresh)
local idx = startIndex(identity, opts, fresh)
local mb = 1024 * 1024
active = Chapter.materializeAsync(self._client, identity, fresh[idx],
function(bytes, total)
if not dialog then return end
if not bytes then dialog:set(_("正在整理这一卷…")); return end
if total and total > 0 then
dialog:update(_("正在下载这一卷…"), math.floor(bytes / mb), math.ceil(total / mb))
end
end,
function(path, materialize_err)
active = nil
closeDialog()
if cancelled then return end
if not path then cb(nil, materialize_err); return end
finish(path, idx)
end
)
end
require("ui/uimanager"):nextTick(function()
if cancelled then return end
dialog = require("ui.themes.widgets.progress_dialog"):new{
@@ -236,26 +264,12 @@ function Source:openBookAsync(identity, opts, cb)
}
dialog:show()
dialog:set(_("正在准备漫画…"))
if local_epub then materialize(toc); return end
active = self:loadTocAsync(identity, function(fresh, err)
active = nil
if cancelled then return end
if not fresh then closeDialog(); cb(nil, err); return end
local idx = startIndex(identity, opts, fresh)
local mb = 1024 * 1024
active = Chapter.materializeAsync(self._client, identity, fresh[idx],
function(bytes, total)
if dialog and total and total > 0 then
dialog:update(_("正在下载这一卷…"), math.floor(bytes / mb), math.ceil(total / mb))
end
end,
function(path, materialize_err)
active = nil
closeDialog()
if cancelled then return end
if not path then cb(nil, materialize_err); return end
finish(path, idx)
end
)
materialize(fresh)
end)
end)