模块:NeteaseMusic
来自异世界百科
此模块的文档可以在模块:NeteaseMusic/doc创建
local p = {}
function p.getMusicId(url)
return string.match(url, "[%?&]id=(%d+)")
end
function p.checkMusicId(id)
return string.match(id, "^%d+$") ~= nil
end
function p.player(frame)
local musicId = frame.args[1]
local autoPlay = frame.args.auto and (frame.args.auto == "1" or frame.args.auto == "true")
local autoPlayStr = "0"
if autoPlay then
autoPlayStr = "1"
end
if musicUrl ~= nil and checkMusicId(musicId) then
local dom = mw.html.create( 'div' )
dom:addClass("netease-music-container")
local iframe = dom:tag("iframe")
iframe:attr("frameborder", "no")
:attr("border", "0")
:attr("marginwidth", "0")
:attr("marginheight", "0")
:attr("width", "330")
:attr("height", "86")
:src(string.format(
"https://music.163.com/outchain/player?type=2&id=%s&auto=%s&height=66",
musicId,
autoPlayStr
))
return tostring(dom)
else
error("输入的网易云音乐分享URL错误: " .. musicUrl)
end
end
return p