Notice: Unexpected clearActionName after getActionName already called in /www/wwwroot/ottowiki/includes/context/RequestContext.php on line 338
模块:Bilibili - 电棍ottowiki
打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
(重定向自模块: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