模块: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 musicId ~= nil and p.checkMusicId(musicId) then
		return '<div class="netease-music-player">' 
			.. frame:extensionTag("htmltag", "", {
					tagname = "iframe",
					frameborder = "no",
					border = "0",
					marginwidth = "0",
					marginheight = "0",
					width = "330",
					height = "86",
					src = string.format(
						"https://music.163.com/outchain/player?type=2&id=%s&auto=%s&height=66",
						musicId,
						autoPlayStr)
				})
			.. '</div>'
	else
		error("输入的网易云音乐ID错误: " .. musicId)
	end
end

return p