模块:NeteaseMusic

来自异世界百科
落雨枫讨论 | 贡献2021年12月23日 (四) 22:36的版本

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

return p