欢迎来到《魔法使的约定》中文WIKI - 当前用户未登录
WIKI建设交流群:578085100;日服游戏交流群:821895698;中文服游戏交流群:790127155
全站通知:
模块:Id2VideoInfo
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:Id2VideoInfo/doc创建
-- Module:Id2VideoInfo (r7: cleaned)
local p = {}
p._VERSION = 'Id2VideoInfo/2025-09-21.r7'
-- ===== Args(使用官方 Module:Arguments)=====
local getArgs
do
local ok, M = pcall(require, 'Module:Arguments')
if ok and type(M) == 'table' and type(M.getArgs) == 'function' then
getArgs = M.getArgs
else
getArgs = function(frame)
if type(frame) ~= 'table' then return {} end
local parent = type(frame.getParent) == 'function' and frame:getParent() or nil
local fa = frame.args or {}
local pa = parent and parent.args or {}
return setmetatable({}, {
__index = function(_, k)
local v = fa[k]
if v == nil or v == '' then v = pa[k] end
return v
end
})
end
end
end
-- ===== 数据加载 =====
local function tryLoad(title)
local ok, tbl = pcall(mw.loadData, title)
if ok and type(tbl) == 'table' then return tbl end
ok, tbl = pcall(require, title)
if ok and type(tbl) == 'table' then return tbl end
return nil
end
local function loadDataFlex()
return tryLoad('Module:Id2VideoInfo/data')
or tryLoad('Module:Id2VideoInfo/Data')
or {}
end
local DATA = loadDataFlex()
-- ===== 常量 =====
local VIDEO_PREFIX = 'https://www.bilibili.com/video/'
local SPACE_PREFIX = 'https://space.bilibili.com/'
-- ===== 组一条 wikitext 片段(把 label 本身做成视频超链接)=====
local function wtItem(item)
if type(item) ~= 'table' then return nil end
local label = item.label or ''
local bv = item.bv or ''
local uid = item.uid or ''
local by = item.by or ''
local parts = {}
-- 1) label:如果有 bvid,则把 label 本身做成外链;否则保留纯文本
if label ~= '' then
if bv ~= '' then
table.insert(parts, ('[%s%s %s]'):format(VIDEO_PREFIX, bv, label))
else
table.insert(parts, label)
end
else
-- 无 label 时,若有 bvid,用“视频”作为占位文本
if bv ~= '' then
table.insert(parts, ('[%s%s 视频]'):format(VIDEO_PREFIX, bv))
end
end
-- 2) 作者:有 uid 就链到空间;没有就纯文本;没有 by 就不拼
if by ~= '' then
if #parts > 0 then table.insert(parts, ' by ') end
if uid ~= '' then
table.insert(parts, ('[%s %s]'):format(SPACE_PREFIX .. uid, by))
else
table.insert(parts, by)
end
end
local s = table.concat(parts)
return (s ~= '') and s or nil
end
-- ===== 主入口 =====
function p.main(frame)
local args = getArgs(frame)
local id = tostring(args.id or args[1] or ''):match('^%s*(.-)%s*$')
local as = tostring(args.as or 'ul') -- 'ul' | 'wikitext'
local wrap = tostring(args.wrap or '') == '1'
local mark = tostring(args.mark or '') == '1'
if id == '' then return '' end
local rows = DATA[id]
local out = {}
if type(rows) == 'table' then
for _, it in ipairs(rows) do
local line = wtItem(it)
if line and line ~= '' then out[#out+1] = line end
end
end
if #out == 0 then return '' end
local body
if as == 'wikitext' then
local lines = {}
for i = 1, #out do lines[i] = '* ' .. out[i] end
body = '\n' .. table.concat(lines, '\n') .. '\n'
else
local ul = mw.html.create('ul'):addClass('id2events-list')
for _, line in ipairs(out) do ul:tag('li'):wikitext(line) end
body = tostring(ul)
end
if wrap then
body = tostring(
mw.html.create('div')
:addClass('id2events-wrap')
:wikitext(body)
)
end
if mark then
body = '<!--ID2EVENTS ' .. id .. ' ' .. p._VERSION .. '-->' .. body .. '<!--/ID2EVENTS-->'
end
return body
end
-- ===== 探针 =====
function p.probe(frame)
local t = mw.title.getCurrentTitle()
return tostring(
mw.html.create('div')
:cssText('border:2px solid #06c;padding:4px;margin:4px 0;background:#f5fbff;color:#024')
:wikitext(('PROBE OK ver=%s | page=%s (ns=%d)')
:format(p._VERSION, t and t.fullText or '?', t and t.namespace or -1))
)
end
-- ===== 纯文本 =====
function p.raw(frame)
local args = getArgs(frame)
local id = tostring(args.id or args[1] or ''):match('^%s*(.-)%s*$')
if id == '' then return '' end
local rows = DATA[id]
local out = {}
if type(rows) == 'table' then
for _, it in ipairs(rows) do
local line = wtItem(it)
if line and line ~= '' then out[#out+1] = line end
end
end
return table.concat(out, '\n')
end
p.id = p.main
return p