打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:Bilibili:修订间差异

来自OTTOWiki
琪露若
琪露若留言 | 贡献 (改到最小限度可用了 修好了mw记得回退)
第9行: 第9行:
     -- 调用B站API获取视频信息
     -- 调用B站API获取视频信息
     local url = "https://api.bilibili.com/x/web-interface/view?bvid=" .. bvid
     local url = "https://api.bilibili.com/x/web-interface/view?bvid=" .. bvid
     local response = mw.http.get(url)
     local response = mw.ext.externalData.getWebData{
        url = url,
        format = "json"
    }
      
      
     if not response then
     if not response then
第15行: 第18行:
     end
     end
      
      
    -- 检查HTTP状态码
     if response.code == 0 and response.data and response.title then
     if response.status ~= 200 then
         return response.title  -- 返回视频标题
        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
     else
         return "视频不存在或获取失败"
         return "视频不存在或获取失败"

2025年6月24日 (二) 18:04的版本

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.ext.externalData.getWebData{
        url = url,
        format = "json"
    }
    
    if not response then
        return "获取信息失败"
    end
    
    if response.code == 0 and response.data and response.title then
        return response.title  -- 返回视频标题
    else
        return "视频不存在或获取失败"
    end
end

return p