模块:Bilibili
来自电棍ottowiki
更多操作
(重定向自模块:Video)
此模块的文档可以在模块:Bilibili/doc创建
local p = {}
function p.getTitle(frame)
local bvid = frame.args[1]
if not bvid or bvid == '' then
return "无效BV号"
end
-- 调用B站API获取视频信息
local url = "https://api.bilibili.com/x/web-interface/view?bvid=" .. bvid
local response = mw.http.get(url)
if not response then
return "获取信息失败"
end
-- 检查HTTP状态码
if response.status ~= 200 then
return "API请求失败 (HTTP " .. response.status .. ")"
end
-- 安全解析JSON
local success, json = pcall(mw.text.jsonDecode, response.body)
if not success or not json then
return "解析数据失败"
end
if json.code == 0 and json.data and json.data.title then
return json.data.title -- 返回视频标题
else
return "视频不存在或获取失败"
end
end
return p