附协议分析笔记,沿用统一的 update.lua 与打包脚本。 Co-authored-by: Copilot <[email protected]>
142 lines
3.9 KiB
Lua
142 lines
3.9 KiB
Lua
local _ = require("moonsource_bilimanga.l10n")
|
|
|
|
local SOURCE_ID = "bilimanga"
|
|
|
|
local function clean(s)
|
|
if not s then return "" end
|
|
return tostring(s)
|
|
end
|
|
|
|
-- ============================================================
|
|
-- Book 映射
|
|
-- ============================================================
|
|
|
|
function Mapper.book(info)
|
|
if not info then return nil end
|
|
local cover = info.vcover or info.horizontal_cover or info.cover or ""
|
|
local author = info.author
|
|
local author_str = ""
|
|
if author then
|
|
if type(author) == "string" then
|
|
author_str = author
|
|
elseif type(author) == "table" then
|
|
if author.name then author_str = author.name end
|
|
end
|
|
end
|
|
if author_str == "" then author_str = "未知作者" end
|
|
|
|
local styles = info.styles
|
|
local category = ""
|
|
if styles and type(styles) == "table" and #styles > 0 then
|
|
category = table.concat(styles, " · ")
|
|
end
|
|
|
|
local status_str = _("连载")
|
|
if info.status == 2 then status_str = _("完结") end
|
|
|
|
return {
|
|
source_id = SOURCE_ID,
|
|
stable_id = tostring(info.comic_id),
|
|
title = clean(info.title),
|
|
authors = author_str,
|
|
cover = cover,
|
|
intro = clean(info.desc),
|
|
category = category,
|
|
meta = {
|
|
status = status_str,
|
|
fans = info.fans or "",
|
|
total_eps = info.ep_count or info.ord_count or 0,
|
|
},
|
|
}
|
|
end
|
|
|
|
function Mapper.bookFromItem(item)
|
|
return Mapper.book(item)
|
|
end
|
|
|
|
-- ============================================================
|
|
-- Chapter 映射
|
|
-- ============================================================
|
|
|
|
function Mapper.chapters(comic)
|
|
if not comic then return {} end
|
|
local eps = comic.ep_list or {}
|
|
local chapters = {}
|
|
for i, ep in ipairs(eps) do
|
|
chapters[#chapters + 1] = {
|
|
idx = i,
|
|
uid = tostring(ep.id),
|
|
title = clean(ep.title or ep.short_title or ("第" .. i .. "话")),
|
|
vip = ep.pay_type == 1 or (ep.is_pay == true and true) or false,
|
|
}
|
|
end
|
|
return chapters
|
|
end
|
|
|
|
-- ============================================================
|
|
-- Image 映射
|
|
-- ============================================================
|
|
|
|
function Mapper.images(wire)
|
|
if not wire then return nil end
|
|
|
|
local images = wire.images
|
|
if not images or type(images) ~= "table" or #images == 0 then
|
|
-- 尝试 image_list
|
|
images = wire.image_list
|
|
if not images or type(images) ~= "table" or #images == 0 then
|
|
return nil
|
|
end
|
|
end
|
|
|
|
local urls = {}
|
|
for _, img in ipairs(images) do
|
|
if type(img) == "table" and type(img.url) == "string" and img.url ~= "" then
|
|
urls[#urls + 1] = img.url
|
|
end
|
|
end
|
|
|
|
return #urls > 0 and urls or nil
|
|
end
|
|
|
|
-- ============================================================
|
|
-- Search 映射
|
|
-- ============================================================
|
|
|
|
function Mapper.searchResults(wire)
|
|
if not wire then return {} end
|
|
local items = wire.list or {}
|
|
local books = {}
|
|
for i = 1, #items do
|
|
local book = Mapper.book(items[i])
|
|
if book then books[#books + 1] = book end
|
|
end
|
|
return books
|
|
end
|
|
|
|
-- ============================================================
|
|
-- Shelf 映射
|
|
-- ============================================================
|
|
|
|
function Mapper.favoriteItems(wire)
|
|
if not wire then return {} end
|
|
return wire.list or {}
|
|
end
|
|
|
|
-- ============================================================
|
|
-- Progress 映射
|
|
-- ============================================================
|
|
|
|
function Mapper.historyItem(wire, comic_id)
|
|
if not wire then return nil end
|
|
local list = wire.list or {}
|
|
for _, item in ipairs(list) do
|
|
if tostring(item.comic_id) == tostring(comic_id) then
|
|
return item
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
return Mapper
|